gettext 2.3.9 → 3.0.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.
Files changed (106) hide show
  1. data/.yardopts +1 -0
  2. data/README.rdoc +28 -23
  3. data/Rakefile +29 -21
  4. data/doc/text/news.md +57 -0
  5. data/gettext.gemspec +1 -1
  6. data/lib/gettext.rb +13 -29
  7. data/lib/gettext/cgi.rb +1 -1
  8. data/lib/gettext/{runtime/class_info.rb → class_info.rb} +1 -1
  9. data/lib/gettext/{runtime/locale_path.rb → locale_path.rb} +1 -2
  10. data/lib/gettext/{runtime/mo.rb → mo.rb} +18 -33
  11. data/lib/gettext/{tools/po.rb → po.rb} +1 -1
  12. data/lib/gettext/{tools/po_entry.rb → po_entry.rb} +8 -4
  13. data/lib/gettext/{tools/poparser.rb → po_parser.rb} +41 -44
  14. data/lib/gettext/{runtime/textdomain.rb → text_domain.rb} +6 -16
  15. data/lib/gettext/text_domain_group.rb +26 -0
  16. data/lib/gettext/{runtime/textdomain_manager.rb → text_domain_manager.rb} +40 -40
  17. data/lib/gettext/tools.rb +1 -182
  18. data/lib/gettext/tools/msgfmt.rb +1 -1
  19. data/lib/gettext/tools/msginit.rb +1 -1
  20. data/lib/gettext/tools/msgmerge.rb +2 -221
  21. data/lib/gettext/tools/parser/erb.rb +49 -30
  22. data/lib/gettext/tools/parser/glade.rb +44 -36
  23. data/lib/gettext/tools/parser/ruby.rb +126 -37
  24. data/lib/gettext/tools/task.rb +225 -0
  25. data/lib/gettext/tools/xgettext.rb +25 -28
  26. data/lib/gettext/version.rb +1 -1
  27. data/locale/bg/LC_MESSAGES/gettext.mo +0 -0
  28. data/locale/bs/LC_MESSAGES/gettext.mo +0 -0
  29. data/locale/ca/LC_MESSAGES/gettext.mo +0 -0
  30. data/locale/cs/LC_MESSAGES/gettext.mo +0 -0
  31. data/locale/de/LC_MESSAGES/gettext.mo +0 -0
  32. data/locale/el/LC_MESSAGES/gettext.mo +0 -0
  33. data/locale/eo/LC_MESSAGES/gettext.mo +0 -0
  34. data/locale/es/LC_MESSAGES/gettext.mo +0 -0
  35. data/locale/et/LC_MESSAGES/gettext.mo +0 -0
  36. data/locale/fr/LC_MESSAGES/gettext.mo +0 -0
  37. data/locale/hr/LC_MESSAGES/gettext.mo +0 -0
  38. data/locale/hu/LC_MESSAGES/gettext.mo +0 -0
  39. data/locale/it/LC_MESSAGES/gettext.mo +0 -0
  40. data/locale/ja/LC_MESSAGES/gettext.mo +0 -0
  41. data/locale/ko/LC_MESSAGES/gettext.mo +0 -0
  42. data/locale/lv/LC_MESSAGES/gettext.mo +0 -0
  43. data/locale/nb/LC_MESSAGES/gettext.mo +0 -0
  44. data/locale/nl/LC_MESSAGES/gettext.mo +0 -0
  45. data/locale/pt_BR/LC_MESSAGES/gettext.mo +0 -0
  46. data/locale/ru/LC_MESSAGES/gettext.mo +0 -0
  47. data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
  48. data/locale/sv/LC_MESSAGES/gettext.mo +0 -0
  49. data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
  50. data/locale/vi/LC_MESSAGES/gettext.mo +0 -0
  51. data/locale/zh/LC_MESSAGES/gettext.mo +0 -0
  52. data/locale/zh_TW/LC_MESSAGES/gettext.mo +0 -0
  53. data/po/gettext.pot +171 -97
  54. data/samples/hello.rb +3 -2
  55. data/samples/hello2.rb +2 -1
  56. data/samples/hello_gtk2.rb +4 -1
  57. data/samples/hello_gtk_builder.rb +32 -0
  58. data/samples/hello_gtk_builder.ui +46 -0
  59. data/samples/hello_noop.rb +2 -1
  60. data/samples/hello_plural.rb +2 -1
  61. data/samples/hello_tk.rb +2 -1
  62. data/src/{poparser.ry → po_parser.ry} +31 -35
  63. data/test/fixtures/N_.rb +1 -1
  64. data/test/fixtures/_/double_quote_in_double_quote.rb +32 -0
  65. data/test/fixtures/_/double_quote_in_single_quote.rb +32 -0
  66. data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +36 -0
  67. data/test/fixtures/_/middle_new_line.rb +32 -0
  68. data/test/fixtures/_/multiple_lines_literal.rb +35 -0
  69. data/test/fixtures/_/multiple_messages_in_same_line.rb +32 -0
  70. data/test/fixtures/_/multiple_same_messages.rb +36 -0
  71. data/{lib/gettext/runtime/mofile.rb → test/fixtures/_/one_new_line.rb} +12 -6
  72. data/test/fixtures/{multi_textdomain.rb → multi_text_domain.rb} +1 -1
  73. data/test/fixtures/non_ascii.rb +1 -1
  74. data/test/fixtures/simple.rb +1 -1
  75. data/test/fixtures/untranslated.rb +1 -1
  76. data/test/gettext-test-utils.rb +1 -24
  77. data/test/po/ja/_.po +63 -13
  78. data/test/po/ja/non_ascii.po +2 -3
  79. data/test/po/ja/untranslated.po +1 -1
  80. data/test/test_class_info.rb +2 -2
  81. data/test/test_gettext.rb +11 -11
  82. data/test/test_mo.rb +2 -2
  83. data/test/test_parser.rb +93 -96
  84. data/test/test_po_entry.rb +237 -146
  85. data/test/test_po_parser.rb +107 -98
  86. data/test/test_string.rb +1 -1
  87. data/test/{test_textdomain_bind.rb → test_text_domain_bind.rb} +6 -6
  88. data/test/{test_textdomain_multi.rb → test_text_domain_multi.rb} +5 -5
  89. data/test/{test_textdomain_toplevel.rb → test_text_domain_toplevel.rb} +1 -1
  90. data/test/test_thread.rb +1 -1
  91. data/test/tools/files/simple_translation.rb +1 -1
  92. data/test/{parser → tools/parser}/test_ruby.rb +110 -14
  93. data/test/tools/test_msgmerge.rb +17 -276
  94. data/test/tools/test_po.rb +1 -1
  95. data/test/tools/test_xgettext.rb +175 -144
  96. metadata +59 -33
  97. data/lib/gettext/core_ext/iconv.rb +0 -110
  98. data/lib/gettext/core_ext/string.rb +0 -91
  99. data/lib/gettext/parser/erb.rb +0 -5
  100. data/lib/gettext/parser/glade.rb +0 -5
  101. data/lib/gettext/parser/ruby.rb +0 -172
  102. data/lib/gettext/runtime/textdomain_group.rb +0 -26
  103. data/lib/gettext/task.rb +0 -203
  104. data/lib/gettext/utils.rb +0 -39
  105. data/test/test_po_generation.rb +0 -45
  106. data/test/tools/test_tools.rb +0 -61
