gettext 2.1.0 → 2.2.0
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/README.rdoc +10 -6
- data/Rakefile +15 -66
- data/data/locale/bg/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/bs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/et/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/hr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/hu/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/lv/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nb/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/uk/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/vi/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
- data/doc/text/news.md +30 -0
- data/gettext.gemspec +26 -34
- data/lib/gettext.rb +26 -24
- data/lib/gettext/cgi.rb +2 -0
- data/lib/gettext/core_ext/iconv.rb +7 -7
- data/lib/gettext/core_ext/string.rb +8 -6
- data/lib/gettext/parser/erb.rb +2 -0
- data/lib/gettext/parser/glade.rb +2 -0
- data/lib/gettext/parser/ruby.rb +12 -12
- data/lib/gettext/runtime/class_info.rb +5 -3
- data/lib/gettext/runtime/locale_path.rb +20 -22
- data/lib/gettext/runtime/mofile.rb +45 -18
- data/lib/gettext/runtime/textdomain.rb +6 -4
- data/lib/gettext/runtime/textdomain_group.rb +3 -1
- data/lib/gettext/runtime/textdomain_manager.rb +29 -26
- data/lib/gettext/tools.rb +15 -13
- data/lib/gettext/tools/parser/erb.rb +5 -3
- data/lib/gettext/tools/parser/glade.rb +16 -14
- data/lib/gettext/tools/parser/ruby.rb +16 -16
- data/lib/gettext/tools/pomessage.rb +9 -7
- data/lib/gettext/tools/poparser.rb +38 -36
- data/lib/gettext/tools/rgettext.rb +38 -13
- data/lib/gettext/tools/rmsgfmt.rb +7 -5
- data/lib/gettext/tools/rmsgmerge.rb +116 -114
- data/lib/gettext/utils.rb +2 -0
- data/lib/gettext/version.rb +3 -3
- data/po/bg/rgettext.po +17 -12
- data/po/bs/rgettext.po +16 -12
- data/po/ca/rgettext.po +17 -12
- data/po/cs/rgettext.po +16 -12
- data/po/de/rgettext.po +17 -12
- data/po/el/rgettext.po +17 -12
- data/po/eo/rgettext.po +17 -12
- data/po/es/rgettext.po +17 -12
- data/po/et/rgettext.po +17 -12
- data/po/fr/rgettext.po +17 -12
- data/po/hr/rgettext.po +19 -15
- data/po/hu/rgettext.po +17 -12
- data/po/it/rgettext.po +16 -12
- data/po/ja/rgettext.po +21 -15
- data/po/ko/rgettext.po +16 -12
- data/po/lv/rgettext.po +17 -12
- data/po/nb/rgettext.po +17 -12
- data/po/nl/rgettext.po +16 -12
- data/po/pt_BR/rgettext.po +17 -12
- data/po/rgettext.pot +16 -12
- data/po/ru/rgettext.po +17 -12
- data/po/sr/rgettext.po +17 -12
- data/po/sv/rgettext.po +16 -12
- data/po/{ua → uk}/rgettext.po +17 -12
- data/po/vi/rgettext.po +17 -12
- data/po/zh/rgettext.po +17 -12
- data/po/zh_TW/rgettext.po +17 -12
- data/samples/cgi/hellolib.rb +1 -1
- data/samples/cgi/http.rb +5 -5
- data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/helloerb1.mo +0 -0
- data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/helloerb2.mo +0 -0
- data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/hellolib.mo +0 -0
- data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/main.mo +0 -0
- data/samples/cgi/po/{ua → uk}/helloerb1.po +0 -0
- data/samples/cgi/po/{ua → uk}/helloerb2.po +0 -0
- data/samples/cgi/po/{ua → uk}/hellolib.po +0 -0
- data/samples/cgi/po/{ua → uk}/main.po +0 -0
- data/samples/hello.rb +1 -1
- data/samples/hello_gtk2.rb +1 -1
- data/samples/hello_noop.rb +1 -1
- data/samples/locale/{ua → uk}/LC_MESSAGES/hello.mo +0 -0
- data/samples/locale/{ua → uk}/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/{ua → uk}/LC_MESSAGES/hello_glade2.mo +0 -0
- data/samples/locale/{ua → uk}/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/{ua → uk}/LC_MESSAGES/hello_noop.mo +0 -0
- data/samples/locale/{ua → uk}/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/{ua → uk}/LC_MESSAGES/hello_tk.mo +0 -0
- data/samples/makemo.rb +2 -0
- data/samples/po/test.rb +2 -0
- data/samples/po/{ua → uk}/hello.po +0 -0
- data/samples/po/{ua → uk}/hello2.po +0 -0
- data/samples/po/{ua → uk}/hello_glade2.po +0 -0
- data/samples/po/{ua → uk}/hello_gtk.po +0 -0
- data/samples/po/{ua → uk}/hello_noop.po +0 -0
- data/samples/po/{ua → uk}/hello_plural.po +0 -0
- data/samples/po/{ua → uk}/hello_tk.po +0 -0
- data/test/Rakefile +1 -1
- data/test/test_class_info.rb +5 -0
- data/test/test_gettext.rb +12 -1
- data/test/test_locale_path.rb +29 -3
- data/test/test_parser.rb +61 -59
- data/test/test_po_generation.rb +3 -1
- data/test/test_pomessage.rb +4 -2
- data/test/test_string.rb +2 -0
- data/test/test_textdomain_bind.rb +2 -0
- data/test/test_textdomain_multi.rb +2 -0
- data/test/test_textdomain_toplevel.rb +2 -0
- data/test/test_thread.rb +4 -2
- data/test/testlib/N_.rb +5 -3
- data/test/testlib/gettext.rb +4 -2
- data/test/testlib/helper.rb +2 -0
- data/test/testlib/multi_textdomain.rb +2 -0
- data/test/testlib/ngettext.rb +10 -8
- data/test/testlib/npgettext.rb +9 -7
- data/test/testlib/nsgettext.rb +4 -2
- data/test/testlib/pgettext.rb +4 -2
- data/test/testlib/sgettext.rb +4 -2
- data/test/testlib/simple.rb +2 -0
- data/test/tools/files/simple_translation.rb +3 -1
- data/test/tools/test_tools.rb +3 -1
- metadata +772 -737
- data/ChangeLog +0 -78
- data/ChangeLog-1 +0 -2016
- data/NEWS-1 +0 -414
- data/benchmark/1.93.0.txt +0 -8
- data/benchmark/2.0.0.txt +0 -8
- data/benchmark/2.0.4.txt +0 -11
- data/benchmark/2.1.0.txt +0 -11
- data/benchmark/benchmark.rb +0 -68
- data/benchmark/test.rb +0 -28
- data/data/locale/ua/LC_MESSAGES/rgettext.mo +0 -0
- data/replace.rb +0 -8
- data/samples/cgi/po/bg/#main.po# +0 -84
- data/test.rb +0 -33
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
module GetText
|
|
2
4
|
class ParseError < StandardError
|
|
3
5
|
end
|
|
@@ -25,7 +27,7 @@ module GetText
|
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
# Required
|
|
28
|
-
attr_accessor :type # :normal, :plural, :msgctxt, :msgctxt_plural
|
|
30
|
+
attr_accessor :type # :normal, :plural, :msgctxt, :msgctxt_plural
|
|
29
31
|
attr_accessor :msgid
|
|
30
32
|
# Options
|
|
31
33
|
attr_accessor :msgid_plural
|
|
@@ -33,7 +35,7 @@ module GetText
|
|
|
33
35
|
attr_accessor :sources # ["file1:line1", "file2:line2", ...]
|
|
34
36
|
attr_accessor :comment
|
|
35
37
|
|
|
36
|
-
# Create the object. +type+ should be :normal, :plural, :msgctxt or :msgctxt_plural.
|
|
38
|
+
# Create the object. +type+ should be :normal, :plural, :msgctxt or :msgctxt_plural.
|
|
37
39
|
def initialize(type)
|
|
38
40
|
@type = type
|
|
39
41
|
@sources = []
|
|
@@ -60,7 +62,7 @@ module GetText
|
|
|
60
62
|
# Checks if the other translation target is mergeable with
|
|
61
63
|
# the current one. Relevant are msgid and translation context (msgctxt).
|
|
62
64
|
def ==(other)
|
|
63
|
-
other.msgid == self.msgid && other.msgctxt == self.msgctxt
|
|
65
|
+
other && other.msgid == self.msgid && other.msgctxt == self.msgctxt
|
|
64
66
|
end
|
|
65
67
|
|
|
66
68
|
# Merges two translation targets with the same msgid and returns the merged
|
|
@@ -125,7 +127,7 @@ module GetText
|
|
|
125
127
|
end
|
|
126
128
|
|
|
127
129
|
# Returns true if the type is kind of msgctxt.
|
|
128
|
-
# And if this is a kind of msgctxt and msgctxt property
|
|
130
|
+
# And if this is a kind of msgctxt and msgctxt property
|
|
129
131
|
# is nil, then raise an RuntimeException.
|
|
130
132
|
def msgctxt?
|
|
131
133
|
if [:msgctxt, :msgctxt_plural].include? @type
|
|
@@ -135,7 +137,7 @@ module GetText
|
|
|
135
137
|
end
|
|
136
138
|
|
|
137
139
|
# Returns true if the type is kind of plural.
|
|
138
|
-
# And if this is a kind of plural and msgid_plural property
|
|
140
|
+
# And if this is a kind of plural and msgid_plural property
|
|
139
141
|
# is nil, then raise an RuntimeException.
|
|
140
142
|
def plural?
|
|
141
143
|
if [:plural, :msgctxt_plural].include? @type
|
|
@@ -164,7 +166,7 @@ module GetText
|
|
|
164
166
|
type = :normal
|
|
165
167
|
msgctxt = nil
|
|
166
168
|
msgid_plural = nil
|
|
167
|
-
|
|
169
|
+
|
|
168
170
|
if msgid.include? "\004"
|
|
169
171
|
msgctxt, msgid = msgid.split(/\004/)
|
|
170
172
|
type = :msgctxt
|
|
@@ -193,5 +195,5 @@ module GetText
|
|
|
193
195
|
send param
|
|
194
196
|
end
|
|
195
197
|
end
|
|
196
|
-
|
|
198
|
+
|
|
197
199
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
=begin
|
|
2
4
|
poparser.rb - Generate a .mo
|
|
3
5
|
|
|
@@ -28,7 +30,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
28
30
|
ret.gsub!(/\\"/, "\"")
|
|
29
31
|
ret
|
|
30
32
|
end
|
|
31
|
-
|
|
33
|
+
|
|
32
34
|
def parse(str, data, ignore_fuzzy = true)
|
|
33
35
|
@comments = []
|
|
34
36
|
@data = data
|
|
@@ -41,39 +43,39 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
41
43
|
until str.empty? do
|
|
42
44
|
case str
|
|
43
45
|
when /\A\s+/
|
|
44
|
-
|
|
46
|
+
str = $'
|
|
45
47
|
when /\Amsgctxt/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
@q.push [:MSGCTXT, $&]
|
|
49
|
+
str = $'
|
|
48
50
|
when /\Amsgid_plural/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
@q.push [:MSGID_PLURAL, $&]
|
|
52
|
+
str = $'
|
|
51
53
|
when /\Amsgid/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
@q.push [:MSGID, $&]
|
|
55
|
+
str = $'
|
|
54
56
|
when /\Amsgstr/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
@q.push [:MSGSTR, $&]
|
|
58
|
+
str = $'
|
|
57
59
|
when /\A\[(\d+)\]/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
@q.push [:PLURAL_NUM, $1]
|
|
61
|
+
str = $'
|
|
60
62
|
when /\A\#~(.*)/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
$stderr.print _("Warning: obsolete msgid exists.\n")
|
|
64
|
+
$stderr.print " #{$&}\n"
|
|
65
|
+
@q.push [:COMMENT, $&]
|
|
66
|
+
str = $'
|
|
65
67
|
when /\A\#(.*)/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
@q.push [:COMMENT, $&]
|
|
69
|
+
str = $'
|
|
68
70
|
when /\A\"(.*)\"/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
@q.push [:STRING, $1]
|
|
72
|
+
str = $'
|
|
71
73
|
else
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
#c = str[0,1]
|
|
75
|
+
#@q.push [:STRING, c]
|
|
76
|
+
str = str[1..-1]
|
|
75
77
|
end
|
|
76
|
-
end
|
|
78
|
+
end
|
|
77
79
|
@q.push [false, '$end']
|
|
78
80
|
if $DEBUG
|
|
79
81
|
@q.each do |a,b|
|
|
@@ -88,7 +90,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
88
90
|
end
|
|
89
91
|
@data
|
|
90
92
|
end
|
|
91
|
-
|
|
93
|
+
|
|
92
94
|
def next_token
|
|
93
95
|
@q.shift
|
|
94
96
|
end
|
|
@@ -101,11 +103,11 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
|
101
103
|
@comments.clear
|
|
102
104
|
@msgctxt = ""
|
|
103
105
|
end
|
|
104
|
-
|
|
106
|
+
|
|
105
107
|
def on_comment(comment)
|
|
106
108
|
@fuzzy = true if (/fuzzy/ =~ comment)
|
|
107
109
|
@comments << comment
|
|
108
|
-
end
|
|
110
|
+
end
|
|
109
111
|
|
|
110
112
|
def parse_file(po_file, data, ignore_fuzzy = true)
|
|
111
113
|
args = [ po_file ]
|
|
@@ -253,7 +255,7 @@ Racc_debug_parser = true
|
|
|
253
255
|
module_eval(<<'.,.,', 'poparser.ry', 23)
|
|
254
256
|
def _reduce_5(val, _values, result)
|
|
255
257
|
@msgctxt = unescape(val[1]) + "\004"
|
|
256
|
-
|
|
258
|
+
|
|
257
259
|
result
|
|
258
260
|
end
|
|
259
261
|
.,.,
|
|
@@ -264,7 +266,7 @@ module_eval(<<'.,.,', 'poparser.ry', 23)
|
|
|
264
266
|
|
|
265
267
|
module_eval(<<'.,.,', 'poparser.ry', 35)
|
|
266
268
|
def _reduce_8(val, _values, result)
|
|
267
|
-
if @fuzzy and $ignore_fuzzy
|
|
269
|
+
if @fuzzy and $ignore_fuzzy
|
|
268
270
|
if val[1] != ""
|
|
269
271
|
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
270
272
|
$stderr.print " #{@po_file}: msgid '#{val[1]}'\n"
|
|
@@ -276,7 +278,7 @@ module_eval(<<'.,.,', 'poparser.ry', 35)
|
|
|
276
278
|
on_message(@msgctxt + unescape(val[1]), unescape(val[3]))
|
|
277
279
|
end
|
|
278
280
|
result = ""
|
|
279
|
-
|
|
281
|
+
|
|
280
282
|
result
|
|
281
283
|
end
|
|
282
284
|
.,.,
|
|
@@ -295,7 +297,7 @@ module_eval(<<'.,.,', 'poparser.ry', 52)
|
|
|
295
297
|
on_message(@msgctxt + unescape(val[1]) + "\000" + unescape(val[3]), unescape(val[4]))
|
|
296
298
|
end
|
|
297
299
|
result = ""
|
|
298
|
-
|
|
300
|
+
|
|
299
301
|
result
|
|
300
302
|
end
|
|
301
303
|
.,.,
|
|
@@ -307,7 +309,7 @@ module_eval(<<'.,.,', 'poparser.ry', 70)
|
|
|
307
309
|
else
|
|
308
310
|
result = ""
|
|
309
311
|
end
|
|
310
|
-
|
|
312
|
+
|
|
311
313
|
result
|
|
312
314
|
end
|
|
313
315
|
.,.,
|
|
@@ -317,7 +319,7 @@ module_eval(<<'.,.,', 'poparser.ry', 70)
|
|
|
317
319
|
module_eval(<<'.,.,', 'poparser.ry', 82)
|
|
318
320
|
def _reduce_12(val, _values, result)
|
|
319
321
|
result = val[2]
|
|
320
|
-
|
|
322
|
+
|
|
321
323
|
result
|
|
322
324
|
end
|
|
323
325
|
.,.,
|
|
@@ -325,7 +327,7 @@ module_eval(<<'.,.,', 'poparser.ry', 82)
|
|
|
325
327
|
module_eval(<<'.,.,', 'poparser.ry', 89)
|
|
326
328
|
def _reduce_13(val, _values, result)
|
|
327
329
|
on_comment(val[0])
|
|
328
|
-
|
|
330
|
+
|
|
329
331
|
result
|
|
330
332
|
end
|
|
331
333
|
.,.,
|
|
@@ -333,7 +335,7 @@ module_eval(<<'.,.,', 'poparser.ry', 89)
|
|
|
333
335
|
module_eval(<<'.,.,', 'poparser.ry', 97)
|
|
334
336
|
def _reduce_14(val, _values, result)
|
|
335
337
|
result = val.delete_if{|item| item == ""}.join
|
|
336
|
-
|
|
338
|
+
|
|
337
339
|
result
|
|
338
340
|
end
|
|
339
341
|
.,.,
|
|
@@ -341,7 +343,7 @@ module_eval(<<'.,.,', 'poparser.ry', 97)
|
|
|
341
343
|
module_eval(<<'.,.,', 'poparser.ry', 101)
|
|
342
344
|
def _reduce_15(val, _values, result)
|
|
343
345
|
result = val[0]
|
|
344
|
-
|
|
346
|
+
|
|
345
347
|
result
|
|
346
348
|
end
|
|
347
349
|
.,.,
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
=begin
|
|
3
3
|
rgettext.rb - Generate a .pot file.
|
|
4
4
|
|
|
5
|
-
Copyright (C) 2003-
|
|
5
|
+
Copyright (C) 2003-2010 Masao Mutoh
|
|
6
6
|
Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
Yasushi Shoji <yashi at atmark-techno.com>
|
|
9
9
|
Masao Mutoh <mutomasa at gmail.com>
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
You may redistribute it and/or modify it under the same
|
|
12
12
|
license terms as Ruby or LGPL.
|
|
13
13
|
=end
|
|
@@ -25,7 +25,7 @@ module GetText
|
|
|
25
25
|
|
|
26
26
|
# constant values
|
|
27
27
|
VERSION = GetText::VERSION
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
@ex_parsers = []
|
|
30
30
|
[
|
|
31
31
|
["glade.rb", "GladeParser"],
|
|
@@ -46,19 +46,45 @@ module GetText
|
|
|
46
46
|
|
|
47
47
|
# Add an option parser
|
|
48
48
|
# the option parser module requires to have target?(file) and parser(file, ary) method.
|
|
49
|
-
#
|
|
49
|
+
#
|
|
50
50
|
# require 'gettext/tools/rgettext'
|
|
51
51
|
# module FooParser
|
|
52
52
|
# module_function
|
|
53
53
|
# def target?(file)
|
|
54
54
|
# File.extname(file) == '.foo' # *.foo file only.
|
|
55
55
|
# end
|
|
56
|
-
# def parse(file
|
|
56
|
+
# def parse(file)
|
|
57
57
|
# :
|
|
58
|
-
#
|
|
58
|
+
# ary = []
|
|
59
|
+
# # Simple message
|
|
60
|
+
# po = PoMessage.new(:normal)
|
|
61
|
+
# po.msgid = "hello"
|
|
62
|
+
# po.sources = ["foo.rb:200", "bar.rb:300"]
|
|
63
|
+
# po.add_comment("Comment for the message")
|
|
64
|
+
# ary << po
|
|
65
|
+
# # Plural message
|
|
66
|
+
# po = PoMessage.new(:plural)
|
|
67
|
+
# po.msgid = "An apple"
|
|
68
|
+
# po.msgid_plural = "Apples"
|
|
69
|
+
# po.sources = ["foo.rb:200", "bar.rb:300"]
|
|
70
|
+
# ary << po
|
|
71
|
+
# # Simple message with the message context
|
|
72
|
+
# po = PoMessage.new(:msgctxt)
|
|
73
|
+
# po.msgctxt = "context"
|
|
74
|
+
# po.msgid = "hello"
|
|
75
|
+
# po.sources = ["foo.rb:200", "bar.rb:300"]
|
|
76
|
+
# ary << po
|
|
77
|
+
# # Plural message with the message context.
|
|
78
|
+
# po = PoMessage.new(:msgctxt_plural)
|
|
79
|
+
# po.msgctxt = "context"
|
|
80
|
+
# po.msgid = "An apple"
|
|
81
|
+
# po.msgid_plural = "Apples"
|
|
82
|
+
# po.sources = ["foo.rb:200", "bar.rb:300"]
|
|
83
|
+
# ary << po
|
|
84
|
+
# return ary
|
|
59
85
|
# end
|
|
60
86
|
# end
|
|
61
|
-
#
|
|
87
|
+
#
|
|
62
88
|
# GetText::RGetText.add_parser(FooParser)
|
|
63
89
|
def add_parser(klass)
|
|
64
90
|
@ex_parsers.insert(0, klass)
|
|
@@ -102,6 +128,7 @@ TITLE
|
|
|
102
128
|
|
|
103
129
|
def parse(paths) # :nodoc:
|
|
104
130
|
pomessages = []
|
|
131
|
+
paths = [paths] if paths.kind_of? String
|
|
105
132
|
paths.each do |path|
|
|
106
133
|
begin
|
|
107
134
|
@ex_parsers.each do |klass|
|
|
@@ -119,7 +146,7 @@ TITLE
|
|
|
119
146
|
end
|
|
120
147
|
|
|
121
148
|
# Save the previous target.
|
|
122
|
-
existing = pomessages.
|
|
149
|
+
existing = pomessages.empty? ? nil : pomessages.index(pomessages.find {|t| t == pomessage})
|
|
123
150
|
if existing
|
|
124
151
|
pomessage = pomessages[existing].merge(pomessage)
|
|
125
152
|
pomessages[existing] = pomessage
|
|
@@ -187,11 +214,9 @@ TITLE
|
|
|
187
214
|
elsif ! paths
|
|
188
215
|
paths, out = check_options
|
|
189
216
|
end
|
|
190
|
-
|
|
191
217
|
if paths.size == 0
|
|
192
218
|
raise ArgumentError, _("no input files")
|
|
193
219
|
end
|
|
194
|
-
|
|
195
220
|
if out.is_a? String
|
|
196
221
|
File.open(File.expand_path(out), "w+") do |file|
|
|
197
222
|
file.puts generate_pot_header
|
|
@@ -205,8 +230,8 @@ TITLE
|
|
|
205
230
|
end
|
|
206
231
|
end
|
|
207
232
|
extend self
|
|
208
|
-
# Creates a po-file from targetfiles(ruby-script-files, .rhtml files, glade-2 XML files),
|
|
209
|
-
# then output the result to out. If no parameter is set, it behaves same as command line tools(rgettet).
|
|
233
|
+
# Creates a po-file from targetfiles(ruby-script-files, .rhtml files, glade-2 XML files),
|
|
234
|
+
# then output the result to out. If no parameter is set, it behaves same as command line tools(rgettet).
|
|
210
235
|
#
|
|
211
236
|
# This function is a part of GetText.create_pofiles.
|
|
212
237
|
# Usually you don't need to call this function directly.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
=begin
|
|
2
4
|
rmsgfmt.rb - Generate a .mo
|
|
3
5
|
|
|
@@ -23,13 +25,13 @@ module GetText
|
|
|
23
25
|
|
|
24
26
|
def run(targetfile = nil, output_path = nil) # :nodoc:
|
|
25
27
|
unless targetfile
|
|
26
|
-
|
|
28
|
+
targetfile, output_path = check_options
|
|
27
29
|
end
|
|
28
30
|
unless targetfile
|
|
29
|
-
|
|
31
|
+
raise ArgumentError, _("no input files")
|
|
30
32
|
end
|
|
31
33
|
unless output_path
|
|
32
|
-
|
|
34
|
+
output_path = "messages.mo"
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
parser = PoParser.new
|
|
@@ -68,8 +70,8 @@ module GetText
|
|
|
68
70
|
[ARGV[0], output]
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
|
-
|
|
72
|
-
# Creates a mo-file from a targetfile(po-file), then output the result to out.
|
|
73
|
+
|
|
74
|
+
# Creates a mo-file from a targetfile(po-file), then output the result to out.
|
|
73
75
|
# If no parameter is set, it behaves same as command line tools(rmsgfmt).
|
|
74
76
|
# * targetfile: An Array of po-files or nil.
|
|
75
77
|
# * output_path: output path.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
=begin
|
|
2
4
|
rmsgmerge.rb - Merge old .po to new .po
|
|
3
5
|
|
|
@@ -14,60 +16,60 @@ require 'gettext/tools/poparser'
|
|
|
14
16
|
require 'rbconfig'
|
|
15
17
|
|
|
16
18
|
module GetText
|
|
17
|
-
|
|
19
|
+
|
|
18
20
|
module RMsgMerge
|
|
19
|
-
|
|
20
|
-
class PoData #:nodoc:
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
class PoData #:nodoc:
|
|
23
|
+
|
|
22
24
|
attr_reader :msgids
|
|
23
|
-
|
|
25
|
+
|
|
24
26
|
def initialize
|
|
25
27
|
@msgid2msgstr = {}
|
|
26
28
|
@msgid2comment = {}
|
|
27
29
|
@msgids = []
|
|
28
30
|
end
|
|
29
|
-
|
|
31
|
+
|
|
30
32
|
def set_comment(msgid_or_sym, comment)
|
|
31
|
-
@msgid2comment[msgid_or_sym] = comment
|
|
33
|
+
@msgid2comment[msgid_or_sym] = comment
|
|
32
34
|
end
|
|
33
|
-
|
|
35
|
+
|
|
34
36
|
def msgstr(msgid)
|
|
35
37
|
@msgid2msgstr[msgid]
|
|
36
38
|
end
|
|
37
|
-
|
|
39
|
+
|
|
38
40
|
def comment(msgid)
|
|
39
41
|
@msgid2comment[msgid]
|
|
40
42
|
end
|
|
41
|
-
|
|
43
|
+
|
|
42
44
|
def [](msgid)
|
|
43
45
|
@msgid2msgstr[msgid]
|
|
44
46
|
end
|
|
45
|
-
|
|
47
|
+
|
|
46
48
|
def []=(msgid, msgstr)
|
|
47
49
|
# Retain the order
|
|
48
50
|
unless @msgid2msgstr[msgid]
|
|
49
51
|
@msgids << msgid
|
|
50
52
|
end
|
|
51
|
-
|
|
53
|
+
|
|
52
54
|
@msgid2msgstr[msgid] = msgstr
|
|
53
55
|
end
|
|
54
|
-
|
|
56
|
+
|
|
55
57
|
def each_msgid
|
|
56
58
|
arr = @msgids.delete_if{|i| Symbol === i or i == ''}
|
|
57
59
|
arr.each do |i|
|
|
58
60
|
yield i
|
|
59
61
|
end
|
|
60
62
|
end
|
|
61
|
-
|
|
63
|
+
|
|
62
64
|
def msgid?(msgid)
|
|
63
65
|
!(Symbol === msgid) and @msgid2msgstr[msgid] and (msgid != '')
|
|
64
66
|
end
|
|
65
|
-
|
|
67
|
+
|
|
66
68
|
# Is it necessary to implement this method?
|
|
67
69
|
def search_msgid_fuzzy(msgid, used_msgids)
|
|
68
70
|
nil
|
|
69
71
|
end
|
|
70
|
-
|
|
72
|
+
|
|
71
73
|
def nplural
|
|
72
74
|
unless @msgid2msgstr['']
|
|
73
75
|
return 0
|
|
@@ -77,53 +79,53 @@ module GetText
|
|
|
77
79
|
else
|
|
78
80
|
return 0
|
|
79
81
|
end
|
|
80
|
-
|
|
82
|
+
|
|
81
83
|
end
|
|
82
84
|
end
|
|
83
|
-
|
|
85
|
+
|
|
84
86
|
def generate_po
|
|
85
87
|
str = ''
|
|
86
88
|
str << generate_po_header
|
|
87
|
-
|
|
89
|
+
|
|
88
90
|
self.each_msgid do |id|
|
|
89
|
-
str << self.generate_po_entry(id)
|
|
91
|
+
str << self.generate_po_entry(id)
|
|
90
92
|
end
|
|
91
|
-
|
|
92
|
-
str << @msgid2comment[:last]
|
|
93
|
-
str
|
|
93
|
+
|
|
94
|
+
str << @msgid2comment[:last]
|
|
95
|
+
str
|
|
94
96
|
end
|
|
95
|
-
|
|
97
|
+
|
|
96
98
|
def generate_po_header
|
|
97
99
|
str = ""
|
|
98
|
-
|
|
100
|
+
|
|
99
101
|
str << @msgid2comment[''].strip << "\n"
|
|
100
|
-
str << 'msgid ""' << "\n"
|
|
102
|
+
str << 'msgid ""' << "\n"
|
|
101
103
|
str << 'msgstr ""' << "\n"
|
|
102
104
|
msgstr = @msgid2msgstr[''].gsub(/"/, '\"').gsub(/\r/, '')
|
|
103
105
|
msgstr = msgstr.gsub(/^(.*)$/, '"\1\n"')
|
|
104
106
|
str << msgstr
|
|
105
107
|
str << "\n"
|
|
106
|
-
|
|
108
|
+
|
|
107
109
|
str
|
|
108
110
|
end
|
|
109
|
-
|
|
111
|
+
|
|
110
112
|
def generate_po_entry(msgid)
|
|
111
113
|
str = ""
|
|
112
114
|
str << @msgid2comment[msgid]
|
|
113
115
|
if str[-1] != "\n"[0]
|
|
114
116
|
str << "\n"
|
|
115
117
|
end
|
|
116
|
-
|
|
118
|
+
|
|
117
119
|
id = msgid.gsub(/"/, '\"').gsub(/\r/, '')
|
|
118
120
|
msgstr = @msgid2msgstr[msgid].gsub(/"/, '\"').gsub(/\r/, '')
|
|
119
121
|
|
|
120
122
|
if id.include?("\000")
|
|
121
|
-
ids = id.split(/\000/)
|
|
123
|
+
ids = id.split(/\000/)
|
|
122
124
|
str << "msgid " << __conv(ids[0]) << "\n"
|
|
123
125
|
ids[1..-1].each do |single_id|
|
|
124
126
|
str << "msgid_plural " << __conv(single_id) << "\n"
|
|
125
127
|
end
|
|
126
|
-
|
|
128
|
+
|
|
127
129
|
msgstr.split("\000").each_with_index do |m, n|
|
|
128
130
|
str << "msgstr[#{n}] " << __conv(m) << "\n"
|
|
129
131
|
end
|
|
@@ -131,11 +133,11 @@ module GetText
|
|
|
131
133
|
str << "msgid " << __conv(id) << "\n"
|
|
132
134
|
str << "msgstr " << __conv(msgstr) << "\n"
|
|
133
135
|
end
|
|
134
|
-
|
|
136
|
+
|
|
135
137
|
str << "\n"
|
|
136
138
|
str
|
|
137
139
|
end
|
|
138
|
-
|
|
140
|
+
|
|
139
141
|
def __conv(str)
|
|
140
142
|
s = ''
|
|
141
143
|
|
|
@@ -145,34 +147,34 @@ module GetText
|
|
|
145
147
|
else
|
|
146
148
|
s << '"' << str.sub("\n", "\\n") << '"'
|
|
147
149
|
end
|
|
148
|
-
|
|
150
|
+
|
|
149
151
|
s.rstrip
|
|
150
152
|
end
|
|
151
|
-
|
|
153
|
+
|
|
152
154
|
end
|
|
153
|
-
|
|
155
|
+
|
|
154
156
|
class Merger #:nodoc:
|
|
155
|
-
|
|
157
|
+
|
|
156
158
|
# From GNU gettext source.
|
|
157
|
-
#
|
|
159
|
+
#
|
|
158
160
|
# Merge the reference with the definition: take the #. and
|
|
159
|
-
#
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
# #: comments from the reference, take the # comments from
|
|
162
|
+
# the definition, take the msgstr from the definition. Add
|
|
163
|
+
# this merged entry to the output message list.
|
|
162
164
|
DOT_COMMENT_RE = /\A#\./
|
|
163
165
|
SEMICOLON_COMMENT_RE = /\A#\:/
|
|
164
166
|
FUZZY_RE = /\A#\,/
|
|
165
167
|
NOT_SPECIAL_COMMENT_RE = /\A#([^:.,]|\z)/
|
|
166
|
-
|
|
168
|
+
|
|
167
169
|
CRLF_RE = /\r?\n/
|
|
168
170
|
POT_DATE_EXTRACT_RE = /POT-Creation-Date:\s*(.*)?\s*$/
|
|
169
171
|
POT_DATE_RE = /POT-Creation-Date:.*?$/
|
|
170
|
-
|
|
172
|
+
|
|
171
173
|
def merge(definition, reference)
|
|
172
174
|
# deep copy
|
|
173
|
-
result = Marshal.load( Marshal.dump(reference) )
|
|
174
|
-
|
|
175
|
-
used = []
|
|
175
|
+
result = Marshal.load( Marshal.dump(reference) )
|
|
176
|
+
|
|
177
|
+
used = []
|
|
176
178
|
merge_header(result, definition)
|
|
177
179
|
|
|
178
180
|
result.each_msgid do |msgid|
|
|
@@ -181,18 +183,18 @@ module GetText
|
|
|
181
183
|
merge_message(msgid, result, msgid, definition)
|
|
182
184
|
elsif other_msgid = definition.search_msgid_fuzzy(msgid, used)
|
|
183
185
|
used << other_msgid
|
|
184
|
-
merge_fuzzy_message(msgid, result, other_msgid, definition)
|
|
186
|
+
merge_fuzzy_message(msgid, result, other_msgid, definition)
|
|
185
187
|
elsif msgid.index("\000") and ( reference.msgstr(msgid).gsub("\000", '') == '' )
|
|
186
188
|
# plural
|
|
187
189
|
result[msgid] = "\000" * definition.nplural
|
|
188
190
|
else
|
|
189
191
|
change_reference_comment(msgid, result)
|
|
190
|
-
end
|
|
192
|
+
end
|
|
191
193
|
end
|
|
192
|
-
|
|
194
|
+
|
|
193
195
|
###################################################################
|
|
194
196
|
# msgids which are not used in reference are handled as obsolete. #
|
|
195
|
-
###################################################################
|
|
197
|
+
###################################################################
|
|
196
198
|
last_comment = result.comment(:last) || ''
|
|
197
199
|
definition.each_msgid do |msgid|
|
|
198
200
|
unless used.include?(msgid)
|
|
@@ -202,13 +204,13 @@ module GetText
|
|
|
202
204
|
end
|
|
203
205
|
end
|
|
204
206
|
result.set_comment(:last, last_comment)
|
|
205
|
-
|
|
207
|
+
|
|
206
208
|
result
|
|
207
209
|
end
|
|
208
|
-
|
|
210
|
+
|
|
209
211
|
def merge_message(msgid, target, def_msgid, definition)
|
|
210
212
|
merge_comment(msgid, target, def_msgid, definition)
|
|
211
|
-
|
|
213
|
+
|
|
212
214
|
############################################
|
|
213
215
|
# check mismatch of msgid and msgid_plural #
|
|
214
216
|
############################################
|
|
@@ -216,10 +218,10 @@ module GetText
|
|
|
216
218
|
if msgid.index("\000")
|
|
217
219
|
if def_msgstr.index("\000")
|
|
218
220
|
# OK
|
|
219
|
-
target[msgid] = def_msgstr
|
|
221
|
+
target[msgid] = def_msgstr
|
|
220
222
|
else
|
|
221
223
|
# NG
|
|
222
|
-
s = ''
|
|
224
|
+
s = ''
|
|
223
225
|
definition.nplural.times {
|
|
224
226
|
s << def_msgstr
|
|
225
227
|
s << "\000"
|
|
@@ -236,29 +238,29 @@ module GetText
|
|
|
236
238
|
end
|
|
237
239
|
end
|
|
238
240
|
end
|
|
239
|
-
|
|
241
|
+
|
|
240
242
|
# for the future
|
|
241
243
|
def merge_fuzzy_message(msgid, target, def_msgid, definition)
|
|
242
244
|
merge_message(msgid, target, def_msgid, definition)
|
|
243
245
|
end
|
|
244
|
-
|
|
246
|
+
|
|
245
247
|
def merge_comment(msgid, target, def_msgid, definition)
|
|
246
248
|
ref_comment = target.comment(msgid)
|
|
247
249
|
def_comment = definition.comment(def_msgid)
|
|
248
|
-
|
|
250
|
+
|
|
249
251
|
normal_comment = []
|
|
250
252
|
dot_comment = []
|
|
251
253
|
semi_comment = []
|
|
252
254
|
is_fuzzy = false
|
|
253
|
-
|
|
254
|
-
def_comment.split(CRLF_RE).each do |l|
|
|
255
|
+
|
|
256
|
+
def_comment.split(CRLF_RE).each do |l|
|
|
255
257
|
if NOT_SPECIAL_COMMENT_RE =~ l
|
|
256
258
|
normal_comment << l
|
|
257
|
-
end
|
|
259
|
+
end
|
|
258
260
|
end
|
|
259
|
-
|
|
261
|
+
|
|
260
262
|
ref_comment.split(CRLF_RE).each do |l|
|
|
261
|
-
if DOT_COMMENT_RE =~ l
|
|
263
|
+
if DOT_COMMENT_RE =~ l
|
|
262
264
|
dot_comment << l
|
|
263
265
|
elsif SEMICOLON_COMMENT_RE =~ l
|
|
264
266
|
semi_comment << l
|
|
@@ -266,19 +268,19 @@ module GetText
|
|
|
266
268
|
is_fuzzy = true
|
|
267
269
|
end
|
|
268
270
|
end
|
|
269
|
-
|
|
271
|
+
|
|
270
272
|
str = format_comment(normal_comment, dot_comment, semi_comment, is_fuzzy)
|
|
271
273
|
target.set_comment(msgid, str)
|
|
272
274
|
end
|
|
273
|
-
|
|
275
|
+
|
|
274
276
|
def change_reference_comment(msgid, podata)
|
|
275
277
|
normal_comment = []
|
|
276
278
|
dot_comment = []
|
|
277
279
|
semi_comment = []
|
|
278
280
|
is_fuzzy = false
|
|
279
|
-
|
|
281
|
+
|
|
280
282
|
podata.comment(msgid).split(CRLF_RE).each do |l|
|
|
281
|
-
if DOT_COMMENT_RE =~ l
|
|
283
|
+
if DOT_COMMENT_RE =~ l
|
|
282
284
|
dot_comment << l
|
|
283
285
|
elsif SEMICOLON_COMMENT_RE =~ l
|
|
284
286
|
semi_comment << l
|
|
@@ -288,14 +290,14 @@ module GetText
|
|
|
288
290
|
normal_comment << l
|
|
289
291
|
end
|
|
290
292
|
end
|
|
291
|
-
|
|
293
|
+
|
|
292
294
|
str = format_comment(normal_comment, dot_comment, semi_comment, is_fuzzy)
|
|
293
|
-
podata.set_comment(msgid, str)
|
|
295
|
+
podata.set_comment(msgid, str)
|
|
294
296
|
end
|
|
295
|
-
|
|
297
|
+
|
|
296
298
|
def format_comment(normal_comment, dot_comment, semi_comment, is_fuzzy)
|
|
297
299
|
str = ''
|
|
298
|
-
|
|
300
|
+
|
|
299
301
|
str << normal_comment.join("\n").gsub(/^#(\s*)/){|sss|
|
|
300
302
|
if $1 == ""
|
|
301
303
|
"# "
|
|
@@ -306,7 +308,7 @@ module GetText
|
|
|
306
308
|
if normal_comment.size > 0
|
|
307
309
|
str << "\n"
|
|
308
310
|
end
|
|
309
|
-
|
|
311
|
+
|
|
310
312
|
str << dot_comment.join("\n").gsub(/^#.(\s*)/){|sss|
|
|
311
313
|
if $1 == ""
|
|
312
314
|
"#. "
|
|
@@ -317,48 +319,48 @@ module GetText
|
|
|
317
319
|
if dot_comment.size > 0
|
|
318
320
|
str << "\n"
|
|
319
321
|
end
|
|
320
|
-
|
|
322
|
+
|
|
321
323
|
str << semi_comment.join("\n").gsub(/^#:\s*/, "#: ")
|
|
322
324
|
if semi_comment.size > 0
|
|
323
325
|
str << "\n"
|
|
324
326
|
end
|
|
325
|
-
|
|
327
|
+
|
|
326
328
|
if is_fuzzy
|
|
327
329
|
str << "#, fuzzy\n"
|
|
328
330
|
end
|
|
329
|
-
|
|
331
|
+
|
|
330
332
|
str
|
|
331
333
|
end
|
|
332
|
-
|
|
334
|
+
|
|
333
335
|
def merge_header(target, definition)
|
|
334
336
|
merge_comment('', target, '', definition)
|
|
335
|
-
|
|
337
|
+
|
|
336
338
|
msg = target.msgstr('')
|
|
337
339
|
def_msg = definition.msgstr('')
|
|
338
340
|
if POT_DATE_EXTRACT_RE =~ msg
|
|
339
341
|
time = $1
|
|
340
342
|
def_msg = def_msg.sub(POT_DATE_RE, "POT-Creation-Date: #{time}")
|
|
341
343
|
end
|
|
342
|
-
|
|
344
|
+
|
|
343
345
|
target[''] = def_msg
|
|
344
346
|
end
|
|
345
|
-
|
|
347
|
+
|
|
346
348
|
end
|
|
347
|
-
|
|
348
|
-
end
|
|
349
|
-
|
|
349
|
+
|
|
350
|
+
end
|
|
351
|
+
|
|
350
352
|
end
|
|
351
353
|
|
|
352
354
|
module GetText::RMsgMerge #:nodoc:
|
|
353
355
|
|
|
354
356
|
class Config #:nodoc:
|
|
355
|
-
|
|
357
|
+
|
|
356
358
|
attr_accessor :defpo, :refpot, :output, :fuzzy, :update
|
|
357
|
-
|
|
359
|
+
|
|
358
360
|
# update mode options
|
|
359
361
|
attr_accessor :backup, :suffix
|
|
360
|
-
|
|
361
|
-
=begin
|
|
362
|
+
|
|
363
|
+
=begin
|
|
362
364
|
The result is written back to def.po.
|
|
363
365
|
--backup=CONTROL make a backup of def.po
|
|
364
366
|
--suffix=SUFFIX override the usual backup suffix
|
|
@@ -370,8 +372,8 @@ the VERSION_CONTROL environment variable. Here are the values:
|
|
|
370
372
|
simple, never always make simple backups
|
|
371
373
|
The backup suffix is `~', unless set with --suffix or the SIMPLE_BACKUP_SUFFIX
|
|
372
374
|
environment variable.
|
|
373
|
-
=end
|
|
374
|
-
|
|
375
|
+
=end
|
|
376
|
+
|
|
375
377
|
def initialize
|
|
376
378
|
@output = STDOUT
|
|
377
379
|
@fuzzy = nil
|
|
@@ -380,23 +382,23 @@ environment variable.
|
|
|
380
382
|
@suffix= ENV["SIMPLE_BACKUP_SUFFIX"] || "~"
|
|
381
383
|
@input_dirs = ["."]
|
|
382
384
|
end
|
|
383
|
-
|
|
385
|
+
|
|
384
386
|
end
|
|
385
|
-
|
|
387
|
+
|
|
386
388
|
end
|
|
387
389
|
|
|
388
390
|
module GetText
|
|
389
|
-
|
|
391
|
+
|
|
390
392
|
module RMsgMerge
|
|
391
393
|
extend GetText
|
|
392
394
|
extend self
|
|
393
395
|
|
|
394
396
|
bindtextdomain("rgettext")
|
|
395
|
-
|
|
397
|
+
|
|
396
398
|
# constant values
|
|
397
399
|
VERSION = GetText::VERSION
|
|
398
400
|
DATE = %w($Date: 2007/07/21 15:03:05 $)[1]
|
|
399
|
-
|
|
401
|
+
|
|
400
402
|
def check_options(config)
|
|
401
403
|
opts = OptionParser.new
|
|
402
404
|
opts.banner = _("Usage: %s def.po ref.pot [-o output.pot]") % $0
|
|
@@ -405,7 +407,7 @@ module GetText
|
|
|
405
407
|
opts.separator(_("Merges two Uniforum style .po files together. The def.po file is an existing PO file with translations. The ref.pot file is the last created PO file with up-to-date source references. ref.pot is generally created by rgettext."))
|
|
406
408
|
opts.separator("")
|
|
407
409
|
opts.separator(_("Specific options:"))
|
|
408
|
-
|
|
410
|
+
|
|
409
411
|
opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
|
|
410
412
|
unless FileTest.exist? out
|
|
411
413
|
config.output = out
|
|
@@ -414,49 +416,49 @@ module GetText
|
|
|
414
416
|
#exit 1
|
|
415
417
|
end
|
|
416
418
|
end
|
|
417
|
-
|
|
419
|
+
|
|
418
420
|
#opts.on("-F", "--fuzzy-matching")
|
|
419
|
-
|
|
421
|
+
|
|
420
422
|
opts.on_tail("--version", _("display version information and exit")) do
|
|
421
423
|
puts "#{$0} #{VERSION} (#{DATE})"
|
|
422
|
-
|
|
424
|
+
puts "#{File.join(::Config::CONFIG["bindir"], ::Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
|
423
425
|
exit
|
|
424
426
|
end
|
|
425
|
-
|
|
427
|
+
|
|
426
428
|
opts.parse!(ARGV)
|
|
427
|
-
|
|
429
|
+
|
|
428
430
|
if ARGV.size != 2
|
|
429
431
|
puts opts.help
|
|
430
432
|
exit 1
|
|
431
433
|
end
|
|
432
|
-
|
|
434
|
+
|
|
433
435
|
config.defpo = ARGV[0]
|
|
434
436
|
config.refpot = ARGV[1]
|
|
435
437
|
end
|
|
436
|
-
|
|
438
|
+
|
|
437
439
|
def run(reference = nil, definition = nil, out = STDOUT)
|
|
438
440
|
config = GetText::RMsgMerge::Config.new
|
|
439
441
|
config.refpot = reference
|
|
440
442
|
config.defpo = definition
|
|
441
443
|
config.output = out
|
|
442
|
-
|
|
444
|
+
|
|
443
445
|
check_options(config)
|
|
444
|
-
|
|
446
|
+
|
|
445
447
|
if config.defpo.nil?
|
|
446
448
|
raise ArgumentError, _("definition po is not given.")
|
|
447
|
-
elsif config.refpot.nil?
|
|
449
|
+
elsif config.refpot.nil?
|
|
448
450
|
raise ArgumentError, _("reference pot is not given.")
|
|
449
451
|
end
|
|
450
|
-
|
|
452
|
+
|
|
451
453
|
parser = PoParser.new
|
|
452
454
|
defpo = parser.parse_file(config.defpo, PoData.new, false)
|
|
453
455
|
refpot = parser.parse_file(config.refstrrefstr, PoData.new, false)
|
|
454
|
-
|
|
456
|
+
|
|
455
457
|
m = Merger.new
|
|
456
|
-
result = m.merge(defpo, refpot)
|
|
458
|
+
result = m.merge(defpo, refpot)
|
|
457
459
|
p result if $DEBUG
|
|
458
460
|
print result.generate_po if $DEBUG
|
|
459
|
-
|
|
461
|
+
|
|
460
462
|
begin
|
|
461
463
|
if out.is_a? String
|
|
462
464
|
File.open(File.expand_path(out), "w+") do |file|
|
|
@@ -468,16 +470,16 @@ module GetText
|
|
|
468
470
|
ensure
|
|
469
471
|
out.close
|
|
470
472
|
end
|
|
471
|
-
end
|
|
472
|
-
|
|
473
|
+
end
|
|
474
|
+
|
|
473
475
|
end
|
|
474
|
-
|
|
476
|
+
|
|
475
477
|
end
|
|
476
478
|
|
|
477
479
|
|
|
478
480
|
|
|
479
481
|
module GetText
|
|
480
|
-
|
|
482
|
+
|
|
481
483
|
# Experimental
|
|
482
484
|
def rmsgmerge(reference = nil, definition = nil, out = STDOUT)
|
|
483
485
|
RMsgMerge.run(reference, definition, out)
|
|
@@ -489,10 +491,10 @@ end
|
|
|
489
491
|
|
|
490
492
|
if $0 == __FILE__ then
|
|
491
493
|
require 'pp'
|
|
492
|
-
|
|
494
|
+
|
|
493
495
|
#parser = GetText::RMsgMerge::PoParser.new;
|
|
494
496
|
#parser = GetText::PoParser.new;
|
|
495
497
|
#pp parser.parse(ARGF.read)
|
|
496
|
-
|
|
498
|
+
|
|
497
499
|
GetText.rmsgmerge
|
|
498
500
|
end
|