gettext 2.3.3 → 2.3.4

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.
Files changed (79) hide show
  1. data/doc/text/news.md +37 -0
  2. data/gettext.gemspec +1 -0
  3. data/lib/gettext/runtime/mo.rb +382 -0
  4. data/lib/gettext/runtime/mofile.rb +24 -366
  5. data/lib/gettext/runtime/textdomain.rb +17 -17
  6. data/lib/gettext/tools.rb +1 -1
  7. data/lib/gettext/tools/msgfmt.rb +2 -2
  8. data/lib/gettext/tools/msginit.rb +16 -15
  9. data/lib/gettext/tools/msgmerge.rb +258 -255
  10. data/lib/gettext/tools/parser/ruby.rb +24 -24
  11. data/lib/gettext/tools/po.rb +256 -0
  12. data/lib/gettext/tools/po_entry.rb +355 -0
  13. data/lib/gettext/tools/poparser.rb +118 -16
  14. data/lib/gettext/tools/xgettext.rb +56 -58
  15. data/lib/gettext/version.rb +1 -1
  16. data/samples/po/hello.pot +3 -3
  17. data/samples/po/hello2.pot +3 -3
  18. data/samples/po/hello_glade2.pot +3 -3
  19. data/samples/po/hello_gtk2.pot +3 -3
  20. data/samples/po/hello_noop.pot +3 -3
  21. data/samples/po/hello_plural.pot +3 -3
  22. data/samples/po/hello_tk.pot +3 -3
  23. data/src/poparser.ry +111 -9
  24. data/test/parser/test_ruby.rb +17 -13
  25. data/test/po/_.pot +3 -3
  26. data/test/po/backslash.pot +3 -3
  27. data/test/po/non_ascii.pot +3 -3
  28. data/test/po/np_.pot +5 -4
  29. data/test/po/ns_.pot +3 -3
  30. data/test/po/p_.pot +3 -3
  31. data/test/po/s_.pot +3 -3
  32. data/test/po/untranslated.pot +3 -3
  33. data/test/{test_mofile.rb → test_mo.rb} +3 -3
  34. data/test/test_parser.rb +13 -12
  35. data/test/test_po_entry.rb +329 -0
  36. data/test/test_po_parser.rb +209 -8
  37. data/test/tools/test_msginit.rb +0 -2
  38. data/test/tools/test_msgmerge.rb +427 -50
  39. data/test/tools/test_po.rb +487 -0
  40. data/test/tools/test_xgettext.rb +1 -1
  41. metadata +28 -45
  42. data/data/locale/de/LC_MESSAGES/gettext.mo +0 -0
  43. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  44. data/data/locale/el/LC_MESSAGES/gettext.mo +0 -0
  45. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  46. data/data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
  47. data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
  48. data/data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
  49. data/data/locale/uk/LC_MESSAGES/rgettext.mo +0 -0
  50. data/lib/gettext/tools/pomessage.rb +0 -232
  51. data/samples/locale/bg/LC_MESSAGES/hello_gtk.mo +0 -0
  52. data/samples/locale/bs/LC_MESSAGES/hello_gtk.mo +0 -0
  53. data/samples/locale/ca/LC_MESSAGES/hello_gtk.mo +0 -0
  54. data/samples/locale/cs/LC_MESSAGES/hello_gtk.mo +0 -0
  55. data/samples/locale/de/LC_MESSAGES/hello_gtk.mo +0 -0
  56. data/samples/locale/el/LC_MESSAGES/hello_gtk.mo +0 -0
  57. data/samples/locale/eo/LC_MESSAGES/hello_gtk.mo +0 -0
  58. data/samples/locale/es/LC_MESSAGES/hello_gtk.mo +0 -0
  59. data/samples/locale/fr/LC_MESSAGES/hello_gtk.mo +0 -0
  60. data/samples/locale/hr/LC_MESSAGES/hello_gtk.mo +0 -0
  61. data/samples/locale/hu/LC_MESSAGES/hello_gtk.mo +0 -0
  62. data/samples/locale/it/LC_MESSAGES/hello_gtk.mo +0 -0
  63. data/samples/locale/ja/LC_MESSAGES/hello_gtk.mo +0 -0
  64. data/samples/locale/ko/LC_MESSAGES/hello_gtk.mo +0 -0
  65. data/samples/locale/lv/LC_MESSAGES/hello_gtk.mo +0 -0
  66. data/samples/locale/nb/LC_MESSAGES/hello_gtk.mo +0 -0
  67. data/samples/locale/nl/LC_MESSAGES/hello_gtk.mo +0 -0
  68. data/samples/locale/pt_BR/LC_MESSAGES/hello_gtk.mo +0 -0
  69. data/samples/locale/ru/LC_MESSAGES/hello_gtk.mo +0 -0
  70. data/samples/locale/sr/LC_MESSAGES/hello_gtk.mo +0 -0
  71. data/samples/locale/sv/LC_MESSAGES/hello_gtk.mo +0 -0
  72. data/samples/locale/uk/LC_MESSAGES/hello_gtk.mo +0 -0
  73. data/samples/locale/vi/LC_MESSAGES/hello_gtk.mo +0 -0
  74. data/samples/locale/zh/LC_MESSAGES/hello_gtk.mo +0 -0
  75. data/samples/locale/zh_TW/LC_MESSAGES/hello_gtk.mo +0 -0
  76. data/test/po/ascii.pot +0 -23
  77. data/test/po/no_exist_msgid.pot +0 -20
  78. data/test/po/not_existed_msgid.pot +0 -20
  79. data/test/test_po_message.rb +0 -118
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'gettext/runtime/mofile'
3
+ require 'gettext/runtime/mo'
4
4
 