@@ -21,284 +21,9 @@
21
21
  require 'gettext/tools/msgmerge'
22
22
 
23
23
  class TestToolsMsgMerge < Test::Unit::TestCase
24
- class TestPoData < self
25
- def setup
26
- @po_data = GetText::Tools::MsgMerge::PoData.new
27
- end
28
-
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
111
- #{header_entry_comment}
112
- msgid \"\"
113
- msgstr \"\"
114
- #{expected_header_entry}
115
-
116
- #{comment}
117
- msgid \"#{msgid}\"
118
- msgstr \"#{msgstr}\"
119
- EOP
120
- assert_equal(expected_po, po.generate_po)
121
- end
122
-
123
- def test_obsolete_comment
124
- obsolete_comment =<<EOC
125
- # test.rb:10
126
- msgid \"Hello\"
127
- msgstr \"Salut\"
128
- EOC
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)
136
-
137
- expected_obsolete_comment = <<-EOC
138
- # test.rb:10
139
- #~ msgid "Hello"
140
- #~ msgstr "Salut"
141
- EOC
142
- expected_obsolete_comment = expected_obsolete_comment.chomp
143
-
144
- expected_po = <<EOP
145
- #{header_entry_comment}
146
- msgid \"\"
147
- msgstr \"#{header_entry}\"
148
-
149
- #{expected_obsolete_comment}
150
- EOP
151
- assert_equal(expected_po, po.generate_po)
152
- end
153
-
154
- def test_msgid_plural_and_empty_msgstr
155
- msgid = "Singular message\000Plural message"
156
-
157
- @po_data[""] = "Plural-Forms: nplurals=2; plural=n != 1;\\n"
158
- @po_data[msgid] = "\000"
159
- @po_data.set_comment(msgid, "# plural message")
160
- actual_po = @po_data.generate_po_entry(msgid)
161
- expected_po = <<'EOE'
162
- # plural message
163
- msgid "Singular message"
164
- msgid_plural "Plural message"
165
- msgstr[0] ""
166
- msgstr[1] ""
167
- EOE
168
- assert_equal(expected_po, actual_po)
169
- end
170
- end
171
-
172
- class TestGeneratePOEntry < self
173
- def test_msgid_plural
174
- msgid = "Singular message\000Plural message"
175
-
176
- @po_data[msgid] = "Singular translation\000Plural translation"
177
- @po_data.set_comment(msgid, "# plural message")
178
- actual_po = @po_data.generate_po_entry(msgid)
179
- expected_po = <<'EOE'
180
- # plural message
181
- msgid "Singular message"
182
- msgid_plural "Plural message"
183
- msgstr[0] "Singular translation"
184
- msgstr[1] "Plural translation"
185
- EOE
186
- assert_equal(expected_po, actual_po)
187
- end
188
-
189
- def test_msgctxt
190
- msg_id = "Context\004Translation"
191
- @po_data[msg_id] = "Translated"
192
- @po_data.set_comment(msg_id, "# no comment")
193
-
194
- entry = @po_data.generate_po_entry(msg_id)
195
- assert_equal(<<-'EOE', entry)
196
- # no comment
197
- msgctxt "Context"
198
- msgid "Translation"
199
- msgstr "Translated"
200
- EOE
201
- end
202
- end
203
- end
204
-
205
- class TestSplitMsgid < self
206
- def test_existed_msgctxt_and_msgid_plural
207
- msgctxt = "msgctxt"
208
- msgid = "msgid"
209
- msgid_plural = "msgid_plural"
210
-
211
- assert_equal([msgctxt, msgid, msgid_plural],
212
- split_msgid("#{msgctxt}\004#{msgid}\000#{msgid_plural}"))
213
- end
214
-
215
- def test_existed_msgctxt_only
216
- msgctxt = "msgctxt"
217
- msgid = "msgid"
218
-
219
- assert_equal([msgctxt, msgid, nil],
220
- split_msgid("#{msgctxt}\004#{msgid}"))
221
- end
222
-
223
- def test_existed_msgid_plural_only
224
- msgid = "msgid"
225
- msgid_plural = "msgid_plural"
226
-
227
- assert_equal([nil, msgid, msgid_plural],
228
- split_msgid("#{msgid}\000#{msgid_plural}"))
229
- end
230
-
231
- def test_not_existed
232
- msgid = "msgid"
233
-
234
- assert_equal([nil, msgid, nil], split_msgid(msgid))
235
- end
236
-
237
- def test_empty_msgid
238
- msgid = ""
239
-
240
- assert_equal([nil, msgid, nil], split_msgid(msgid))
241
- end
242
-
243
- def test_last_symbol_msgid
244
- msgid = :last
245
-
246
- assert_equal([nil, msgid, nil], split_msgid(msgid))
247
- end
248
-
249
- private
250
- def split_msgid(msgid)
251
- po_data = GetText::Tools::MsgMerge::PoData.new
252
- po_data.send(:split_msgid, msgid)
253
- end
254
- end
255
-
256
- class TestParseComment < self
257
- def setup
258
- @po_data = GetText::Tools::MsgMerge::PoData.new
259
- @entry = @po_data.send(:generate_entry, "test")
260
- end
261
-
262
- def test_translator_comment
263
- comment = "# translator comment"
264
- parsed_comment = parse_comment(comment).translator_comment
265
- assert_equal("translator comment\n", parsed_comment)
266
- end
267
-
268
- def test_extracted_comment
269
- comment = "#. extracted comment"
270
- parsed_comment = parse_comment(comment).extracted_comment
271
- assert_equal("extracted comment\n", parsed_comment)
272
- end
273
-
274
- def test_references
275
- comment = "#: reference.rb:10"
276
- parsed_comment = parse_comment(comment).references
277
- assert_equal(["reference.rb:10"], parsed_comment)
278
- end
279
-
280
- def test_flag
281
- comment = "#, fuzzy"
282
- parsed_comment = parse_comment(comment).flag
283
- assert_equal("fuzzy\n", parsed_comment)
284
- end
285
-
286
- def test_previous
287
- comment = "#| msgid the previous msgid"
288
- parsed_comment = parse_comment(comment).previous
289
- assert_equal("msgid the previous msgid\n", parsed_comment)
290
- end
291
-
292
- private
293
- def parse_comment(comment)
294
- @po_data.send(:parse_comment, comment, @entry)
295
- end
296
- end
297
-
298
24
  class TestMerger < self
