gettext 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +82 -42
- data/gettext.gemspec +3 -0
- data/lib/gettext/core_ext/string.rb +60 -56
- data/lib/gettext/runtime/mofile.rb +16 -12
- data/lib/gettext/runtime/textdomain.rb +1 -1
- data/lib/gettext/runtime/textdomain_manager.rb +16 -0
- data/lib/gettext/tools/poparser.rb +107 -76
- data/lib/gettext/tools/rmsgfmt.rb +2 -2
- data/lib/gettext/version.rb +2 -1
- data/src/poparser.ry +59 -25
- data/test/locale/ja/LC_MESSAGES/backslash.mo +0 -0
- data/test/locale/ja/LC_MESSAGES/non_ascii.mo +0 -0
- data/test/po/ja/backslash.po +21 -0
- data/test/po/ja/non_ascii.po +21 -0
- data/test/pot/backslash.pot +21 -0
- data/test/pot/non_ascii.pot +21 -0
- data/test/pot/npgettext.pot +46 -0
- data/test/pot/nsgettext.pot +65 -0
- data/test/pot/pgettext.pot +48 -0
- data/test/pot/sgettext.pot +17 -0
- data/test/run-test.rb +37 -0
- data/test/test_gettext.rb +9 -7
- data/test/test_locale_path.rb +4 -0
- data/test/test_mofile.rb +21 -0
- data/test/test_string.rb +56 -60
- data/test/test_textdomain_bind.rb +5 -0
- data/test/test_textdomain_multi.rb +5 -1
- data/test/test_textdomain_toplevel.rb +12 -9
- data/test/testlib/backslash.rb +12 -0
- data/test/testlib/multi_textdomain.rb +91 -89
- data/test/testlib/non_ascii.rb +12 -0
- metadata +62 -7
- data/test/README +0 -1
- data/test/Rakefile +0 -17
data/Rakefile
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
$:.unshift "./lib"
|
|
16
16
|
|
|
17
|
+
require "tempfile"
|
|
17
18
|
require 'rake'
|
|
18
19
|
require 'rubygems'
|
|
19
20
|
require "yard/rake/yardoc_task"
|
|
20
|
-
require 'rake/testtask'
|
|
21
21
|
require 'gettext/version'
|
|
22
22
|
|
|
23
23
|
require "bundler/gem_helper"
|
|
@@ -34,37 +34,35 @@ PKG_VERSION = GetText::VERSION
|
|
|
34
34
|
############################################################
|
|
35
35
|
# GetText tasks for developing
|
|
36
36
|
############################################################
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
tmpfile.close
|
|
65
|
-
File.delete("src/poparser.tmp.rb")
|
|
66
|
-
$stderr.puts "Create #{poparser_path}."
|
|
37
|
+
poparser_rb_path = "lib/gettext/tools/poparser.rb"
|
|
38
|
+
desc "Create #{poparser_rb_path}"
|
|
39
|
+
task :poparser => poparser_rb_path
|
|
40
|
+
|
|
41
|
+
poparser_ry_path = "src/poparser.ry"
|
|
42
|
+
file poparser_rb_path => poparser_ry_path do
|
|
43
|
+
racc = File.join(Gem.bindir, "racc")
|
|
44
|
+
tempfile = Tempfile.new("gettext-poparser")
|
|
45
|
+
command_line = "#{racc} -g #{poparser_ry_path} -o #{tempfile.path}"
|
|
46
|
+
ruby(command_line)
|
|
47
|
+
$stderr.puts("ruby #{command_line}")
|
|
48
|
+
|
|
49
|
+
File.open(poparser_rb_path, "w") do |poparser_rb|
|
|
50
|
+
poparser_rb.puts(<<-EOH)
|
|
51
|
+
# -*- coding: utf-8 -*-
|
|
52
|
+
#
|
|
53
|
+
# poparser.rb - Generate a .mo
|
|
54
|
+
#
|
|
55
|
+
# Copyright (C) 2003-2009 Masao Mutoh <mutomasa at gmail.com>
|
|
56
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
|
57
|
+
#
|
|
58
|
+
# You may redistribute it and/or modify it under the same
|
|
59
|
+
# license terms as Ruby or LGPL.
|
|
60
|
+
|
|
61
|
+
EOH
|
|
62
|
+
|
|
63
|
+
poparser_rb.puts(tempfile.read)
|
|
67
64
|
end
|
|
65
|
+
$stderr.puts "Create #{poparser_rb_path}."
|
|
68
66
|
end
|
|
69
67
|
|
|
70
68
|
|
|
@@ -162,18 +160,60 @@ end
|
|
|
162
160
|
|
|
163
161
|
task :package => [:makemo]
|
|
164
162
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
namespace :test do
|
|
164
|
+
namespace :pot do
|
|
165
|
+
pot_base_dir = "test/pot"
|
|
166
|
+
directory pot_base_dir
|
|
167
|
+
|
|
168
|
+
pot_paths = []
|
|
169
|
+
ruby_base_paths = [
|
|
170
|
+
"non_ascii", "npgettext", "nsgettext",
|
|
171
|
+
"pgettext", "backslash",
|
|
172
|
+
]
|
|
173
|
+
ruby_paths = Dir.glob("test/testlib/{#{ruby_base_paths.join(',')}}.rb")
|
|
174
|
+
ruby_paths.each do |ruby_path|
|
|
175
|
+
pot_base_path = File.basename(ruby_path).sub(/\.rb\z/, ".pot")
|
|
176
|
+
pot_path = "#{pot_base_dir}/#{pot_base_path}"
|
|
177
|
+
pot_paths << pot_path
|
|
178
|
+
file pot_path => [pot_base_dir, ruby_path] do
|
|
179
|
+
require "gettext/tools"
|
|
180
|
+
GetText.rgettext(ruby_path, pot_path)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
desc "Update pot files for testing"
|
|
185
|
+
task :update => pot_paths
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
namespace :mo do
|
|
189
|
+
mo_paths = []
|
|
190
|
+
language_paths = Dir.glob("test/po/*")
|
|
191
|
+
language_paths.each do |language_path|
|
|
192
|
+
language = File.basename(language_path)
|
|
193
|
+
po_paths = Dir.glob("#{language_path}/*.po")
|
|
194
|
+
po_paths.each do |po_path|
|
|
195
|
+
mo_base_path = File.basename(po_path).sub(/\.po\z/, ".mo")
|
|
196
|
+
mo_path = "test/locale/#{language}/LC_MESSAGES/#{mo_base_path}"
|
|
197
|
+
mo_paths << mo_path
|
|
198
|
+
file mo_path => [po_path, poparser_rb_path] do
|
|
199
|
+
require "gettext/tools"
|
|
200
|
+
GetText.rmsgfmt(po_path, mo_path)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
desc "Update mo files for testing"
|
|
206
|
+
task :update => mo_paths
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
desc "Prepare test environment"
|
|
210
|
+
task :prepare => "test:mo:update"
|
|
211
|
+
end
|
|
212
|
+
|
|
168
213
|
desc 'Run all tests'
|
|
169
|
-
task :test do
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
sh "rake.bat", "test"
|
|
173
|
-
else
|
|
174
|
-
ruby "-S", "rake", "test"
|
|
175
|
-
end
|
|
176
|
-
end
|
|
214
|
+
task :test => "test:prepare" do
|
|
215
|
+
options = ARGV - Rake.application.top_level_tasks
|
|
216
|
+
ruby "test/run-test.rb", *options
|
|
177
217
|
end
|
|
178
218
|
|
|
179
219
|
YARD::Rake::YardocTask.new do |t|
|
data/gettext.gemspec
CHANGED
|
@@ -28,5 +28,8 @@ So you can use GNU GetText tools for maintaining.
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
s.add_runtime_dependency("locale")
|
|
31
|
+
s.add_development_dependency("racc")
|
|
31
32
|
s.add_development_dependency("yard")
|
|
33
|
+
s.add_development_dependency("test-unit")
|
|
34
|
+
s.add_development_dependency("test-unit-notify")
|
|
32
35
|
end
|
|
@@ -20,64 +20,68 @@ class String
|
|
|
20
20
|
alias :bytesize :size
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
begin
|
|
24
|
+
"%<key>" % {:key => "value"}
|
|
25
|
+
rescue ArgumentError
|
|
26
|
+
alias :_old_format_m :% # :nodoc:
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
PERCENT_MATCH_RE = Regexp.union(
|
|
29
|
+
/%%/,
|
|
30
|
+
/%\{(.+?)\}/,
|
|
31
|
+
/%<(.+?)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/
|
|
32
|
+
)
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
34
|
+
# call-seq:
|
|
35
|
+
# %(arg)
|
|
36
|
+
# %(hash)
|
|
37
|
+
#
|
|
38
|
+
# Format - Uses str as a format specification, and returns the result of applying it to arg.
|
|
39
|
+
# If the format specification contains more than one substitution, then arg must be
|
|
40
|
+
# an Array containing the values to be substituted. See Kernel::sprintf for details of the
|
|
41
|
+
# format string. This is the default behavior of the String class.
|
|
42
|
+
# * arg: an Array or other class except Hash.
|
|
43
|
+
# * Returns: formatted String
|
|
44
|
+
#
|
|
45
|
+
# (e.g.) "%s, %s" % ["Masao", "Mutoh"]
|
|
46
|
+
#
|
|
47
|
+
# Also you can use a Hash as the "named argument". This is recommanded way for Ruby-GetText
|
|
48
|
+
# because the translators can understand the meanings of the msgids easily.
|
|
49
|
+
# * hash: {:key1 => value1, :key2 => value2, ... }
|
|
50
|
+
# * Returns: formatted String
|
|
51
|
+
#
|
|
52
|
+
# (e.g.)
|
|
53
|
+
# For strings.
|
|
54
|
+
# "%{firstname}, %{familyname}" % {:firstname => "Masao", :familyname => "Mutoh"}
|
|
55
|
+
#
|
|
56
|
+
# With field type to specify format such as d(decimal), f(float),...
|
|
57
|
+
# "%<age>d, %<weight>.1f" % {:age => 10, :weight => 43.4}
|
|
58
|
+
def %(args)
|
|
59
|
+
if args.kind_of?(Hash)
|
|
60
|
+
ret = dup
|
|
61
|
+
ret.gsub!(PERCENT_MATCH_RE) {|match|
|
|
62
|
+
if match == '%%'
|
|
63
|
+
'%'
|
|
64
|
+
elsif $1
|
|
65
|
+
key = $1.to_sym
|
|
66
|
+
args.has_key?(key) ? args[key] : match
|
|
67
|
+
elsif $2
|
|
68
|
+
key = $2.to_sym
|
|
69
|
+
args.has_key?(key) ? sprintf("%#{$3}", args[key]) : match
|
|
70
|
+
end
|
|
71
|
+
}
|
|
72
|
+
ret
|
|
73
|
+
else
|
|
74
|
+
ret = gsub(/%([{<])/, '%%\1')
|
|
75
|
+
begin
|
|
76
|
+
ret._old_format_m(args)
|
|
77
|
+
rescue ArgumentError => e
|
|
78
|
+
if $DEBUG
|
|
79
|
+
$stderr.puts " The string:#{ret}"
|
|
80
|
+
$stderr.puts " args:#{args.inspect}"
|
|
81
|
+
puts e.backtrace
|
|
82
|
+
else
|
|
83
|
+
raise ArgumentError, e.message
|
|
84
|
+
end
|
|
81
85
|
end
|
|
82
86
|
end
|
|
83
87
|
end
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
require 'stringio'
|
|
21
21
|
|
|
22
22
|
module GetText
|
|
23
|
-
class
|
|
23
|
+
class MoFile < Hash
|
|
24
24
|
class InvalidFormat < RuntimeError; end;
|
|
25
25
|
|
|
26
26
|
attr_reader :filename
|
|
@@ -122,23 +122,24 @@ module GetText
|
|
|
122
122
|
io.pos = header.translated_table_offset
|
|
123
123
|
trans_table_data = io.read((4 * 2) * header.nstrings).unpack(endian_type_astr)
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
msgids = Array.new(header.nstrings)
|
|
126
126
|
for i in 0...header.nstrings
|
|
127
127
|
io.pos = orig_table_data[i * 2 + 1]
|
|
128
|
-
|
|
128
|
+
msgids[i] = io.read(orig_table_data[i * 2 + 0])
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
clear
|
|
132
132
|
for i in 0...header.nstrings
|
|
133
133
|
io.pos = trans_table_data[i * 2 + 1]
|
|
134
|
-
|
|
134
|
+
msgstr = io.read(trans_table_data[i * 2 + 0])
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
msgid = msgids[i]
|
|
137
|
+
if msgid.nil? || msgid.empty?
|
|
138
|
+
if msgstr
|
|
138
139
|
@charset = nil
|
|
139
140
|
@nplurals = nil
|
|
140
141
|
@plural = nil
|
|
141
|
-
|
|
142
|
+
msgstr.each_line{|line|
|
|
142
143
|
if /^Content-Type:/i =~ line and /charset=((?:\w|-)+)/i =~ line
|
|
143
144
|
@charset = $1
|
|
144
145
|
elsif /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line
|
|
@@ -151,11 +152,9 @@ module GetText
|
|
|
151
152
|
@plural = "0" unless @plural
|
|
152
153
|
end
|
|
153
154
|
else
|
|
154
|
-
|
|
155
|
-
str = convert_encoding(str, original_strings[i])
|
|
156
|
-
end
|
|
155
|
+
msgstr = convert_encoding(msgstr, msgid)
|
|
157
156
|
end
|
|
158
|
-
self[
|
|
157
|
+
self[convert_encoding(msgid, msgid)] = msgstr.freeze
|
|
159
158
|
end
|
|
160
159
|
self
|
|
161
160
|
end
|
|
@@ -303,6 +302,8 @@ module GetText
|
|
|
303
302
|
private
|
|
304
303
|
if "".respond_to?(:encode)
|
|
305
304
|
def convert_encoding(string, original_string)
|
|
305
|
+
return string if @output_charset.nil? or @charset.nil?
|
|
306
|
+
|
|
306
307
|
begin
|
|
307
308
|
string.encode(@output_charset, @charset)
|
|
308
309
|
rescue EncodingError
|
|
@@ -331,6 +332,9 @@ module GetText
|
|
|
331
332
|
end
|
|
332
333
|
end
|
|
333
334
|
end
|
|
335
|
+
|
|
336
|
+
# Just for backward compatibility.
|
|
337
|
+
MOFile = MoFile
|
|
334
338
|
end
|
|
335
339
|
|
|
336
340
|
# Test
|
|
@@ -342,7 +346,7 @@ if $0 == __FILE__
|
|
|
342
346
|
end
|
|
343
347
|
|
|
344
348
|
ARGV.each{ |item|
|
|
345
|
-
mo = GetText::
|
|
349
|
+
mo = GetText::MoFile.open(item)
|
|
346
350
|
puts "------------------------------------------------------------------"
|
|
347
351
|
puts "charset = \"#{mo.charset}\""
|
|
348
352
|
puts "nplurals = \"#{mo.nplurals}\""
|
|
@@ -170,7 +170,7 @@ module GetText
|
|
|
170
170
|
|
|
171
171
|
if path
|
|
172
172
|
charset = @output_charset || lang.charset || Locale.charset || "UTF-8"
|
|
173
|
-
@mofiles[lang_key] =
|
|
173
|
+
@mofiles[lang_key] = MoFile.open(path, charset)
|
|
174
174
|
else
|
|
175
175
|
@mofiles[lang_key] = :empty
|
|
176
176
|
end
|
|
@@ -183,6 +183,22 @@ module GetText
|
|
|
183
183
|
return plural ? msgstrs[1] : msgstrs[0]
|
|
184
184
|
end
|
|
185
185
|
|
|
186
|
+
# for testing.
|
|
187
|
+
def dump_all_textdomains
|
|
188
|
+
[
|
|
189
|
+
@@textdomain_pool.dup,
|
|
190
|
+
@@textdomain_group_pool.dup,
|
|
191
|
+
@@gettext_classes.dup,
|
|
192
|
+
]
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# for testing.
|
|
196
|
+
def restore_all_textdomains(dumped_all_textdomains)
|
|
197
|
+
@@textdomain_pool, @@textdomain_group_pool, @@gettext_classes =
|
|
198
|
+
dumped_all_textdomains
|
|
199
|
+
clear_caches
|
|
200
|
+
end
|
|
201
|
+
|
|
186
202
|
# for testing.
|
|
187
203
|
def clear_all_textdomains
|
|
188
204
|
@@textdomain_pool = {}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
=end
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# poparser.rb - Generate a .mo
|
|
4
|
+
#
|
|
5
|
+
# Copyright (C) 2003-2009 Masao Mutoh <mutomasa at gmail.com>
|
|
6
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
|
7
|
+
#
|
|
8
|
+
# You may redistribute it and/or modify it under the same
|
|
9
|
+
# license terms as Ruby or LGPL.
|
|
11
10
|
|
|
12
11
|
#
|
|
13
12
|
# DO NOT MODIFY!!!!
|
|
14
|
-
# This file is automatically generated by Racc 1.4.
|
|
13
|
+
# This file is automatically generated by Racc 1.4.8
|
|
15
14
|
# from Racc grammer file "".
|
|
16
15
|
#
|
|
17
16
|
|
|
@@ -19,9 +18,30 @@ require 'racc/parser.rb'
|
|
|
19
18
|
module GetText
|
|
20
19
|
class PoParser < Racc::Parser
|
|
21
20
|
|
|
22
|
-
module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry',
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 114)
|
|
22
|
+
if GetText.respond_to?(:bindtextdomain)
|
|
23
|
+
include GetText
|
|
24
|
+
GetText.bindtextdomain("rgettext")
|
|
25
|
+
else
|
|
26
|
+
def _(message_id)
|
|
27
|
+
message_id
|
|
28
|
+
end
|
|
29
|
+
private :_
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
attr_writer :ignore_fuzzy, :report_warning
|
|
33
|
+
def initialize
|
|
34
|
+
@ignore_fuzzy = true
|
|
35
|
+
@report_warning = true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def ignore_fuzzy?
|
|
39
|
+
@ignore_fuzzy
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def report_warning?
|
|
43
|
+
@report_warning
|
|
44
|
+
end
|
|
25
45
|
|
|
26
46
|
def unescape(orig)
|
|
27
47
|
ret = orig.gsub(/\\n/, "\n")
|
|
@@ -30,50 +50,57 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
30
50
|
ret.gsub!(/\\"/, "\"")
|
|
31
51
|
ret
|
|
32
52
|
end
|
|
53
|
+
private :unescape
|
|
54
|
+
|
|
55
|
+
def unescape_string(string)
|
|
56
|
+
string.gsub(/\\\\/, "\\")
|
|
57
|
+
end
|
|
58
|
+
private :unescape_string
|
|
33
59
|
|
|
34
|
-
def parse(str, data
|
|
60
|
+
def parse(str, data)
|
|
35
61
|
@comments = []
|
|
36
62
|
@data = data
|
|
37
63
|
@fuzzy = false
|
|
38
64
|
@msgctxt = ""
|
|
39
|
-
$ignore_fuzzy = ignore_fuzzy
|
|
40
65
|
|
|
41
66
|
str.strip!
|
|
42
67
|
@q = []
|
|
43
68
|
until str.empty? do
|
|
44
69
|
case str
|
|
45
70
|
when /\A\s+/
|
|
46
|
-
|
|
71
|
+
str = $'
|
|
47
72
|
when /\Amsgctxt/
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
@q.push [:MSGCTXT, $&]
|
|
74
|
+
str = $'
|
|
50
75
|
when /\Amsgid_plural/
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
@q.push [:MSGID_PLURAL, $&]
|
|
77
|
+
str = $'
|
|
53
78
|
when /\Amsgid/
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
@q.push [:MSGID, $&]
|
|
80
|
+
str = $'
|
|
56
81
|
when /\Amsgstr/
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
@q.push [:MSGSTR, $&]
|
|
83
|
+
str = $'
|
|
59
84
|
when /\A\[(\d+)\]/
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
@q.push [:PLURAL_NUM, $1]
|
|
86
|
+
str = $'
|
|
62
87
|
when /\A\#~(.*)/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
88
|
+
if report_warning?
|
|
89
|
+
$stderr.print _("Warning: obsolete msgid exists.\n")
|
|
90
|
+
$stderr.print " #{$&}\n"
|
|
91
|
+
end
|
|
92
|
+
@q.push [:COMMENT, $&]
|
|
93
|
+
str = $'
|
|
67
94
|
when /\A\#(.*)/
|
|
68
|
-
|
|
69
|
-
|
|
95
|
+
@q.push [:COMMENT, $&]
|
|
96
|
+
str = $'
|
|
70
97
|
when /\A\"(.*)\"/
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
@q.push [:STRING, unescape_string($1)]
|
|
99
|
+
str = $'
|
|
73
100
|
else
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
101
|
+
#c = str[0,1]
|
|
102
|
+
#@q.push [:STRING, c]
|
|
103
|
+
str = str[1..-1]
|
|
77
104
|
end
|
|
78
105
|
end
|
|
79
106
|
@q.push [false, '$end']
|
|
@@ -109,7 +136,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
109
136
|
@comments << comment
|
|
110
137
|
end
|
|
111
138
|
|
|
112
|
-
def parse_file(po_file, data
|
|
139
|
+
def parse_file(po_file, data)
|
|
113
140
|
args = [ po_file ]
|
|
114
141
|
# In Ruby 1.9, we must detect proper encoding of a PO file.
|
|
115
142
|
if String.instance_methods.include?(:encode)
|
|
@@ -117,7 +144,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
117
144
|
args << "r:#{encoding}"
|
|
118
145
|
end
|
|
119
146
|
@po_file = po_file
|
|
120
|
-
parse(File.open(*args) {|io| io.read }, data
|
|
147
|
+
parse(File.open(*args) {|io| io.read }, data)
|
|
121
148
|
end
|
|
122
149
|
|
|
123
150
|
def detect_file_encoding(po_file)
|
|
@@ -133,33 +160,33 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
133
160
|
##### State transition tables begin ###
|
|
134
161
|
|
|
135
162
|
racc_action_table = [
|
|
136
|
-
|
|
137
|
-
|
|
163
|
+
2, 13, 10, 9, 6, 17, 16, 15, 22, 15,
|
|
164
|
+
15, 13, 13, 13, 15, 11, 22, 24, 13, 15 ]
|
|
138
165
|
|
|
139
166
|
racc_action_check = [
|
|
140
|
-
1,
|
|
141
|
-
|
|
167
|
+
1, 17, 1, 1, 1, 14, 14, 14, 19, 19,
|
|
168
|
+
12, 6, 16, 9, 18, 2, 20, 22, 24, 25 ]
|
|
142
169
|
|
|
143
170
|
racc_action_pointer = [
|
|
144
|
-
nil, 0,
|
|
145
|
-
nil, nil,
|
|
146
|
-
|
|
171
|
+
nil, 0, 15, nil, nil, nil, 4, nil, nil, 6,
|
|
172
|
+
nil, nil, 3, nil, 0, nil, 5, -6, 7, 2,
|
|
173
|
+
10, nil, 9, nil, 11, 12 ]
|
|
147
174
|
|
|
148
175
|
racc_action_default = [
|
|
149
|
-
-1, -16,
|
|
150
|
-
|
|
151
|
-
|
|
176
|
+
-1, -16, -16, -2, -3, -4, -16, -6, -7, -16,
|
|
177
|
+
-13, 26, -5, -15, -16, -14, -16, -16, -8, -16,
|
|
178
|
+
-9, -11, -16, -10, -16, -12 ]
|
|
152
179
|
|
|
153
180
|
racc_goto_table = [
|
|
154
|
-
12,
|
|
155
|
-
|
|
181
|
+
12, 21, 23, 14, 4, 5, 3, 7, 8, 20,
|
|
182
|
+
18, 19, 1, nil, nil, nil, nil, nil, 25 ]
|
|
156
183
|
|
|
157
184
|
racc_goto_check = [
|
|
158
|
-
5, 9, 5, 3,
|
|
159
|
-
|
|
185
|
+
5, 9, 9, 5, 3, 4, 2, 6, 7, 8,
|
|
186
|
+
5, 5, 1, nil, nil, nil, nil, nil, 5 ]
|
|
160
187
|
|
|
161
188
|
racc_goto_pointer = [
|
|
162
|
-
nil, 12, 5,
|
|
189
|
+
nil, 12, 5, 3, 4, -6, 6, 7, -10, -18 ]
|
|
163
190
|
|
|
164
191
|
racc_goto_default = [
|
|
165
192
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ]
|
|
@@ -252,10 +279,10 @@ Racc_debug_parser = true
|
|
|
252
279
|
|
|
253
280
|
# reduce 4 omitted
|
|
254
281
|
|
|
255
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
282
|
+
module_eval(<<'.,.,', 'poparser.ry', 25)
|
|
256
283
|
def _reduce_5(val, _values, result)
|
|
257
284
|
@msgctxt = unescape(val[1]) + "\004"
|
|
258
|
-
|
|
285
|
+
|
|
259
286
|
result
|
|
260
287
|
end
|
|
261
288
|
.,.,
|
|
@@ -264,12 +291,14 @@ module_eval(<<'.,.,', 'poparser.ry', 23)
|
|
|
264
291
|
|
|
265
292
|
# reduce 7 omitted
|
|
266
293
|
|
|
267
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
294
|
+
module_eval(<<'.,.,', 'poparser.ry', 37)
|
|
268
295
|
def _reduce_8(val, _values, result)
|
|
269
|
-
if @fuzzy and
|
|
296
|
+
if @fuzzy and ignore_fuzzy?
|
|
270
297
|
if val[1] != ""
|
|
271
|
-
|
|
272
|
-
|
|
298
|
+
if report_warning?
|
|
299
|
+
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
300
|
+
$stderr.print " #{@po_file}: msgid '#{val[1]}'\n"
|
|
301
|
+
end
|
|
273
302
|
else
|
|
274
303
|
on_message('', unescape(val[3]))
|
|
275
304
|
end
|
|
@@ -278,17 +307,19 @@ module_eval(<<'.,.,', 'poparser.ry', 35)
|
|
|
278
307
|
on_message(@msgctxt + unescape(val[1]), unescape(val[3]))
|
|
279
308
|
end
|
|
280
309
|
result = ""
|
|
281
|
-
|
|
310
|
+
|
|
282
311
|
result
|
|
283
312
|
end
|
|
284
313
|
.,.,
|
|
285
314
|
|
|
286
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
315
|
+
module_eval(<<'.,.,', 'poparser.ry', 56)
|
|
287
316
|
def _reduce_9(val, _values, result)
|
|
288
317
|
if @fuzzy and $ignore_fuzzy
|
|
289
318
|
if val[1] != ""
|
|
290
|
-
|
|
291
|
-
|
|
319
|
+
if report_warning?
|
|
320
|
+
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
321
|
+
$stderr.print "msgid = '#{val[1]}\n"
|
|
322
|
+
end
|
|
292
323
|
else
|
|
293
324
|
on_message('', unescape(val[3]))
|
|
294
325
|
end
|
|
@@ -297,53 +328,53 @@ module_eval(<<'.,.,', 'poparser.ry', 52)
|
|
|
297
328
|
on_message(@msgctxt + unescape(val[1]) + "\000" + unescape(val[3]), unescape(val[4]))
|
|
298
329
|
end
|
|
299
330
|
result = ""
|
|
300
|
-
|
|
331
|
+
|
|
301
332
|
result
|
|
302
333
|
end
|
|
303
334
|
.,.,
|
|
304
335
|
|
|
305
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
336
|
+
module_eval(<<'.,.,', 'poparser.ry', 76)
|
|
306
337
|
def _reduce_10(val, _values, result)
|
|
307
338
|
if val[0].size > 0
|
|
308
339
|
result = val[0] + "\000" + val[1]
|
|
309
340
|
else
|
|
310
341
|
result = ""
|
|
311
342
|
end
|
|
312
|
-
|
|
343
|
+
|
|
313
344
|
result
|
|
314
345
|
end
|
|
315
346
|
.,.,
|
|
316
347
|
|
|
317
348
|
# reduce 11 omitted
|
|
318
349
|
|
|
319
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
350
|
+
module_eval(<<'.,.,', 'poparser.ry', 88)
|
|
320
351
|
def _reduce_12(val, _values, result)
|
|
321
352
|
result = val[2]
|
|
322
|
-
|
|
353
|
+
|
|
323
354
|
result
|
|
324
355
|
end
|
|
325
356
|
.,.,
|
|
326
357
|
|
|
327
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
358
|
+
module_eval(<<'.,.,', 'poparser.ry', 95)
|
|
328
359
|
def _reduce_13(val, _values, result)
|
|
329
360
|
on_comment(val[0])
|
|
330
|
-
|
|
361
|
+
|
|
331
362
|
result
|
|
332
363
|
end
|
|
333
364
|
.,.,
|
|
334
365
|
|
|
335
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
366
|
+
module_eval(<<'.,.,', 'poparser.ry', 103)
|
|
336
367
|
def _reduce_14(val, _values, result)
|
|
337
368
|
result = val.delete_if{|item| item == ""}.join
|
|
338
|
-
|
|
369
|
+
|
|
339
370
|
result
|
|
340
371
|
end
|
|
341
372
|
.,.,
|
|
342
373
|
|
|
343
|
-
module_eval(<<'.,.,', 'poparser.ry',
|
|
374
|
+
module_eval(<<'.,.,', 'poparser.ry', 107)
|
|
344
375
|
def _reduce_15(val, _values, result)
|
|
345
376
|
result = val[0]
|
|
346
|
-
|
|
377
|
+
|
|
347
378
|
result
|
|
348
379
|
end
|
|
349
380
|
.,.,
|