5
- class TestMoFile < Test::Unit::TestCase
5
+ class TestMo < Test::Unit::TestCase
6
6
  def test_not_exist_msgid
7
7
  mo = load_mo("_.mo")
8
8
  assert_equal(nil, mo["notexistent"])
@@ -26,6 +26,6 @@ class TestMoFile < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  def load_mo(file)
29
- GetText::MoFile.open("locale/ja/LC_MESSAGES/#{file}", "UTF-8")
29
+ GetText::MO.open("locale/ja/LC_MESSAGES/#{file}", "UTF-8")
30
30
  end
31
31
  end
data/test/test_parser.rb CHANGED
@@ -52,8 +52,8 @@ class TestGetTextParser < Test::Unit::TestCase
52
52
  assert_target "\\taaa", ['fixtures/_.rb:96']
53
53
  assert_target "Here document1\\nHere document2\\n", ['fixtures/_.rb:100']
54
54
  assert_target "Francois Pinard", ['fixtures/_.rb:119'] do |t|
55
- assert_match(/proper name/, t.comment)
56
- assert_match(/Pronunciation/, t.comment)
55
+ assert_match(/proper name/, t.extracted_comment)
56
+ assert_match(/Pronunciation/, t.extracted_comment)
57
57
  end
58
58
 
59
59
  assert_target("No TRANSLATORS comment", ["fixtures/_.rb:122"]) do |t|
@@ -101,7 +101,8 @@ class TestGetTextParser < Test::Unit::TestCase
101
101
  assert_plural_target "mmmmmm", "mmm2mmm2", ['fixtures/n_.rb:80']
102
102
  assert_plural_target "nnn", "nnn2", ['fixtures/n_.rb:81']
103
103
  assert_plural_target "comment", "comments", ['fixtures/n_.rb:97'] do |t|
104
- assert_equal "please provide translations for all\n the plural forms!", t.comment
104
+ assert_equal "please provide translations for all\n the plural forms!",
105
+ t.extracted_comment
105
106
  end
106
107
  end
107
108
 
@@ -112,7 +113,7 @@ class TestGetTextParser < Test::Unit::TestCase
112
113
  assert_target_in_context "AAA", "CCC", ["fixtures/p_.rb:41"]
113
114
  assert_target_in_context "CCC", "BBB", ["fixtures/p_.rb:45"]
114
115
  assert_target_in_context "program", "name", ['fixtures/p_.rb:55'] do |t|