299
25
  def setup
300
26
  @merger = GetText::Tools::MsgMerge::Merger.new
301
- @po_data = GetText::Tools::MsgMerge::PoData.new
302
27
  @po = GetText::PO.new
303
28
  @pot = GetText::PO.new
304
29
  end
@@ -521,7 +246,7 @@ EOC
521
246
  def generate_entry(options)
522
247
  msgctxt = options[:msgctxt]
523
248
  msgid_plural = options[:msgid_plural]
524
- type = @po_data.send(:detect_entry_type, msgctxt, msgid_plural)
249
+ type = detect_entry_type(msgctxt, msgid_plural)
525
250
 
526
251
  entry = GetText::POEntry.new(type)
527
252
  entry.translator_comment = options[:translator_comment]
@@ -536,6 +261,22 @@ EOC
536
261
  entry.comment = options[:comment]
537
262
  entry
538
263
  end
264
+
265
+ def detect_entry_type(msgctxt, msgid_plural)
266
+ if msgctxt.nil?
267
+ if msgid_plural.nil?
268
+ :normal
269
+ else
270
+ :plural
271
+ end
272
+ else
273
+ if msgid_plural.nil?
274
+ :msgctxt
275
+ else
276
+ :msgctxt_plural
277
+ end
278
+ end
279
+ end
539
280
  end
