gettext 2.3.3 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/text/news.md +37 -0
- data/gettext.gemspec +1 -0
- data/lib/gettext/runtime/mo.rb +382 -0
- data/lib/gettext/runtime/mofile.rb +24 -366
- data/lib/gettext/runtime/textdomain.rb +17 -17
- data/lib/gettext/tools.rb +1 -1
- data/lib/gettext/tools/msgfmt.rb +2 -2
- data/lib/gettext/tools/msginit.rb +16 -15
- data/lib/gettext/tools/msgmerge.rb +258 -255
- data/lib/gettext/tools/parser/ruby.rb +24 -24
- data/lib/gettext/tools/po.rb +256 -0
- data/lib/gettext/tools/po_entry.rb +355 -0
- data/lib/gettext/tools/poparser.rb +118 -16
- data/lib/gettext/tools/xgettext.rb +56 -58
- data/lib/gettext/version.rb +1 -1
- data/samples/po/hello.pot +3 -3
- data/samples/po/hello2.pot +3 -3
- data/samples/po/hello_glade2.pot +3 -3
- data/samples/po/hello_gtk2.pot +3 -3
- data/samples/po/hello_noop.pot +3 -3
- data/samples/po/hello_plural.pot +3 -3
- data/samples/po/hello_tk.pot +3 -3
- data/src/poparser.ry +111 -9
- data/test/parser/test_ruby.rb +17 -13
- data/test/po/_.pot +3 -3
- data/test/po/backslash.pot +3 -3
- data/test/po/non_ascii.pot +3 -3
- data/test/po/np_.pot +5 -4
- data/test/po/ns_.pot +3 -3
- data/test/po/p_.pot +3 -3
- data/test/po/s_.pot +3 -3
- data/test/po/untranslated.pot +3 -3
- data/test/{test_mofile.rb → test_mo.rb} +3 -3
- data/test/test_parser.rb +13 -12
- data/test/test_po_entry.rb +329 -0
- data/test/test_po_parser.rb +209 -8
- data/test/tools/test_msginit.rb +0 -2
- data/test/tools/test_msgmerge.rb +427 -50
- data/test/tools/test_po.rb +487 -0
- data/test/tools/test_xgettext.rb +1 -1
- metadata +28 -45
- data/data/locale/de/LC_MESSAGES/gettext.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/el/LC_MESSAGES/gettext.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
- data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
- data/data/locale/uk/LC_MESSAGES/rgettext.mo +0 -0
- data/lib/gettext/tools/pomessage.rb +0 -232
- data/samples/locale/bg/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/bs/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/ca/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/cs/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/de/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/el/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/es/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/fr/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/hr/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/hu/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/it/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/ja/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/ko/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/lv/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/nb/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/nl/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/pt_BR/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/ru/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/sr/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/sv/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/uk/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/vi/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/hello_gtk.mo +0 -0
- data/samples/locale/zh_TW/LC_MESSAGES/hello_gtk.mo +0 -0
- data/test/po/ascii.pot +0 -23
- data/test/po/no_exist_msgid.pot +0 -20
- data/test/po/not_existed_msgid.pot +0 -20
- data/test/test_po_message.rb +0 -118
data/test/tools/test_msginit.rb
CHANGED
@@ -331,7 +331,6 @@ msgstr ""
|
|
331
331
|
"Content-Type: text/plain; charset=UTF-8\\n"
|
332
332
|
"Content-Transfer-Encoding: 8bit\\n"
|
333
333
|
"Plural-Forms: #{plural_forms}\\n"
|
334
|
-
|
335
334
|
EOF
|
336
335
|
end
|
337
336
|
|
@@ -361,7 +360,6 @@ msgstr ""
|
|
361
360
|
"Content-Type: text/plain; charset=UTF-8\\n"
|
362
361
|
"Content-Transfer-Encoding: 8bit\\n"
|
363
362
|
"Plural-Forms: #{plural_forms}\\n"
|
364
|
-
|
365
363
|
EOF
|
366
364
|
end
|
367
365
|
end
|
data/test/tools/test_msgmerge.rb
CHANGED
@@ -26,85 +26,152 @@ class TestToolsMsgMerge < Test::Unit::TestCase
|
|
26
26
|
@po_data = GetText::Tools::MsgMerge::PoData.new
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
def test_msgids
|
30
|
+
@po_data["hello"] = "bonjour"
|
31
|
+
@po_data["he"] = "il"
|
32
|
+
|
33
|
+
assert_equal(["he", "hello"], @po_data.msgids.sort)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_each_msgids
|
37
|
+
@po_data["hello"] = "bonjour"
|
38
|
+
@po_data["he"] = "il"
|
39
|
+
@po_data[""] = "header"
|
40
|
+
@po_data[:last] = ""
|
41
|
+
|
42
|
+
msgids = []
|
43
|
+
@po_data.each_msgid do |msgid|
|
44
|
+
msgids << msgid
|
45
|
+
end
|
46
|
+
assert_equal(["he", "hello"], msgids.sort)
|
47
|
+
end
|
48
|
+
|
49
|
+
class TestAddToExistingEntry < self
|
50
|
+
def test_msgctxt
|
51
|
+
msgctxt = "msgctxt"
|
52
|
+
msgid = "msgid"
|
53
|
+
original_string = "#{msgctxt}\004#{msgid}"
|
54
|
+
msgstr = "msgstr"
|
55
|
+
|
56
|
+
po_data = GetText::Tools::MsgMerge::PoData.new
|
57
|
+
po_data[original_string] = msgstr
|
58
|
+
|
59
|
+
assert_equal(msgctxt, po_data.po[msgctxt, msgid].msgctxt)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_msgid_plural
|
63
|
+
msgid = "msgid"
|
64
|
+
msgid_plural = "msgid_plural"
|
65
|
+
original_string = "#{msgid}\000#{msgid_plural}"
|
66
|
+
msgstr = "msgstr"
|
67
|
+
|
68
|
+
po_data = GetText::Tools::MsgMerge::PoData.new
|
69
|
+
po_data[msgid] = msgstr
|
70
|
+
assert_equal(nil, po_data.po[msgid].msgid_plural)
|
71
|
+
|
72
|
+
po_data[original_string] = msgstr
|
73
|
+
assert_equal(msgid_plural, po_data.po[msgid].msgid_plural)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_msgctxt_and_msgid_plural
|
77
|
+
msgctxt = "msgctxt"
|
78
|
+
msgid = "msgid"
|
79
|
+
msgid_plural = "msgid_plural"
|
80
|
+
original_string = "#{msgctxt}\004#{msgid}\000#{msgid_plural}"
|
81
|
+
msgstr = "msgstr"
|
82
|
+
|
83
|
+
po_data = GetText::Tools::MsgMerge::PoData.new
|
84
|
+
po_data[original_string] = msgstr
|
85
|
+
|
86
|
+
assert_equal(msgctxt, po_data.po[msgctxt, msgid].msgctxt)
|
87
|
+
assert_equal(msgid_plural, po_data.po[msgctxt, msgid].msgid_plural)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class TestGeneratePo < self
|
92
|
+
def test_comment_and_msgid_and_msgstr
|
93
|
+
header_entry_comment = "# header entry comment."
|
94
|
+
header_entry = "header\nentry\n"
|
95
|
+
comment = "#: test.rb:10"
|
96
|
+
msgid = "Hello"
|
97
|
+
msgstr = "Salut"
|
98
|
+
|
99
|
+
po = GetText::Tools::MsgMerge::PoData.new
|
100
|
+
po.set_comment("", header_entry_comment)
|
101
|
+
po[""] = header_entry
|
102
|
+
po[msgid] = msgstr
|
103
|
+
po.set_comment(msgid, comment)
|
104
|
+
|
105
|
+
expected_header_entry = ""
|
106
|
+
header_entry.each_line do |line|
|
107
|
+
expected_header_entry << "\"#{line.chomp}\\n\"\n"
|
108
|
+
end
|
109
|
+
expected_header_entry = expected_header_entry.chomp
|
110
|
+
expected_po = <<EOP
|
36
111
|
#{header_entry_comment}
|
37
112
|
msgid \"\"
|
38
113
|
msgstr \"\"
|
39
|
-
|
114
|
+
#{expected_header_entry}
|
40
115
|
|
41
116
|
#{comment}
|
42
117
|
msgid \"#{msgid}\"
|
43
118
|
msgstr \"#{msgstr}\"
|
44
119
|
EOP
|
120
|
+
assert_equal(expected_po, po.generate_po)
|
121
|
+
end
|
45
122
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
assert_equal(expected_po, po.generate_po)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_generate_po_including_obsolete_comment
|
56
|
-
obsolete_comment = <<EOC
|
57
|
-
#. #: test.rb:10
|
58
|
-
#. msgid \"Hello\"
|
59
|
-
#. msgstr \"Salut\"
|
123
|
+
def test_obsolete_comment
|
124
|
+
obsolete_comment =<<EOC
|
125
|
+
# test.rb:10
|
126
|
+
msgid \"Hello\"
|
127
|
+
msgstr \"Salut\"
|
60
128
|
EOC
|
61
|
-
|
129
|
+
header_entry_comment = "# header entry comment."
|
130
|
+
header_entry = "header entry"
|
131
|
+
|
132
|
+
po = GetText::Tools::MsgMerge::PoData.new
|
133
|
+
po.set_comment("", header_entry_comment)
|
134
|
+
po[""] = header_entry
|
135
|
+
po.set_comment(:last, obsolete_comment)
|
62
136
|
|
63
|
-
|
64
|
-
|
65
|
-
expected_po = <<EOP
|
137
|
+
expected_obsolete_comment = obsolete_comment.gsub(/^/, "#~ ").chomp
|
138
|
+
expected_po = <<EOP
|
66
139
|
#{header_entry_comment}
|
67
140
|
msgid \"\"
|
68
|
-
msgstr \"\"
|
69
|
-
\"#{header_entry}\\n\"
|
141
|
+
msgstr \"#{header_entry}\"
|
70
142
|
|
71
|
-
#{
|
143
|
+
#{expected_obsolete_comment}
|
72
144
|
EOP
|
145
|
+
assert_equal(expected_po, po.generate_po)
|
146
|
+
end
|
73
147
|
|
74
|
-
|
75
|
-
|
76
|
-
po[""] = header_entry
|
77
|
-
po.set_comment(:last, obsolete_comment)
|
78
|
-
|
79
|
-
assert_equal(expected_po, po.generate_po)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_generate_po_msgid_plural_and_empty_msgstr
|
83
|
-
msgid = "Singular message\000Plural message"
|
148
|
+
def test_msgid_plural_and_empty_msgstr
|
149
|
+
msgid = "Singular message\000Plural message"
|
84
150
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
151
|
+
@po_data[""] = "Plural-Forms: nplurals=2; plural=n != 1;\\n"
|
152
|
+
@po_data[msgid] = "\000"
|
153
|
+
@po_data.set_comment(msgid, "# plural message")
|
154
|
+
actual_po = @po_data.generate_po_entry(msgid)
|
155
|
+
expected_po = <<'EOE'
|
90
156
|
# plural message
|
91
157
|
msgid "Singular message"
|
92
158
|
msgid_plural "Plural message"
|
93
159
|
msgstr[0] ""
|
94
160
|
msgstr[1] ""
|
95
161
|
EOE
|
96
|
-
|
162
|
+
assert_equal(expected_po, actual_po)
|
163
|
+
end
|
97
164
|
end
|
98
165
|
|
99
|
-
class
|
166
|
+
class TestGeneratePOEntry < self
|
100
167
|
def test_msgid_plural
|
101
168
|
msgid = "Singular message\000Plural message"
|
102
169
|
|
103
170
|
@po_data[msgid] = "Singular translation\000Plural translation"
|
104
|
-
@po_data.set_comment(msgid, "#plural message")
|
171
|
+
@po_data.set_comment(msgid, "# plural message")
|
105
172
|
actual_po = @po_data.generate_po_entry(msgid)
|
106
173
|
expected_po = <<'EOE'
|
107
|
-
#plural message
|
174
|
+
# plural message
|
108
175
|
msgid "Singular message"
|
109
176
|
msgid_plural "Plural message"
|
110
177
|
msgstr[0] "Singular translation"
|
@@ -116,11 +183,11 @@ EOE
|
|
116
183
|
def test_msgctxt
|
117
184
|
msg_id = "Context\004Translation"
|
118
185
|
@po_data[msg_id] = "Translated"
|
119
|
-
@po_data.set_comment(msg_id, "#no comment")
|
186
|
+
@po_data.set_comment(msg_id, "# no comment")
|
120
187
|
|
121
188
|
entry = @po_data.generate_po_entry(msg_id)
|
122
189
|
assert_equal(<<-'EOE', entry)
|
123
|
-
#no comment
|
190
|
+
# no comment
|
124
191
|
msgctxt "Context"
|
125
192
|
msgid "Translation"
|
126
193
|
msgstr "Translated"
|
@@ -129,6 +196,316 @@ EOE
|
|
129
196
|
end
|
130
197
|
end
|
131
198
|
|
199
|
+
class TestSplitMsgid < self
|
200
|
+
def test_existed_msgctxt_and_msgid_plural
|
201
|
+
msgctxt = "msgctxt"
|
202
|
+
msgid = "msgid"
|
203
|
+
msgid_plural = "msgid_plural"
|
204
|
+
|
205
|
+
assert_equal([msgctxt, msgid, msgid_plural],
|
206
|
+
split_msgid("#{msgctxt}\004#{msgid}\000#{msgid_plural}"))
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_existed_msgctxt_only
|
210
|
+
msgctxt = "msgctxt"
|
211
|
+
msgid = "msgid"
|
212
|
+
|
213
|
+
assert_equal([msgctxt, msgid, nil],
|
214
|
+
split_msgid("#{msgctxt}\004#{msgid}"))
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_existed_msgid_plural_only
|
218
|
+
msgid = "msgid"
|
219
|
+
msgid_plural = "msgid_plural"
|
220
|
+
|
221
|
+
assert_equal([nil, msgid, msgid_plural],
|
222
|
+
split_msgid("#{msgid}\000#{msgid_plural}"))
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_not_existed
|
226
|
+
msgid = "msgid"
|
227
|
+
|
228
|
+
assert_equal([nil, msgid, nil], split_msgid(msgid))
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_empty_msgid
|
232
|
+
msgid = ""
|
233
|
+
|
234
|
+
assert_equal([nil, msgid, nil], split_msgid(msgid))
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_last_symbol_msgid
|
238
|
+
msgid = :last
|
239
|
+
|
240
|
+
assert_equal([nil, msgid, nil], split_msgid(msgid))
|
241
|
+
end
|
242
|
+
|
243
|
+
private
|
244
|
+
def split_msgid(msgid)
|
245
|
+
po_data = GetText::Tools::MsgMerge::PoData.new
|
246
|
+
po_data.send(:split_msgid, msgid)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
class TestParseComment < self
|
251
|
+
def setup
|
252
|
+
@po_data = GetText::Tools::MsgMerge::PoData.new
|
253
|
+
@entry = @po_data.send(:generate_entry, "test")
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_translator_comment
|
257
|
+
comment = "# translator comment"
|
258
|
+
parsed_comment = parse_comment(comment).translator_comment
|
259
|
+
assert_equal("translator comment\n", parsed_comment)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_extracted_comment
|
263
|
+
comment = "#. extracted comment"
|
264
|
+
parsed_comment = parse_comment(comment).extracted_comment
|
265
|
+
assert_equal("extracted comment\n", parsed_comment)
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_references
|
269
|
+
comment = "#: reference.rb:10"
|
270
|
+
parsed_comment = parse_comment(comment).references
|
271
|
+
assert_equal(["reference.rb:10"], parsed_comment)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_flag
|
275
|
+
comment = "#, fuzzy"
|
276
|
+
parsed_comment = parse_comment(comment).flag
|
277
|
+
assert_equal("fuzzy\n", parsed_comment)
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_previous
|
281
|
+
comment = "#| msgid the previous msgid"
|
282
|
+
parsed_comment = parse_comment(comment).previous
|
283
|
+
assert_equal("msgid the previous msgid\n", parsed_comment)
|
284
|
+
end
|
285
|
+
|
286
|
+
private
|
287
|
+
def parse_comment(comment)
|
288
|
+
@po_data.send(:parse_comment, comment, @entry)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
class TestMerger < self
|
293
|
+
def setup
|
294
|
+
@merger = GetText::Tools::MsgMerge::Merger.new
|
295
|
+
@po_data = GetText::Tools::MsgMerge::PoData.new
|
296
|
+
@po = GetText::PO.new
|
297
|
+
@pot = GetText::PO.new
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_add_entry
|
301
|
+
@po["hello"] = "bonjour"
|
302
|
+
@pot["hello"] = "bonjour"
|
303
|
+
@pot["he"] = "il"
|
304
|
+
merged_po = @merger.merge(@po, @pot)
|
305
|
+
|
306
|
+
assert_equal("bonjour", merged_po["hello"].msgstr)
|
307
|
+
assert_equal("il", merged_po["he"].msgstr)
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_different_msgstr
|
311
|
+
@po["hello"] = "salut"
|
312
|
+
@pot["hello"] = "bonjour"
|
313
|
+
merged_po = @merger.merge(@po, @pot)
|
314
|
+
|
315
|
+
assert_equal("salut", merged_po["hello"].msgstr)
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_similar_msgstr_for_fuzzy
|
319
|
+
@po["helol"] = "bonjour"
|
320
|
+
@pot["hello"] = ""
|
321
|
+
merged_po = @merger.merge(@po, @pot)
|
322
|
+
|
323
|
+
assert_false(merged_po.has_key?("helol"))
|
324
|
+
assert_true(merged_po.has_key?("hello"))
|
325
|
+
assert_equal("bonjour", merged_po["hello"].msgstr)
|
326
|
+
assert_equal("fuzzy", merged_po["hello"].flag)
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_nonexistent_msgctxt
|
330
|
+
@po["normal", "hello"] = generate_entry(:msgctxt => "normal",
|
331
|
+
:msgid => "hello",
|
332
|
+
:msgstr => "salut")
|
333
|
+
@pot["hello"] = generate_entry(:msgid => "hello",
|
334
|
+
:msgstr => "")
|
335
|
+
merged_po = @merger.merge(@po, @pot)
|
336
|
+
|
337
|
+
assert_false(merged_po.has_key?("normal", "hello"))
|
338
|
+
assert_true(merged_po.has_key?("hello"))
|
339
|
+
assert_equal("salut", merged_po["hello"].msgstr)
|
340
|
+
assert_equal("fuzzy", merged_po["hello"].flag)
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_msgid_plural
|
344
|
+
@po["he"] = generate_entry(:msgid => "he",
|
345
|
+
:msgid_plural => "thye",
|
346
|
+
:msgstr => "il\000ils")
|
347
|
+
@pot["he"] = generate_entry(:msgid => "he",
|
348
|
+
:msgid_plural => "they",
|
349
|
+
:msgstr => "")
|
350
|
+
merged_po = @merger.merge(@po, @pot)
|
351
|
+
|
352
|
+
assert_equal("il\000ils", merged_po["he"].msgstr)
|
353
|
+
assert_equal("they", merged_po["he"].msgid_plural)
|
354
|
+
assert_equal("fuzzy", merged_po["he"].flag)
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_translator_comment
|
358
|
+
@po["hello"] = generate_entry(:msgid => "hello",
|
359
|
+
:msgstr => "bonjour",
|
360
|
+
:translator_comment => "comment")
|
361
|
+
|
362
|
+
@pot["hello"] = generate_entry(:msgid => "hello",
|
363
|
+
:msgstr => "",
|
364
|
+
:translator_comment => "It's comments")
|
365
|
+
|
366
|
+
merged_po = @merger.merge(@po, @pot)
|
367
|
+
assert_equal("bonjour", merged_po["hello"].msgstr)
|
368
|
+
assert_equal("comment", merged_po["hello"].translator_comment)
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_extracted_comment
|
372
|
+
@po["hello"] = generate_entry(:msgid => "hello",
|
373
|
+
:msgstr => "bonjour",
|
374
|
+
:extracted_comment => "comment")
|
375
|
+
|
376
|
+
@pot["hello"] = generate_entry(:msgid => "hello",
|
377
|
+
:msgstr => "",
|
378
|
+
:extracted_comment => "extracted comments")
|
379
|
+
|
380
|
+
merged_po = @merger.merge(@po, @pot)
|
381
|
+
assert_equal("bonjour", merged_po["hello"].msgstr)
|
382
|
+
assert_equal("extracted comments", merged_po["hello"].extracted_comment)
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_references
|
386
|
+
references = ["file.rb:10", "helper.rb:10"]
|
387
|
+
pot_references = ["file.rb:10", "test.rb:25"]
|
388
|
+
@po["hello"] = generate_entry(:msgid => "hello",
|
389
|
+
:msgstr => "bonjour",
|
390
|
+
:references => references)
|
391
|
+
|
392
|
+
@pot["hello"] = generate_entry(:msgid => "hello",
|
393
|
+
:msgstr => "",
|
394
|
+
:references => pot_references)
|
395
|
+
|
396
|
+
merged_po = @merger.merge(@po, @pot)
|
397
|
+
assert_equal("bonjour", merged_po["hello"].msgstr)
|
398
|
+
assert_equal(pot_references, merged_po["hello"].references)
|
399
|
+
end
|
400
|
+
|
401
|
+
def test_flag
|
402
|
+
@po["hello"] = generate_entry(:msgid => "hello",
|
403
|
+
:msgstr => "bonjour",
|
404
|
+
:flag => "c-format")
|
405
|
+
|
406
|
+
@pot["hello"] = generate_entry(:msgid => "hello",
|
407
|
+
:msgstr => "",
|
408
|
+
:flag => "no-c-format")
|
409
|
+
|
410
|
+
merged_po = @merger.merge(@po, @pot)
|
411
|
+
assert_equal("bonjour", merged_po["hello"].msgstr)
|
412
|
+
assert_equal("no-c-format", merged_po["hello"].flag)
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_fuzzy_flag
|
416
|
+
@po["hello"] = generate_entry(:msgid => "hello",
|
417
|
+
:msgstr => "bonjuor",
|
418
|
+
:flag => "fuzzy")
|
419
|
+
|
420
|
+
@pot["hello"] = generate_entry(:msgid => "hello",
|
421
|
+
:msgstr => "")
|
422
|
+
|
423
|
+
merged_po = @merger.merge(@po, @pot)
|
424
|
+
assert_equal("bonjuor", merged_po["hello"].msgstr)
|
425
|
+
assert_equal("fuzzy", merged_po["hello"].flag)
|
426
|
+
end
|
427
|
+
|
428
|
+
def test_previous
|
429
|
+
@po["hello"] = generate_entry(:msgid => "hello",
|
430
|
+
:msgstr => "bonjour",
|
431
|
+
:previous => "hi")
|
432
|
+
|
433
|
+
@pot["hello"] = generate_entry(:msgid => "hello",
|
434
|
+
:msgstr => "")
|
435
|
+
|
436
|
+
merged_po = @merger.merge(@po, @pot)
|
437
|
+
assert_equal("bonjour", merged_po["hello"].msgstr)
|
438
|
+
assert_equal(nil, merged_po["hello"].previous)
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_fuzzy_header
|
442
|
+
@po[""] = generate_entry(:msgid => "",
|
443
|
+
:msgstr => "header\nentry",
|
444
|
+
:translator_comment => "header comment")
|
445
|
+
|
446
|
+
@pot[""] = generate_entry(:msgid => "",
|
447
|
+
:msgstr => "uninitialized\ncomment",
|
448
|
+
:translator_comment => "uninitialized comment",
|
449
|
+
:flag => "fuzzy")
|
450
|
+
|
451
|
+
merged_po = @merger.merge(@po, @pot)
|
452
|
+
assert_equal("header\nentry", merged_po[""].msgstr)
|
453
|
+
assert_equal("header comment", merged_po[""].translator_comment)
|
454
|
+
assert_equal(nil, merged_po[""].flag)
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_fuzzy_header_including_pot_creation_date
|
458
|
+
creation_date_mark = "POT-Creation-Date: "
|
459
|
+
po_creation_date = "#{creation_date_mark}2012-11-15 08:15+0900"
|
460
|
+
pot_creation_date = "#{creation_date_mark}2012-11-20 14:15+0900"
|
461
|
+
@po[""] = generate_entry(:msgid => "",
|
462
|
+
:msgstr => po_creation_date,
|
463
|
+
:translator_comment => "header comment")
|
464
|
+
|
465
|
+
@pot[""] = generate_entry(:msgid => "",
|
466
|
+
:msgstr => pot_creation_date,
|
467
|
+
:translator_comment => "header comment",
|
468
|
+
:flag => "fuzzy")
|
469
|
+
|
470
|
+
merged_po = @merger.merge(@po, @pot)
|
471
|
+
assert_equal(pot_creation_date, merged_po[""].msgstr)
|
472
|
+
end
|
473
|
+
|
474
|
+
def test_obsolete_entry
|
475
|
+
@po["hello"] = "bonjour"
|
476
|
+
@pot["hi"] = "salut"
|
477
|
+
merged_po = @merger.merge(@po, @pot)
|
478
|
+
|
479
|
+
assert_equal("salut", merged_po["hi"].msgstr)
|
480
|
+
assert_false(merged_po.has_key?("hello"))
|
481
|
+
|
482
|
+
obsolete_comment = <<-EOC
|
483
|
+
msgid "hello"
|
484
|
+
msgstr "bonjour"
|
485
|
+
EOC
|
486
|
+
assert_equal(obsolete_comment, merged_po[:last].comment)
|
487
|
+
end
|
488
|
+
|
489
|
+
private
|
490
|
+
def generate_entry(options)
|
491
|
+
msgctxt = options[:msgctxt]
|
492
|
+
msgid_plural = options[:msgid_plural]
|
493
|
+
type = @po_data.send(:detect_entry_type, msgctxt, msgid_plural)
|
494
|
+
|
495
|
+
entry = GetText::POEntry.new(type)
|
496
|
+
entry.translator_comment = options[:translator_comment]
|
497
|
+
entry.extracted_comment = options[:extracted_comment]
|
498
|
+
entry.references = options[:references] || []
|
499
|
+
entry.flag = options[:flag]
|
500
|
+
entry.previous = options[:previous]
|
501
|
+
entry.msgctxt = msgctxt
|
502
|
+
entry.msgid = options[:msgid]
|
503
|
+
entry.msgid_plural = msgid_plural
|
504
|
+
entry.msgstr = options[:msgstr]
|
505
|
+
entry
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
132
509
|
class TestMerge < self
|
133
510
|
include GetTextTestUtils
|
134
511
|
|