115
- assert_equal "please translate 'name' in the context of 'program'.\n Hint: the translation should NOT contain the translation of 'program'.", t.comment
116
+ assert_equal "please translate 'name' in the context of 'program'.\n Hint: the translation should NOT contain the translation of 'program'.", t.extracted_comment
116
117
  end
117
118
  end
118
119
 
@@ -184,11 +185,11 @@ class TestGetTextParser < Test::Unit::TestCase
184
185
 
185
186
  private
186
187
 
187
- def assert_target(msgid, sources = nil)
188
+ def assert_target(msgid, references = nil)
188
189
  t = @ary.detect {|elem| elem.msgid == msgid}
189
190
  if t
190
- if sources
191
- assert_equal sources.sort, t.sources.sort, 'Translation target sources do not match.'
191
+ if references
192
+ assert_equal references.sort, t.references.sort, 'Translation target references do not match.'
192
193
  end
193
194
  yield t if block_given?
194
195
  else
@@ -196,18 +197,18 @@ class TestGetTextParser < Test::Unit::TestCase
196
197
  end
197
198
  end
198
199
 
199
- def assert_plural_target(msgid, plural, sources = nil)
200
- assert_target msgid, sources do |t|
200
+ def assert_plural_target(msgid, plural, references = nil)
201
+ assert_target msgid, references do |t|
201
202
  assert_equal plural, t.msgid_plural, 'Expected plural form'
202
203
  yield t if block_given?
203
204
  end
204
205
  end
205
206
 
206
- def assert_target_in_context(msgctxt, msgid, sources = nil)
207
+ def assert_target_in_context(msgctxt, msgid, references = nil)
207
208
  t = @ary.detect {|elem| elem.msgid == msgid && elem.msgctxt == msgctxt}
208
209
  if t
209
- if sources
210
- assert_equal sources.sort, t.sources.sort, 'Translation target sources do not match.'
210
+ if references
211
+ assert_equal references.sort, t.references.sort, 'Translation target references do not match.'
211
212
  end
212
213
  yield t if block_given?
213
214
  else