540
281
 
541
282
  class TestMerge < self
@@ -18,7 +18,7 @@
18
18
  # You should have received a copy of the GNU Lesser General Public License
19
19
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
- require "gettext/tools/po"
21
+ require "gettext/po"
22
22
 
23
23
  class TestPO < Test::Unit::TestCase
24
24
  def setup
@@ -43,24 +43,20 @@ class TestToolsXGetText < Test::Unit::TestCase
43
43
  FileUtils.mkdir_p(File.dirname(@rhtml_file_path))
44
44
  end
45
45
 
46
- def test_relative_reference
46
+ private
47
+ def generate(ruby_source, *command_line_options)
47
48
  File.open(@rb_file_path, "w") do |rb_file|
48
- rb_file.puts(<<-EOR)
49
- _("Hello")
50
- EOR
49
+ rb_file.puts(ruby_source)
51
50
  end
52
51
 
53
- @xgettext.run("--output", @pot_file_path, @rb_file_path)
52
+ command_line = ["--output", @pot_file_path]
53
+ command_line += command_line_options
54
+ command_line += [@rb_file_path]
55
+ @xgettext.run(*command_line)
54
56
 
55
- assert_equal(<<-EOP, File.read(@pot_file_path))
56
- #{header}
57
- #: ../lib/xgettext.rb:1
58
- msgid "Hello"
59
- msgstr ""
60
- EOP
57
+ File.read(@pot_file_path)
61
58
  end