@@ -0,0 +1,329 @@
1
+ # encoding: utf-8
2
+
3
+ require 'gettext/tools/parser/ruby'
4
+
5
+ # Most functionality of PoMessage is thoroughly tested together
6
+ # with the parser and po file generator. Here only tests for some special
7
+ # functionality.
8
+ class TestPOEntry < Test::Unit::TestCase
9
+
10
+ def test_context_match
11
+ tt1 = GetText::POEntry.new(:msgctxt)
12
+ tt1.msgid = 'hello'
13
+ tt1.msgctxt = 'world'
14
+ tt2 = GetText::POEntry.new(:normal)
15
+ tt2.msgid = 'hello'
16
+ assert_raise GetText::ParseError do
17
+ tt1.merge tt2
18
+ end
19
+ end
20
+
21
+ def test_attribute_accumulation
22
+ tt = GetText::POEntry.new(:plural)
23
+ tt.set_current_attribute 'long'
24
+ tt.set_current_attribute ' tail'
25
+ tt.advance_to_next_attribute
26
+ tt.set_current_attribute 'long tails'
27
+ assert_equal 'long tail', tt.msgid
28
+ assert_equal 'long tails', tt.msgid_plural
29
+ end
30
+
31
+ class TestSetType < self
32
+ def test_varid_type
33
+ entry = GetText::POEntry.new(:normal)
34
+ type = :plural
35
+ entry.type = type
36
+ assert_equal(type, entry.type)
37
+ end
38
+
39
+ def test_invalid_type
40
+ entry = GetText::POEntry.new(:normal)
41
+ type = :invalid
42
+ assert_raise(GetText::POEntry::InvalidTypeError) do
43
+ entry.type = type
44
+ end
45
+ assert_equal(:normal, entry.type)
46
+ end
47
+
48
+ def test_invalid_type_for_initializing
49
+ assert_raise(GetText::POEntry::InvalidTypeError) do
50
+ GetText::POEntry.new(:invalid)
51
+ end
52
+ end
53
+ end
54
+
55
+ class TestToS < self
56
+ def test_normal
57
+ po = GetText::POEntry.new(:normal)
58
+ po.msgid = 'hello'
59
+ po.references = ["file1:1", "file2:10"]
60
+ assert_equal "#: file1:1 file2:10\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_s
61
+
62
+ po.msgctxt = 'context'
63
+ po.msgid_plural = 'hello2'
64
+ # Ignore these properties.
65
+ assert_equal "#: file1:1 file2:10\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_s
66
+ end
67
+
68
+ def test_plural
69
+ po = GetText::POEntry.new(:plural)
70
+ po.msgid = 'hello'
71
+ po.msgid_plural = 'hello2'
72
+ po.references = ["file1:1", "file2:10"]
73
+ assert_equal "#: file1:1 file2:10\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_s
74
+
75
+ po.msgctxt = 'context'
76
+ # Ignore this property
77
+ assert_equal "#: file1:1 file2:10\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_s
78
+ end
79
+
80
+ def test_msgctxt
81
+ po = GetText::POEntry.new(:msgctxt)
82
+ po.msgctxt = 'context'
83
+ po.msgid = 'hello'
84
+ po.references = ["file1:1", "file2:10"]
85
+ assert_equal "#: file1:1 file2:10\nmsgctxt \"context\"\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_s
86
+ end
87
+
88
+ def test_msgctxt_plural
89
+ po = GetText::POEntry.new(:msgctxt_plural)
90
+ po.msgctxt = 'context'
91
+ po.msgid = 'hello'
92
+ po.msgid_plural = 'hello2'
93
+ po.references = ["file1:1", "file2:10"]
94
+ assert_equal "#: file1:1 file2:10\nmsgctxt \"context\"\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_s
95
+ end
96
+
97
+ def test_exception
98
+ po = GetText::POEntry.new(:normal)
99
+ po.references = ["file1:1", "file2:10"]
100
+ assert_raise(GetText::POEntry::NoMsgidError) {po.to_s}
101
+
102
+ po.references = nil
103
+ assert_raise(GetText::POEntry::NoMsgidError) {po.to_s}
104
+
105
+ po = GetText::POEntry.new(:plural)
106
+ po.msgid = 'hello'
107
+ po.references = ["file1:1", "file2:10"]
108
+ assert_raise(GetText::POEntry::NoMsgidPluralError) {po.to_s}
109
+
110
+ po = GetText::POEntry.new(:msgctxt)
111
+ po.msgid = 'hello'
112
+ po.references = ["file1:1", "file2:10"]
113
+ assert_raise(GetText::POEntry::NoMsgctxtError) {po.to_s}
114
+
115
+ po = GetText::POEntry.new(:msgctxt_plural)
116
+ po.msgctxt = 'context'
117
+ po.msgid = 'hello'
118
+ po.references = ["file1:1", "file2:10"]
119
+ assert_raise(GetText::POEntry::NoMsgidPluralError) {po.to_s}
120
+ end
121
+
122
+ def test_header
123
+ po = GetText::POEntry.new(:normal)
124
+ po.msgid = ""
125
+ po.msgstr = "This is the header entry."
126
+ po.references = nil
127
+ expected_header = <<EOH
128
+ msgid ""
129
+ msgstr "This is the header entry."
130
+ EOH
131
+ assert_equal(expected_header, po.to_s)
132
+ end
133
+
134
+ def test_msgstr
135
+ po = GetText::POEntry.new(:normal)
136
+ po.msgid = "hello"
137
+ po.msgstr = "Bonjour"
138
+ po.references = ["file1:1", "file2:10"]
139
+ expected_entry = <<-EOE
140
+ #: file1:1 file2:10
141
+ msgid "hello"
142
+ msgstr "Bonjour"
143
+ EOE
144
+ assert_equal(expected_entry, po.to_s)
145
+ end
146
+
147
+ def test_escaped_msgstr
148
+ po = GetText::POEntry.new(:normal)
149
+ po.msgid = "He said \"hello.\""
150
+ po.msgstr = "Il a dit \"bonjour.\""
151
+ po.references = ["file1:1", "file2:10"]
152
+ expected_entry = <<-EOE
153
+ #: file1:1 file2:10
154
+ msgid "He said \\\"hello.\\\""
155
+ msgstr "Il a dit \\\"bonjour.\\\""
156
+ EOE
157
+ assert_equal(expected_entry, po.to_s)
158
+ end
159
+
160
+ def test_escaped_msgstr_with_msgid_plural
161
+ po = GetText::POEntry.new(:plural)
162
+ po.msgid = "He said \"hello.\""
163
+ po.msgid_plural = "They said \"hello.\""
164
+ po.msgstr = "Il a dit \"bonjour.\"\000Ils ont dit \"bonjour.\""
165
+ po.references = ["file1:1", "file2:10"]
166
+ expected_entry = <<-EOE
167
+ #: file1:1 file2:10
168
+ msgid "He said \\\"hello.\\\""
169
+ msgid_plural "They said \\\"hello.\\\""
170
+ msgstr[0] "Il a dit \\\"bonjour.\\\""
171
+ msgstr[1] "Ils ont dit \\\"bonjour.\\\""
172
+ EOE
173
+ assert_equal(expected_entry, po.to_s)
174
+ end
175
+
176
+ def test_msgstr_with_msgid_plural
177
+ po = GetText::POEntry.new(:plural)
178
+ po.msgid = "he"
179
+ po.msgid_plural = "them"
180
+ po.msgstr = "il\000ils"
181
+ po.references = ["file1:1", "file2:10"]
182
+ expected_entry = <<-EOE
183
+ #: file1:1 file2:10
184
+ msgid "he"
185
+ msgid_plural "them"
186
+ msgstr[0] "il"
187
+ msgstr[1] "ils"
188
+ EOE
189
+ assert_equal(expected_entry, po.to_s)
190
+ end
191
+
192
+ def test_obsolete_comment
193
+ po = GetText::POEntry.new(:normal)
194
+ po.msgid = :last
195
+ obsolete_comment =<<EOC
196
+ # test.rb:10
197
+ msgid \"hello\"
198
+ msgstr \"Salut\"
199
+ EOC
200
+ po.comment = obsolete_comment
201
+
202
+ expected_obsolete_comment = obsolete_comment.gsub(/^/, "#~ ")
203
+ assert_equal(expected_obsolete_comment, po.to_s)
204
+ end
205
+
206
+ def test_translator_comment
207
+ po = GetText::POEntry.new(:normal)
208
+ po.msgid = "msgid"
209
+ po.msgstr = "msgstr"
210
+ po.translator_comment = "It's the translator comment."
211
+
212
+ expected_po =<<EOP
213
+ # It's the translator comment.
214
+ msgid \"msgid\"
215
+ msgstr \"msgstr\"
216
+ EOP
217
+ assert_equal(expected_po, po.to_s)
218
+ end
219
+
220
+ def test_extracted_comment
221
+ po = GetText::POEntry.new(:normal)
222
+ po.msgid = "msgid"
223
+ po.msgstr = "msgstr"
224
+ po.extracted_comment = "It's the extracted comment."
225
+
226
+ expected_po =<<EOP
227
+ #. It's the extracted comment.
228
+ msgid \"msgid\"
229
+ msgstr \"msgstr\"
230
+ EOP
231
+ assert_equal(expected_po, po.to_s)
232
+ end
233
+
234
+ def test_flag
235
+ po = GetText::POEntry.new(:normal)
236
+ po.msgid = "msgid"
237
+ po.msgstr = "msgstr"
238
+ po.flag = "It's the flag."
239
+
240
+ expected_po =<<EOP
241
+ #, It's the flag.
242
+ msgid \"msgid\"
243
+ msgstr \"msgstr\"
244
+ EOP
245
+ assert_equal(expected_po, po.to_s)
246
+ end
247
+
248
+ def test_previous
249
+ po = GetText::POEntry.new(:normal)
250
+ po.msgid = "msgid"
251
+ po.msgstr = "msgstr"
252
+ po.previous = <<EOC
253
+ msgctxt previous_msgctxt
254
+ msgid previous_msgid
255
+ msgid_plural previous_msgid_plural
256
+ EOC
257
+
258
+ expected_po =<<EOP
259
+ #| msgctxt previous_msgctxt
260
+ #| msgid previous_msgid
261
+ #| msgid_plural previous_msgid_plural
262
+ msgid \"msgid\"
263
+ msgstr \"msgstr\"
264
+ EOP
265
+ assert_equal(expected_po, po.to_s)
266
+ end
267
+ end
268
+
269
+ class TestEscape < self
270
+ def setup
271
+ @entry = GetText::POEntry.new(:normal)
272
+ end
273
+
274
+ def test_backslash
275
+ @entry.msgid = "You should escape '\\' as '\\\\'."
276
+ assert_equal("You should escape '\\\\' as '\\\\\\\\'.",
277
+ @entry.escaped(:msgid))
278
+ end
279
+
280
+ def test_new_line
281
+ @entry.msgid = "First\nSecond\nThird"
282
+ assert_equal("First\\nSecond\\nThird",
283
+ @entry.escaped(:msgid))
284
+ end
285
+ end
286
+
287
+ class TestFormatMessage < self
288
+ def setup
289
+ @entry = GetText::POEntry.new(:normal)
290
+ end
291
+
292
+ def test_including_newline
293
+ message = "line 1\n" +
294
+ "line 2"
295
+ expected_message = "\"\"\n" +
296
+ "\"line 1\\n\"\n" +
297
+ "\"line 2\"\n"
298
+ assert_equal(expected_message, @entry.format_message(message))
299
+ end
300
+
301
+ def test_not_existed_newline
302
+ message = "line 1"
303
+ expected_message = "\"line 1\"\n"
304
+ assert_equal(expected_message, @entry.format_message(message))
305
+ end
306
+ end
307
+
308
+ class TestFormatComment < self
309
+ def setup
310
+ @entry = GetText::POEntry.new(:normal)
311
+ end
312
+
313
+ def test_one_line_comment
314
+ comment = "comment"
315
+ mark = "#"
316
+ @entry.msgid = "msgid"
317
+ expected_comment = "# #{comment}\n"
318
+ assert_equal(expected_comment, @entry.format_comment(mark, comment))
319
+ end
320
+
321
+ def test_multiline_comment
322
+ comment = "comment1\ncomment2"
323
+ mark = "#"
324
+ @entry.msgid = ""
325
+ expected_comment = "#{comment.gsub(/^/, "#{mark} ")}\n"
326
+ assert_equal(expected_comment, @entry.format_comment(mark, comment))
327
+ end
328
+ end
329
+ end
@@ -20,13 +20,13 @@
20
20
 