62
59
 
63
- private
64
60
  def header(options=nil)
65
61
  options ||= {}
66
62
  package_name = options[:package_name] || "PACKAGE"
@@ -94,10 +90,35 @@ msgstr ""
94
90
  EOH
95
91
  end
96
92
 
93
+ class TestReference < self
94
+ def test_relative
95
+ pot_content = generate(<<-EOR)
96
+ _("Hello")
97
+ EOR
98
+ assert_equal(<<-EOP, pot_content)
99
+ #{header}
100
+ #: ../lib/xgettext.rb:1
101
+ msgid "Hello"
102
+ msgstr ""
103
+ EOP
104
+ end
105
+
106
+ def test_same_message
107
+ pot_content = generate(<<-EOR)
108
+ _("Hello")
109
+ _("Hello")
110
+ EOR
111
+ assert_equal(<<-EOP, pot_content)
112
+ #{header}
113
+ #: ../lib/xgettext.rb:1 ../lib/xgettext.rb:2
114
+ msgid "Hello"
115
+ msgstr ""
116
+ EOP
117
+ end
118
+ end
119
+
97
120
  class TestEncoding < self
98
121
  def test_different_encoding_from_current_locale
99
- need_encoding
100
-
101
122
  rhtml = <<-EOR
102
123
  <%#-*- coding: sjis -*-%>
103
124
  <html>
@@ -110,36 +131,34 @@ EOH
110
131
  </html>
111
132
  EOR
112
133
  File.open(@rhtml_file_path, "w") do |rhtml_file|
113
- rhtml_file.puts(encode(rhtml, "sjis"))
134
+ rhtml_file.puts(rhtml.encode("sjis"))
114
135
  end
115
136
 
116
137
  @xgettext.run("--output", @pot_file_path, @rhtml_file_path)
117
138
 
118
139
  encoding = "UTF-8"
119
140
  pot_content = File.read(@pot_file_path)
120
- set_encoding(pot_content, encoding)
141
+ pot_content.force_encoding(encoding)
121
142
  expected_content = <<-EOP
122
143
  #{header}
123
144
  #: ../templates/xgettext.rhtml:7
124
145
  msgid "わたし"
125
146
  msgstr ""
126
147
  EOP
127
- expected_content = encode(expected_content, encoding)
148
+ expected_content = expected_content.encode(encoding)
128
149
  assert_equal(expected_content, pot_content)
129
150
  end
130
151
 
131
152
  def test_multiple_encodings
132
- need_encoding
133
-
134
153
  File.open(@rb_file_path, "w") do |rb_file|
135
- rb_file.puts(encode(<<-EOR, "euc-jp"))
154
+ rb_file.puts(<<-EOR.encode("euc-jp"))
136
155
  # -*- coding: euc-jp -*-
137
156
  _("こんにちは")
138
157
  EOR
139
158
  end
140
159
 
141
160
  File.open(@rhtml_file_path, "w") do |rhtml_file|
142
- rhtml_file.puts(encode(<<-EOR, "cp932"))
161
+ rhtml_file.puts(<<-EOR.encode("cp932"))
143
162
  <%# -*- coding: cp932 -*-%>
144
163
  <h1><%= _("わたし") %></h1>
145
164
  EOR
@@ -149,7 +168,7 @@ EOR
149
168
 
150
169
  encoding = "UTF-8"
151
170
  pot_content = File.read(@pot_file_path)
152
- set_encoding(pot_content, encoding)
171
+ pot_content.force_encoding(encoding)
153
172
  expected_content = <<-EOP
154
173
  #{header}
155
174
  #: ../lib/xgettext.rb:2
@@ -160,128 +179,180 @@ msgstr ""
160
179
  msgid "わたし"
161
180
  msgstr ""
162
181
  EOP
163
- expected_content = encode(expected_content, encoding)
182
+ expected_content = expected_content.encode(encoding)
164
183
  assert_equal(expected_content, pot_content)
165
184
  end
166
185
  end
167
186
 
168
187
  class TestTranslatorComment < self
169
188
  def test_n_
170
- rb = <<-RB
189
+ pot_content = generate(<<-RB, "--add-comments=TRANSLATORS:")
171
190
  n_members = 1
172
191
  # TRANSLATORS: Use this message as test
173
192
  n_("I will go!",
174
193
  "We will go!",
175
194
  n_members)
176
-
177
- _("No comment")
178
195
  RB
179
- File.open(@rb_file_path, "w") do |rb_file|
180
- rb_file.puts(rb)
181
- end
182
-
183
- @xgettext.run("--output", @pot_file_path, @rb_file_path)
184
-
185
- encoding = "UTF-8"
186
- pot_content = File.read(@pot_file_path)
187
- set_encoding(pot_content, encoding)
188
196
  expected_content = <<-POT
189
197
  #{header}
190
- #. Use this message as test
198
+ #. TRANSLATORS: Use this message as test
191
199
  #: ../lib/xgettext.rb:3
192
200
  msgid "I will go!"
193
201
  msgid_plural "We will go!"
194
202
  msgstr[0] ""
195
203
  msgstr[1] ""
196
-
197
- #: ../lib/xgettext.rb:7
198
- msgid "No comment"
199
- msgstr ""
200
204
  POT
201
- expected_content = encode(expected_content, encoding)
202
205
  assert_equal(expected_content, pot_content)
203
206
  end
207
+
208
+ def test_no_add_comments
209
+ pot_content = generate(<<-RUBY)
210
+ # TRNALSTORS: There is no translator's tag
211
+ _("Message")
212
+ RUBY
213
+
214
+ assert_equal(<<-POT, pot_content)
215
+ #{header}
216
+ #: ../lib/xgettext.rb:2
217
+ msgid "Message"
218
+ msgstr ""
219
+ POT
220
+ end
221
+
222
+ def test_add_comments_without_tag
223
+ pot_content = generate(<<-RUBY, "--add-comments")
224
+ # There is no translator's tag but all
225
+ # comments are included.
226
+ _("Message")
227
+ RUBY
228
+
229
+ assert_equal(<<-POT, pot_content)
230
+ #{header}
231
+ #. There is no translator's tag but all
232
+ #. comments are included.
233
+ #: ../lib/xgettext.rb:3
234
+ msgid "Message"
235
+ msgstr ""
236
+ POT
237
+ end
238
+
239
+ def test_not_started_with_tag
240
+ pot_content = generate(<<-RUBY, "--add-comments=TRANSLATORS:")
241
+ # This comment isn't started with "TRANSLATORS:" tag
242
+ _("Message")
243
+ RUBY
244
+
245
+ assert_equal(<<-POT, pot_content)
246
+ #{header}
247
+ #: ../lib/xgettext.rb:2
248
+ msgid "Message"
249
+ msgstr ""
250
+ POT
251
+ end
252
+
253
+ def test_not_first_line_is_started_with_tag
254
+ pot_content = generate(<<-RUBY, "--add-comments=TRANSLATORS:")
255
+ # The first line.
256
+ # TRANSLATORS: The second line.
257
+ # The third line.
258
+ _("Message")
259
+ RUBY
260
+
261
+ assert_equal(<<-POT, pot_content)
262
+ #{header}
263
+ #. TRANSLATORS: The second line.
264
+ #. The third line.
265
+ #: ../lib/xgettext.rb:4
266
+ msgid "Message"
267
+ msgstr ""
268
+ POT
269
+ end
270
+
271
+ def test_indented
272
+ pot_content = generate(<<-RUBY, "--add-comments")
273
+ # The following lines are indented
274
+ # * indented1
275
+ # * indented2
276
+ _("Message")
277
+ RUBY
278
+
279
+ assert_equal(<<-POT, pot_content)
280
+ #{header}
281
+ #. The following lines are indented
282
+ #. * indented1
283
+ #. * indented2
284
+ #: ../lib/xgettext.rb:4
285
+ msgid "Message"
286
+ msgstr ""
287
+ POT
288
+ end
289
+
290
+ def test_multiple
291
+ pot_content = generate(<<-RUBY, "--add-comments=TRANSLATORS:")
292
+ # TRANSLATORS: The first comment
293
+ _("Message")
294
+
295
+ # TRANSLATORS: The second comment
296
+ _("Message")
297
+ RUBY
298
+
299
+ assert_equal(<<-POT, pot_content)
300
+ #{header}
301
+ #. TRANSLATORS: The first comment
302
+ #. TRANSLATORS: The second comment
303
+ #: ../lib/xgettext.rb:2 ../lib/xgettext.rb:5
304
+ msgid "Message"
305
+ msgstr ""
306
+ POT
307
+ end
204
308
  end