21
21
  require "gettext/tools/poparser"
22
22
 
23
- class TestPoParser < Test::Unit::TestCase
23
+ class TestPOParser < Test::Unit::TestCase
24
24
  def test_msgstr_not_existing
25
25
  po_file = create_po_file(<<-EOP)
26
26
  msgid "Hello"
27
27
  msgstr ""
28
28
  EOP
29
- messages = parse_po_file(po_file)
29
+ messages = parse_po_file(po_file, MO.new)
30
30
 
31
31
  assert_equal(nil, messages["Hello"])
32
32
  end
@@ -38,12 +38,213 @@ msgid_plural "They"
38
38
  msgstr[0] ""
39
39
  msgstr[1] ""
40
40
  EOP
41
- messages = parse_po_file(po_file)
41
+ messages = parse_po_file(po_file, MO.new)
42
42
 
43
43
  assert_true(messages.has_key?("He\000They"))
44
44
  assert_equal(nil, messages["He\000They"])
45
45
  end
46
46
 
47
+ class TestPoData < self
48
+ def test_comment
49
+ po_file = create_po_file(<<-EOP)
50
+ #: file.rb:10
51
+ msgid "hello"
52
+ msgstr "bonjour"
53
+ EOP
54
+ entries = parse_po_file(po_file)
55
+ assert_true(entries.msgids.include?("hello"))
56
+ assert_equal("bonjour", entries["hello"])
57
+ assert_equal("#: file.rb:10", entries.comment("hello"))
58
+ end
59
+
60
+ def test_msgctxt
61
+ po_file = create_po_file(<<-EOP)
62
+ msgctxt "pronoun"
63
+ msgid "he"
64
+ msgstr "il"
65
+ EOP
66
+ entries = parse_po_file(po_file)
67
+ assert_true(entries.msgids.include?("pronoun\004he"))
68
+ assert_equal("il", entries["pronoun\004he"])
69
+ end
70
+
71
+ def test_msgid_plural
72
+ po_file = create_po_file(<<-EOP)
73
+ msgid "he"
74
+ msgid_plural "they"
75
+ msgstr[0] "il"
76
+ msgstr[1] "ils"
77
+ EOP
78
+ entries = parse_po_file(po_file)
79
+
80
+ assert_true(entries.msgids.include?("he\000they"))
81
+ assert_equal("il\000ils", entries["he\000they"])
82
+ end
83
+
84
+ def test_msgctxt_and_msgid_plural
85
+ po_file = create_po_file(<<-EOP)
86
+ msgctxt "pronoun"
87
+ msgid "he"
88
+ msgid_plural "them"
89
+ msgstr[0] "il"
90
+ msgstr[1] "ils"
91
+ EOP
92
+ entries = parse_po_file(po_file)
93
+ assert_true(entries.msgids.include?("pronoun\004he\000them"))
94
+ assert_equal("il\000ils", entries["pronoun\004he\000them"])
95
+ end
96
+
97
+ private
98
+ def parse_po_file(po_file)
99
+ super(po_file, GetText::Tools::MsgMerge::PoData.new)
100
+ end
101
+ end
102
+
103
+ class TestPO < self
104
+ def test_msgstr
105
+ po_file = create_po_file(<<-EOP)
106
+ # This is the comment.
107
+ #: file.rb:10
108
+ msgid "hello"
109
+ msgstr "bonjour"
110
+ EOP
111
+ entries = parse_po_file(po_file)
112
+ assert_true(entries.has_key?(nil, "hello"))
113
+ assert_equal("bonjour", entries["hello"].msgstr)
114
+ end
115
+
116
+ def test_references
117
+ po_file = create_po_file(<<-EOP)
118
+ # This is the comment.
119
+ #: file.rb:10
120
+ msgid "hello"
121
+ msgstr "bonjour"
122
+ EOP
123
+ entries = parse_po_file(po_file)
124
+ assert_true(entries.has_key?(nil, "hello"))
125
+ assert_equal(["file.rb:10"], entries["hello"].references)
126
+ end
127
+
128
+ def test_translator_comment
129
+ po_file = create_po_file(<<-EOP)
130
+ # This is the translator comment.
131
+ msgid "hello"
132
+ msgstr "bonjour"
133
+ EOP
134
+ entries = parse_po_file(po_file)
135
+ assert_true(entries.has_key?(nil, "hello"))
136
+ entry = entries["hello"]
137
+ assert_equal("This is the translator comment.", entry.translator_comment)
138
+ end
139
+
140
+ def test_extracted_comment
141
+ po_file = create_po_file(<<-EOP)
142
+ #. This is the extracted comment.
143
+ msgid "hello"
144
+ msgstr "bonjour"
145
+ EOP
146
+ entries = parse_po_file(po_file)
147
+ assert_true(entries.has_key?(nil, "hello"))
148
+ entry = entries["hello"]
149
+ assert_equal("This is the extracted comment.", entry.extracted_comment)
150
+ end
151
+
152
+ def test_flag
153
+ po_file = create_po_file(<<-EOP)
154
+ #, flag
155
+ msgid "hello"
156
+ msgstr "bonjour"
157
+ EOP
158
+ entries = parse_po_file(po_file)
159
+ assert_true(entries.has_key?(nil, "hello"))
160
+ assert_equal("flag", entries["hello"].flag)
161
+ end
162
+
163
+ def test_previous
164
+ po_file = create_po_file(<<-EOP)
165
+ #| msgctxt Normal
166
+ #| msgid He
167
+ #| msgid_plural Them
168
+ msgid "he"
169
+ msgid_plural "them"
170
+ msgstr[0] "il"
171
+ msgstr[1] "ils"
172
+ EOP
173
+ expected_previous = "msgctxt Normal\n" +
174
+ "msgid He\n" +
175
+ "msgid_plural Them"
176
+ entries = parse_po_file(po_file)
177
+ assert_true(entries.has_key?(nil, "he"))
178
+ assert_equal(expected_previous, entries["he"].previous)
179
+ end
180
+
181
+ def test_msgid_plural
182
+ po_file = create_po_file(<<-EOP)
183
+ # This is the comment.
184
+ #: file.rb:10
185
+ msgid "he"
186
+ msgid_plural "them"
187
+ msgstr[0] "il"
188
+ msgstr[1] "ils"
189
+ EOP
190
+ entries = parse_po_file(po_file)
191
+ assert_true(entries.has_key?(nil, "he"))
192
+ assert_equal("them", entries["he"].msgid_plural)
193
+ assert_equal("il\000ils", entries["he"].msgstr)
194
+ end
195
+
196
+ def test_msgctxt
197
+ po_file = create_po_file(<<-EOP)
198
+ # This is the comment.
199
+ #: file.rb:10
200
+ msgctxt "pronoun"
201
+ msgid "he"
202
+ msgstr "il"
203
+ EOP
204
+ entries = parse_po_file(po_file)
205
+ assert_true(entries.has_key?("pronoun", "he"))
206
+ assert_equal("pronoun", entries["pronoun", "he"].msgctxt)
207
+ end
208
+
209
+ def test_msgctxt_with_msgid_plural
210
+ po_file = create_po_file(<<-EOP)
211
+ # This is the comment.
212
+ #: file.rb:10
213
+ msgctxt "pronoun"
214
+ msgid "he"
215
+ msgid_plural "them"
216
+ msgstr[0] "il"
217
+ msgstr[1] "ils"
218
+ EOP
219
+ entries = parse_po_file(po_file)
220
+ assert_true(entries.has_key?("pronoun", "he"))
221
+ assert_equal("pronoun", entries["pronoun", "he"].msgctxt)
222
+ assert_equal("them", entries["pronoun", "he"].msgid_plural)
223
+ assert_equal("il\000ils", entries["pronoun", "he"].msgstr)
224
+ end
225
+
226
+ def test_fuzzy
227
+ po_file = create_po_file(<<-EOP)
228
+ #, fuzzy
229
+ #: file.rb:10
230
+ msgid "hello"
231
+ msgstr "bonjour"
232
+ EOP
233
+ entries = parse_po_file(po_file, :ignore_fuzzy => false)
234
+
235
+ assert_true(entries.has_key?("hello"))
236
+ assert_equal("fuzzy", entries["hello"].flag)
237
+ end
238
+
239
+ private
240
+ def parse_po_file(po_file, options={:ignore_fuzzy => true})
241
+ ignore_fuzzy = options[:ignore_fuzzy]
242
+ parser = GetText::POParser.new
243
+ parser.ignore_fuzzy = ignore_fuzzy
244
+ parser.parse_file(po_file.path, PO.new)
245
+ end
246
+ end
247
+
47
248
  private
48
249
  def create_po_file(content)
49
250
  po_file = Tempfile.new("hello.po")
@@ -52,9 +253,9 @@ EOP
52
253
  po_file
53
254
  end
54
255
 
55
- def parse_po_file(po_file)
56
- parser = GetText::PoParser.new
57
- parser.parse_file(po_file.path, MoFile.new)
256
+ def parse_po_file(po_file, parsed_entries)
257
+ parser = GetText::POParser.new
258
+ parser.parse_file(po_file.path, parsed_entries)
58
259
  end
59
260
 
60
261
  class FuzzyTest < self
@@ -115,13 +316,13 @@ EOP
115
316
 
116
317
  private
117
318
  def parse
118
- parser = GetText::PoParser.new
319
+ parser = GetText::POParser.new
119
320
  class << parser
120
321
  def _(message_id)
121
322
  message_id
122
323
  end
123
324
  end
124
- messages = MoFile.new
325
+ messages = MO.new
125
326
  yield parser
126
327
  parser.parse_file(@po_file.path, messages)
127
328
  messages