205
309
 
206
310
  class TestCommandLineOption < self
207
311
  def test_package_name
208
- File.open(@rb_file_path, "w") do |rb_file|
209
- rb_file.puts(":hello")
210
- end
211
-
212
312
  package_name = "test-package"
213
- @xgettext.run("--output", @pot_file_path,
214
- "--package-name", package_name,
215
- @rb_file_path)
313
+ pot_content = generate(":hello", "--package-name", package_name)
216
314
 
217
315
  options = {:package_name => package_name}
218
316
  expected_header = "#{header(options)}\n"
219
- assert_equal(expected_header, File.read(@pot_file_path))
317
+ assert_equal(expected_header, pot_content)
220
318
  end
221
319
 
222
320
  def test_package_version
223
- File.open(@rb_file_path, "w") do |rb_file|
224
- rb_file.puts(":hello")
225
- end
226
-
227
321
  package_version = "1.2.3"
228
- @xgettext.run("--output", @pot_file_path,
229
- "--package-version", package_version,
230
- @rb_file_path)
322
+ pot_content = generate(":hello", "--package-version", package_version)
231
323
 
232
324
  options = {:package_version => package_version}
233
325
  expected_header = "#{header(options)}\n"
234
- assert_equal(expected_header, File.read(@pot_file_path))
326
+ assert_equal(expected_header, pot_content)
235
327
  end
236
328
 
237
329
  def test_report_msgid_bugs_to
238
- File.open(@rb_file_path, "w") do |rb_file|
239
- rb_file.puts(":hello")
240
- end
241
-
242
330
  msgid_bugs_address = "me@example.com"
243
- @xgettext.run("--output", @pot_file_path,
244
- "--msgid-bugs-address", msgid_bugs_address,
245
- @rb_file_path)
331
+ pot_content = generate(":hello",
332
+ "--msgid-bugs-address", msgid_bugs_address)
246
333
 
247
334
  options = {:msgid_bugs_address => msgid_bugs_address}
248
335
  expected_header = "#{header(options)}\n"
249
- assert_equal(expected_header, File.read(@pot_file_path))
336
+ assert_equal(expected_header, pot_content)
250
337
  end
251
338
 
252
339
  def test_copyright_holder
253
- File.open(@rb_file_path, "w") do |rb_file|
254
- rb_file.puts(":hello")
255
- end
256
-
257
340
  copyright_holder = "me"
258
- @xgettext.run("--output", @pot_file_path,
259
- "--copyright-holder", copyright_holder,
260
- @rb_file_path)
341
+ pot_content = generate(":hello", "--copyright-holder", copyright_holder)
261
342
 
262
343
  options = {:copyright_holder => copyright_holder}
263
344
  expected_header = "#{header(options)}\n"
264
- assert_equal(expected_header, File.read(@pot_file_path))
345
+ assert_equal(expected_header, pot_content)
265
346
  end
266
347
 
267
348
  def test_to_code
268
- need_encoding
269
-
270
- File.open(@rb_file_path, "w") do |rb_file|
271
- rb_file.puts(<<-EOR)
349
+ output_encoding = "EUC-JP"
350
+ pot_content = generate(<<-EOR, "--output-encoding", output_encoding)
272
351
  # -*- coding: utf-8 -*-
273
352
 
274
353
  _("わたし")
275
354
  EOR
276
- end
277
-
278
- output_encoding = "EUC-JP"
279
- @xgettext.run("--output", @pot_file_path,
280
- "--output-encoding", output_encoding,
281
- @rb_file_path)
282
-
283
- actual_pot = File.read(@pot_file_path)
284
- set_encoding(actual_pot, output_encoding)
355
+ pot_content.force_encoding(output_encoding)
285
356
 
286
357
  options = {:to_code => output_encoding}
287
358
  expected_pot = <<-EOP
@@ -290,9 +361,9 @@ EOR
290
361
  msgid "わたし"
291
362
  msgstr ""
292
363
  EOP
293
- expected_pot = encode(expected_pot, output_encoding)
364
+ expected_pot = expected_pot.encode(output_encoding)
294
365
 
295
- assert_equal(expected_pot, actual_pot)
366
+ assert_equal(expected_pot, pot_content)
296
367
  end
297
368
  end
298
369
 
@@ -313,6 +384,22 @@ EOP
313
384
  xgettext.parse(["index.html"])
314
385
  end
315
386
 
387
+ def test_old_style_parser
388
+ parser = Object.new
389
+ def parser.target?(path)
390
+ true
391
+ end
392
+ def parser.parse(path)
393
+ # It doesn't receive options argument as the second argument
394
+ [["Message"]]
395
+ end
396
+
397
+ GetText::Tools::XGetText.add_parser(parser)
398
+ xgettext = GetText::Tools::XGetText.new
399
+ assert_equal([POEntry.new_from_ary(["Message"])],
400
+ xgettext.parse(["index.html"]))
401
+ end
402
+
316
403
  def test_instance_method
317
404
  @xgettext.add_parser(mock_html_parser)
318
405
  @xgettext.parse(["index.html"])
@@ -330,60 +417,4 @@ EOP
330
417
  html_parser
331
418
  end
332
419
  end
333
-
334
- class TestRGetText < self
335
- def setup
336
- @now = Time.now
337
- @warning_message = "Warning: This method is obsolete. " +
338
- "Please use GetText::Tools::XGetText.run."
339
- end
340
-
341
- def test_warning
342
- mock(GetText::RGetText).warn(@warning_message) {}
343
-
344
- File.open(@rb_file_path, "w") do |rb_file|
345
- end
346
- GetText::RGetText.run(@rb_file_path, @pot_file_path)
347
- end
348
-
349
- class TestArguments < self
350
- def test_input_file_and_output_file
351
- stub(GetText::RGetText).warn(@warning_message) {}
352
-
353
- File.open(@rb_file_path, "w") do |rb_file|
354
- rb_file.puts(<<-EOR)
355
- _("Hello")
356
- EOR
357
- end
358
- GetText::RGetText.run(@rb_file_path, @pot_file_path)
359
-
360
- assert_equal(expected_pot_content, File.read(@pot_file_path))
361
- end
362
-
363
- def test_argv
364
- stub(GetText::RGetText).warn(@warning_message) {}
365
-
366
- File.open(@rb_file_path, "w") do |rb_file|
367
- rb_file.puts(<<-EOR)
368
- _("Hello")
369
- EOR
370
- end
371
-
372
- ARGV.replace([@rb_file_path, "--output", @pot_file_path])
373
- GetText::RGetText.run
374
-
375
- assert_equal(expected_pot_content, File.read(@pot_file_path))
376
- end
377
-
378
- private
379
- def expected_pot_content
380
- <<-EOP
381
- #{header}
382
- #: ../lib/xgettext.rb:1
383
- msgid "Hello"
384
- msgstr ""
385
- EOP
386
- end
387
- end
388
- end
389
420
  end