gettext 3.2.9 → 3.4.9

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 (237) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +276 -198
  3. data/Rakefile +7 -4
  4. data/doc/text/news.md +451 -0
  5. data/gettext.gemspec +10 -7
  6. data/lib/gettext/locale_path.rb +17 -9
  7. data/lib/gettext/mo.rb +12 -19
  8. data/lib/gettext/po.rb +4 -4
  9. data/lib/gettext/po_entry.rb +47 -27
  10. data/lib/gettext/po_parser.rb +65 -59
  11. data/lib/gettext/text_domain.rb +1 -1
  12. data/lib/gettext/text_domain_manager.rb +6 -5
  13. data/lib/gettext/tools/msgcat.rb +9 -2
  14. data/lib/gettext/tools/msginit.rb +226 -54
  15. data/lib/gettext/tools/msgmerge.rb +24 -6
  16. data/lib/gettext/tools/parser/erb.rb +9 -1
  17. data/lib/gettext/tools/parser/erubi.rb +88 -0
  18. data/lib/gettext/tools/parser/glade.rb +38 -40
  19. data/lib/gettext/tools/parser/gtk_builder_ui_definitions.rb +129 -0
  20. data/lib/gettext/tools/parser/ruby.rb +288 -221
  21. data/lib/gettext/tools/task.rb +4 -5
  22. data/lib/gettext/tools/xgettext.rb +21 -10
  23. data/lib/gettext/version.rb +3 -3
  24. data/locale/bg/LC_MESSAGES/gettext.mo +0 -0
  25. data/locale/bs/LC_MESSAGES/gettext.mo +0 -0
  26. data/locale/ca/LC_MESSAGES/gettext.mo +0 -0
  27. data/locale/cs/LC_MESSAGES/gettext.mo +0 -0
  28. data/locale/de/LC_MESSAGES/gettext.mo +0 -0
  29. data/locale/el/LC_MESSAGES/gettext.mo +0 -0
  30. data/locale/eo/LC_MESSAGES/gettext.mo +0 -0
  31. data/locale/es/LC_MESSAGES/gettext.mo +0 -0
  32. data/locale/et/LC_MESSAGES/gettext.mo +0 -0
  33. data/locale/fr/LC_MESSAGES/gettext.mo +0 -0
  34. data/locale/hr/LC_MESSAGES/gettext.mo +0 -0
  35. data/locale/hu/LC_MESSAGES/gettext.mo +0 -0
  36. data/locale/it/LC_MESSAGES/gettext.mo +0 -0
  37. data/locale/ja/LC_MESSAGES/gettext.mo +0 -0
  38. data/locale/ko/LC_MESSAGES/gettext.mo +0 -0
  39. data/locale/lv/LC_MESSAGES/gettext.mo +0 -0
  40. data/locale/nb/LC_MESSAGES/gettext.mo +0 -0
  41. data/locale/nl/LC_MESSAGES/gettext.mo +0 -0
  42. data/locale/pt_BR/LC_MESSAGES/gettext.mo +0 -0
  43. data/locale/ru/LC_MESSAGES/gettext.mo +0 -0
  44. data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
  45. data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
  46. data/locale/vi/LC_MESSAGES/gettext.mo +0 -0
  47. data/locale/zh/LC_MESSAGES/gettext.mo +0 -0
  48. data/locale/zh_TW/LC_MESSAGES/gettext.mo +0 -0
  49. data/po/bg/gettext.edit.po +81 -572
  50. data/po/bg/gettext.po +7 -409
  51. data/po/bs/gettext.edit.po +81 -572
  52. data/po/bs/gettext.po +7 -409
  53. data/po/ca/gettext.edit.po +81 -572
  54. data/po/ca/gettext.po +7 -409
  55. data/po/cs/gettext.edit.po +81 -572
  56. data/po/cs/gettext.po +7 -409
  57. data/po/de/gettext.edit.po +81 -572
  58. data/po/de/gettext.po +7 -409
  59. data/po/el/gettext.edit.po +81 -572
  60. data/po/el/gettext.po +7 -409
  61. data/po/eo/gettext.edit.po +81 -572
  62. data/po/eo/gettext.po +7 -409
  63. data/po/es/gettext.edit.po +81 -572
  64. data/po/es/gettext.po +7 -409
  65. data/po/et/gettext.edit.po +81 -572
  66. data/po/et/gettext.po +7 -409
  67. data/po/fr/gettext.edit.po +81 -572
  68. data/po/fr/gettext.po +7 -409
  69. data/po/gettext.pot +93 -645
  70. data/po/hr/gettext.edit.po +81 -572
  71. data/po/hr/gettext.po +7 -409
  72. data/po/hu/gettext.edit.po +81 -572
  73. data/po/hu/gettext.po +7 -409
  74. data/po/it/gettext.edit.po +81 -572
  75. data/po/it/gettext.po +7 -409
  76. data/po/ja/gettext.edit.po +83 -574
  77. data/po/ja/gettext.po +9 -411
  78. data/po/ko/gettext.edit.po +81 -572
  79. data/po/ko/gettext.po +7 -409
  80. data/po/lv/gettext.edit.po +81 -572
  81. data/po/lv/gettext.po +7 -409
  82. data/po/nb/gettext.edit.po +81 -572
  83. data/po/nb/gettext.po +7 -409
  84. data/po/nl/gettext.edit.po +81 -572
  85. data/po/nl/gettext.po +7 -409
  86. data/po/pt_BR/gettext.edit.po +81 -572
  87. data/po/pt_BR/gettext.po +7 -409
  88. data/po/ru/gettext.edit.po +81 -572
  89. data/po/ru/gettext.po +7 -409
  90. data/po/sr/gettext.edit.po +81 -572
  91. data/po/sr/gettext.po +7 -409
  92. data/po/sv/gettext.edit.po +81 -572
  93. data/po/sv/gettext.po +7 -409
  94. data/po/uk/gettext.edit.po +81 -572
  95. data/po/uk/gettext.po +7 -409
  96. data/po/vi/gettext.edit.po +81 -572
  97. data/po/vi/gettext.po +7 -409
  98. data/po/zh/gettext.edit.po +81 -572
  99. data/po/zh/gettext.po +7 -409
  100. data/po/zh_TW/gettext.edit.po +81 -572
  101. data/po/zh_TW/gettext.po +7 -409
  102. data/samples/cgi/po/helloerb1.pot +3 -3
  103. data/samples/cgi/po/helloerb2.pot +3 -3
  104. data/samples/cgi/po/hellolib.pot +3 -3
  105. data/samples/cgi/po/main.pot +3 -3
  106. data/samples/po/bg/hello_gtk_builder.edit.po +15 -0
  107. data/samples/po/bg/hello_gtk_builder.po +12 -0
  108. data/samples/po/bs/hello_gtk_builder.edit.po +15 -0
  109. data/samples/po/bs/hello_gtk_builder.po +12 -0
  110. data/samples/po/ca/hello_gtk_builder.edit.po +15 -0
  111. data/samples/po/ca/hello_gtk_builder.po +12 -0
  112. data/samples/po/cs/hello_gtk_builder.edit.po +15 -0
  113. data/samples/po/cs/hello_gtk_builder.po +12 -0
  114. data/samples/po/de/hello_gtk_builder.edit.po +15 -0
  115. data/samples/po/de/hello_gtk_builder.po +12 -0
  116. data/samples/po/el/hello_gtk_builder.edit.po +15 -0
  117. data/samples/po/el/hello_gtk_builder.po +12 -0
  118. data/samples/po/eo/hello_gtk_builder.edit.po +15 -0
  119. data/samples/po/eo/hello_gtk_builder.po +12 -0
  120. data/samples/po/es/hello_gtk_builder.edit.po +15 -0
  121. data/samples/po/es/hello_gtk_builder.po +12 -0
  122. data/samples/po/fr/hello_gtk_builder.edit.po +15 -0
  123. data/samples/po/fr/hello_gtk_builder.po +12 -0
  124. data/samples/po/hello.pot +3 -3
  125. data/samples/po/hello2.pot +4 -4
  126. data/samples/po/hello_glade2.pot +8 -5
  127. data/samples/po/hello_gtk2.pot +4 -4
  128. data/samples/po/hello_gtk_builder.pot +18 -4
  129. data/samples/po/hello_noop.pot +4 -4
  130. data/samples/po/hello_plural.pot +4 -4
  131. data/samples/po/hello_tk.pot +4 -4
  132. data/samples/po/hr/hello_gtk_builder.edit.po +15 -0
  133. data/samples/po/hr/hello_gtk_builder.po +12 -0
  134. data/samples/po/hu/hello_gtk_builder.edit.po +15 -0
  135. data/samples/po/hu/hello_gtk_builder.po +12 -0
  136. data/samples/po/it/hello_gtk_builder.edit.po +15 -0
  137. data/samples/po/it/hello_gtk_builder.po +12 -0
  138. data/samples/po/ja/hello_gtk_builder.edit.po +15 -0
  139. data/samples/po/ja/hello_gtk_builder.po +12 -0
  140. data/samples/po/ko/hello_gtk_builder.edit.po +15 -0
  141. data/samples/po/ko/hello_gtk_builder.po +12 -0
  142. data/samples/po/lv/hello_gtk_builder.edit.po +15 -0
  143. data/samples/po/lv/hello_gtk_builder.po +12 -0
  144. data/samples/po/nb/hello_gtk_builder.edit.po +15 -0
  145. data/samples/po/nb/hello_gtk_builder.po +12 -0
  146. data/samples/po/nl/hello_gtk_builder.edit.po +15 -0
  147. data/samples/po/nl/hello_gtk_builder.po +12 -0
  148. data/samples/po/pt_BR/hello_gtk_builder.edit.po +15 -0
  149. data/samples/po/pt_BR/hello_gtk_builder.po +12 -0
  150. data/samples/po/ru/hello_gtk_builder.edit.po +15 -0
  151. data/samples/po/ru/hello_gtk_builder.po +12 -0
  152. data/samples/po/sr/hello_gtk_builder.edit.po +15 -0
  153. data/samples/po/sr/hello_gtk_builder.po +12 -0
  154. data/samples/po/sv/hello_gtk_builder.edit.po +15 -0
  155. data/samples/po/sv/hello_gtk_builder.po +12 -0
  156. data/samples/po/uk/hello_gtk_builder.edit.po +15 -0
  157. data/samples/po/uk/hello_gtk_builder.po +12 -0
  158. data/samples/po/vi/hello_gtk_builder.edit.po +15 -0
  159. data/samples/po/vi/hello_gtk_builder.po +12 -0
  160. data/samples/po/zh/hello_gtk_builder.edit.po +15 -0
  161. data/samples/po/zh/hello_gtk_builder.po +12 -0
  162. data/samples/po/zh_TW/hello_gtk_builder.edit.po +15 -0
  163. data/samples/po/zh_TW/hello_gtk_builder.po +12 -0
  164. data/src/po_parser.ry +48 -42
  165. data/test/fixtures/_/backtick.rb +30 -0
  166. data/test/fixtures/_/block_parameter.rb +2 -2
  167. data/test/fixtures/_/double_quote_in_double_quote.rb +2 -2
  168. data/test/fixtures/_/double_quote_in_single_quote.rb +2 -2
  169. data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +2 -2
  170. data/test/fixtures/_/middle_new_line.rb +2 -2
  171. data/test/fixtures/_/multiple_lines_literal.rb +2 -2
  172. data/test/fixtures/_/multiple_messages_in_same_line.rb +2 -2
  173. data/test/fixtures/_/multiple_same_messages.rb +2 -2
  174. data/test/fixtures/_/one_line.rb +2 -2
  175. data/test/fixtures/_/one_new_line.rb +2 -2
  176. data/test/fixtures/_/percent_strings.rb +55 -0
  177. data/test/fixtures/_/pipe.rb +32 -0
  178. data/test/{gettext-test-utils.rb → fixtures/_/quoted_symbol.rb} +13 -23
  179. data/test/fixtures/_.rb +10 -1
  180. data/test/fixtures/erb/case.rhtml +16 -0
  181. data/test/fixtures/erb/minus.rhtml +12 -0
  182. data/test/fixtures/erb/non_ascii.rhtml +1 -0
  183. data/test/fixtures/glade/3.glade +63 -0
  184. data/test/fixtures/gtk_builder_ui_definitions.ui +68 -0
  185. data/test/fixtures/multi_text_domain.rb +12 -12
  186. data/test/fixtures/np_.rb +1 -1
  187. data/test/fixtures/ns_/custom.rb +2 -2
  188. data/test/fixtures/ns_.rb +1 -1
  189. data/test/fixtures/p_.rb +1 -1
  190. data/test/fixtures/ruby/percent_lower_i.rb +1 -0
  191. data/test/fixtures/ruby/percent_lower_w.rb +1 -0
  192. data/test/fixtures/ruby/percent_upper_i.rb +1 -0
  193. data/test/fixtures/ruby/percent_upper_w.rb +1 -0
  194. data/test/fixtures/s_/custom.rb +2 -2
  195. data/test/fixtures/s_.rb +1 -1
  196. data/test/fixtures/simple.rb +5 -1
  197. data/test/fixtures/upper_nn_.rb +77 -0
  198. data/test/helper.rb +99 -0
  199. data/test/locale/fr/LC_MESSAGES/plural_error.mo +0 -0
  200. data/test/locale/fr/LC_MESSAGES/test1.mo +0 -0
  201. data/test/locale/fr_BE/LC_MESSAGES/test1.mo +0 -0
  202. data/test/locale/fr_BE_Foo/LC_MESSAGES/test1.mo +0 -0
  203. data/test/locale/ja/LC_MESSAGES/_.mo +0 -0
  204. data/test/po/_.pot +28 -4
  205. data/test/po/backslash.pot +6 -4
  206. data/test/po/fr/plural_error.po +7 -0
  207. data/test/po/fr/test1.po +7 -0
  208. data/test/po/fr_BE/test1.po +24 -0
  209. data/test/po/fr_BE_Foo/test1.po +20 -0
  210. data/test/po/hello.pot +3 -3
  211. data/test/po/ja/_.edit.po +27 -3
  212. data/test/po/ja/_.po +20 -2
  213. data/test/po/ja/hello.edit.po +0 -1
  214. data/test/po/non_ascii.pot +4 -4
  215. data/test/po/np_.pot +8 -5
  216. data/test/po/ns_.pot +6 -4
  217. data/test/po/p_.pot +3 -3
  218. data/test/po/s_.pot +6 -4
  219. data/test/po/untranslated.pot +4 -4
  220. data/test/run-test.rb +2 -3
  221. data/test/test_class_info.rb +8 -9
  222. data/test/test_gettext.rb +30 -1
  223. data/test/test_locale_path.rb +12 -4
  224. data/test/test_parser.rb +113 -25
  225. data/test/test_po_entry.rb +21 -17
  226. data/test/test_po_parser.rb +49 -4
  227. data/test/test_string.rb +9 -5
  228. data/test/tools/parser/test_glade.rb +91 -0
  229. data/test/tools/parser/test_gtk_builder_ui_definitions.rb +63 -0
  230. data/test/tools/parser/test_ruby.rb +76 -39
  231. data/test/tools/test_msgcat.rb +21 -1
  232. data/test/tools/test_msginit.rb +82 -3
  233. data/test/tools/test_msgmerge.rb +81 -6
  234. data/test/tools/test_xgettext.rb +106 -5
  235. metadata +82 -34
  236. data/lib/gettext/tools/parser/haml.rb +0 -61
  237. /data/test/fixtures/{gladeparser.glade → glade/2.glade} +0 -0
data/test/test_parser.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2012-2021 Sutou Kouhei <kou@clear-code.com>
5
5
  # Copyright (C) 2010 masone (Christian Felder) <ema@rh-productions.ch>
6
6
  # Copyright (C) 2009 Vladimir Dobriakov <vladimir@geekq.net>
7
7
  # Copyright (C) 2009-2010 Masao Mutoh
@@ -23,8 +23,8 @@
23
23
 
24
24
  require "tempfile"
25
25
  require "gettext/tools/parser/ruby"
26
- require "gettext/tools/parser/glade"
27
26
  require "gettext/tools/parser/erb"
27
+ require "gettext/tools/parser/erubi"
28
28
 
29
29
  require "gettext/tools/xgettext"
30
30
 
@@ -97,6 +97,40 @@ class TestGetTextParser < Test::Unit::TestCase
97
97
  ['fixtures/upper_n_.rb:64'])
98
98
  end
99
99
 
100
+ def test_Nn_
101
+ @ary = @xgettext.parse(['fixtures/upper_nn_.rb'])
102
+
103
+ assert_plural_target('aaa', 'aaas',
104
+ ['fixtures/upper_nn_.rb:10'])
105
+ assert_plural_target("aaa\n", "aaas\n",
106
+ ['fixtures/upper_nn_.rb:14'])
107
+ assert_plural_target("bbb\nccc", "bbbs\ncccs",
108
+ ['fixtures/upper_nn_.rb:18'])
109
+ assert_plural_target("bbb\nccc\nddd\n", "bbbs\ncccs\nddds\n",
110
+ ['fixtures/upper_nn_.rb:22'])
111
+ assert_plural_target('eee', 'eees',
112
+ [
113
+ 'fixtures/upper_nn_.rb:33',
114
+ 'fixtures/upper_nn_.rb:37',
115
+ ])
116
+ assert_plural_target('fff', 'fffs',
117
+ ['fixtures/upper_nn_.rb:37'])
118
+ assert_plural_target('ggghhhiii', 'gggshhhsiiis',
119
+ ['fixtures/upper_nn_.rb:41'])
120
+ assert_plural_target('a"b"c"', 'as"bs"cs"',
121
+ ['fixtures/upper_nn_.rb:50'])
122
+ assert_plural_target('d"e"f"', 'ds"es"fs"',
123
+ ['fixtures/upper_nn_.rb:54'])
124
+ assert_plural_target('jjj', 'jjjs',
125
+ ['fixtures/upper_nn_.rb:58'])
126
+ assert_plural_target('kkk', 'kkks',
127
+ ['fixtures/upper_nn_.rb:59'])
128
+ assert_plural_target('lllmmm', 'lllsmmms',
129
+ ['fixtures/upper_nn_.rb:63'])
130
+ assert_plural_target("nnn\nooo", "nnns\nooos",
131
+ ['fixtures/upper_nn_.rb:71'])
132
+ end
133
+
100
134
  def test_n_
101
135
  @xgettext.parse_options[:comment_tag] = "TRANSLATORS:"
102
136
  @ary = @xgettext.parse(['fixtures/lower_n_.rb'])
@@ -144,23 +178,61 @@ class TestGetTextParser < Test::Unit::TestCase
144
178
  end
145
179
  end
146
180
 
147
- class TestGlade < self
148
- def test_old_style
149
- # Old style (~2.0.4)
150
- ary = GetText::GladeParser.parse('fixtures/gladeparser.glade')
181
+ class TestErbParser < self
182
+ include Helper::Path
183
+
184
+ def test_detect_encoding
185
+ euc_file = Tempfile.new("euc-jp.rhtml")
186
+ euc_file.open
187
+ euc_file.puts("<%#-*- coding: euc-jp -*-%>")
188
+ euc_file.close
189
+
190
+ erb_source = ERB.new(File.read(euc_file.path)).src
191
+ encoding = GetText::ErbParser.new(euc_file.path).detect_encoding(erb_source)
192
+
193
+ assert_equal("EUC-JP", encoding)
194
+ end
195
+
196
+ def test_ascii
197
+ path = fixture_path("erb", "ascii.rhtml")
198
+ @ary = GetText::ErbParser.parse(path)
199
+
200
+ assert_target 'aaa', ["#{path}:8"]
201
+ assert_target "aaa\n", ["#{path}:11"]
202
+ assert_target 'bbb', ["#{path}:12"]
203
+ assert_plural_target "ccc1", "ccc2", ["#{path}:13"]
204
+ end
205
+
206
+ def test_non_ascii
207
+ path = fixture_path("erb", "non_ascii.rhtml")
208
+ @ary = GetText::ErbParser.parse(path)
209
+
210
+ assert_target('わたし', ["#{path}:12"])
211
+ end
212
+
213
+ def test_minus
214
+ path = fixture_path("erb", "minus.rhtml")
215
+ @ary = GetText::ErbParser.parse(path)
216
+
217
+ assert_target("Hello", ["#{path}:8"])
218
+ end
219
+
220
+ def test_case
221
+ path = fixture_path("erb", "case.rhtml")
222
+ @ary = GetText::ErbParser.parse(path)
151
223
 
152
- assert_equal(['window1', 'fixtures/gladeparser.glade:8'], ary[0])
153
- assert_equal(['normal text', 'fixtures/gladeparser.glade:29'], ary[1])
154
- assert_equal(['1st line\n2nd line\n3rd line', 'fixtures/gladeparser.glade:50'], ary[2])
155
- assert_equal(['<span color="red" weight="bold" size="large">markup </span>', 'fixtures/gladeparser.glade:73'], ary[3])
156
- assert_equal(['<span color="red">1st line markup </span>\n<span color="blue">2nd line markup</span>', 'fixtures/gladeparser.glade:94'], ary[4])
157
- assert_equal(['<span>&quot;markup&quot; with &lt;escaped strings&gt;</span>', 'fixtures/gladeparser.glade:116'], ary[5])
158
- assert_equal(['duplicated', 'fixtures/gladeparser.glade:137', 'fixtures/gladeparser.glade:158'], ary[6])
224
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
225
+ assert_target("Hello", ["#{path}:11"])
226
+ assert_target("World", ["#{path}:14"])
227
+ else
228
+ assert_target("Hello", ["#{path}:11"])
229
+ assert_nil(@ary.detect {|elem| elem.msgid == 'World'}) # Not detected. see PR #91
230
+ end
159
231
  end
160
232
  end
161
233
 
162
- class TestErbParser < self
163
- include GetTextTestUtils
234
+ class TestErubiParser < self
235
+ include Helper::Path
164
236
 
165
237
  def test_detect_encoding
166
238
  euc_file = Tempfile.new("euc-jp.rhtml")
@@ -168,26 +240,42 @@ class TestGetTextParser < Test::Unit::TestCase
168
240
  euc_file.puts("<%#-*- coding: euc-jp -*-%>")
169
241
  euc_file.close
170
242
 
171
- erb_source = ERB.new(File.read(euc_file.path)).src
172
- encoding = GetText::ErbParser.new(euc_file.path).detect_encoding(erb_source)
243
+ euc_file_content = File.read(euc_file.path)
244
+ encoding = GetText::ErubiParser.new(euc_file.path).detect_encoding(euc_file_content)
173
245
 
174
246
  assert_equal("EUC-JP", encoding)
175
247
  end
176
248
 
177
249
  def test_ascii
178
- @ary = GetText::ErbParser.parse('fixtures/erb/ascii.rhtml')
250
+ path = fixture_path("erb", "ascii.rhtml")
251
+ @ary = GetText::ErubiParser.parse(path)
179
252
 
180
- assert_target 'aaa', ['fixtures/erb/ascii.rhtml:8']
181
- assert_target "aaa\n", ['fixtures/erb/ascii.rhtml:11']
182
- assert_target 'bbb', ['fixtures/erb/ascii.rhtml:12']
183
- assert_plural_target "ccc1", "ccc2", ['fixtures/erb/ascii.rhtml:13']
253
+ assert_target 'aaa', ["#{path}:8"]
254
+ assert_target "aaa\n", ["#{path}:11"]
255
+ assert_target 'bbb', ["#{path}:12"]
256
+ assert_plural_target "ccc1", "ccc2", ["#{path}:13"]
184
257
  end
185
258
 
186
259
  def test_non_ascii
187
- fixture_path = "fixtures/erb/non_ascii.rhtml"
188
- @ary = GetText::ErbParser.parse(fixture_path)
260
+ path = fixture_path("erb", "non_ascii.rhtml")
261
+ @ary = GetText::ErubiParser.parse(path)
262
+
263
+ assert_target('わたし', ["#{path}:12"])
264
+ end
265
+
266
+ def test_minus
267
+ path = fixture_path("erb", "minus.rhtml")
268
+ @ary = GetText::ErubiParser.parse(path)
269
+
270
+ assert_target("Hello", ["#{path}:8"])
271
+ end
272
+
273
+ def test_case
274
+ path = fixture_path("erb", "case.rhtml")
275
+ @ary = GetText::ErubiParser.parse(path)
189
276
 
190
- assert_target('わたし', ["#{fixture_path}:11"])
277
+ assert_target("Hello", ["#{path}:11"])
278
+ assert_target("World", ["#{path}:14"]) # Detected with Erubi
191
279
  end
192
280
  end
193
281
 
@@ -1,7 +1,5 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
1
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2012-2014 Kouhei Sutou <kou@clear-code.com>
2
+ # Copyright (C) 2012-2019 Sutou Kouhei <kou@clear-code.com>
5
3
  # Copyright (C) 2010 masone (Christian Felder) <ema@rh-productions.ch>
6
4
  # Copyright (C) 2009 Masao Mutoh
7
5
  #
@@ -35,16 +33,6 @@ class TestPOEntry < Test::Unit::TestCase
35
33
  end
36
34
  end
37
35
 
38
- def test_attribute_accumulation
39
- tt = GetText::POEntry.new(:plural)
40
- tt.set_current_attribute 'long'
41
- tt.set_current_attribute ' tail'
42
- tt.advance_to_next_attribute
43
- tt.set_current_attribute 'long tails'
44
- assert_equal 'long tail', tt.msgid
45
- assert_equal 'long tails', tt.msgid_plural
46
- end
47
-
48
36
  class TestSetType < self
49
37
  def test_varid_type
50
38
  entry = GetText::POEntry.new(:normal)
@@ -245,13 +233,15 @@ EOE
245
233
  class TestEscape < self
246
234
  def test_normal
247
235
  entry = GetText::POEntry.new(:normal)
248
- entry.msgid = "He said \"hello.\""
249
- entry.msgstr = "Il a dit \"bonjour.\""
236
+ entry.msgid = "He said \"hello.\"\r\n"
237
+ entry.msgstr = "Il a dit \"bonjour.\"\r\n"
250
238
  entry.references = ["file1:1", "file2:10"]
251
239
  expected_po = <<-EOE
252
240
  #: file1:1 file2:10
253
- msgid "He said \\"hello.\\""
254
- msgstr "Il a dit \\"bonjour.\\""
241
+ msgid ""
242
+ "He said \\"hello.\\"\\r\\n"
243
+ msgstr ""
244
+ "Il a dit \\"bonjour.\\"\\r\\n"
255
245
  EOE
256
246
  assert_equal(expected_po, entry.to_s)
257
247
  end
@@ -354,6 +344,20 @@ EOP
354
344
  assert_equal(expected_po, entry.to_s)
355
345
  end
356
346
 
347
+ def test_multiple_flags
348
+ entry = GetText::POEntry.new(:normal)
349
+ entry.msgid = "msgid"
350
+ entry.msgstr = "msgstr"
351
+ entry.flags = ["It's the flag.", "fuzzy"]
352
+
353
+ expected_po = <<-EOP
354
+ #, It's the flag., fuzzy
355
+ msgid "msgid"
356
+ msgstr "msgstr"
357
+ EOP
358
+ assert_equal(expected_po, entry.to_s)
359
+ end
360
+
357
361
  def test_previous
358
362
  entry = GetText::POEntry.new(:normal)
359
363
  entry.msgid = "msgid"
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2012-2023 Sutou Kouhei <kou@clear-code.com>
4
2
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
5
3
  #
6
4
  # License: Ruby's or LGPL
@@ -62,6 +60,18 @@ EOP
62
60
  end
63
61
 
64
62
  class TestPO < self
63
+ include Helper::Warning
64
+
65
+ def test_msgid_escape
66
+ po_file = create_po_file(<<-'EOP')
67
+ msgid "\\\\r \\r \t \r \n"
68
+ msgstr "\\\\r \\r \t \r \n"
69
+ EOP
70
+ entries = parse_po_file(po_file)
71
+ assert_equal("\\\\r \\r \t \r \n",
72
+ entries["\\\\r \\r \t \r \n"].msgstr)
73
+ end
74
+
65
75
  def test_msgstr
66
76
  po_file = create_po_file(<<-EOP)
67
77
  # This is the comment.
@@ -220,12 +230,47 @@ EOP
220
230
  msgid "hello"
221
231
  msgstr "bonjour"
222
232
  EOP
223
- entries = parse_po_file(po_file, :ignore_fuzzy => false)
233
+ entries = suppress_warning do
234
+ parse_po_file(po_file, :ignore_fuzzy => false)
235
+ end
224
236
 
225
237
  assert_true(entries.has_key?("hello"))
226
238
  assert_equal("fuzzy", entries["hello"].flag)
227
239
  end
228
240
 
241
+ def test_fuzzy_ignore
242
+ po_file = create_po_file(<<-PO)
243
+ #, fuzzy
244
+ #: file.rb:10
245
+ msgid "hello"
246
+ msgstr "bonjour"
247
+
248
+ #, c-format, fuzzy , no-sh-format
249
+ #: file.rb:11
250
+ msgid "world"
251
+ msgstr "monde"
252
+
253
+ # This is not fuzzy
254
+ msgid "non-fuzzy"
255
+ msgstr "non-fuzzy string"
256
+ PO
257
+ entries = suppress_warning do
258
+ parse_po_file(po_file)
259
+ end
260
+
261
+ actual = entries.collect do |entry|
262
+ [
263
+ entry.msgid,
264
+ entry.msgstr,
265
+ entry.flags,
266
+ ]
267
+ end
268
+ assert_equal([
269
+ ["non-fuzzy", "non-fuzzy string", []],
270
+ ],
271
+ actual)
272
+ end
273
+
229
274
  private
230
275
  def parse_po_file(po_file, options={:ignore_fuzzy => true})
231
276
  ignore_fuzzy = options[:ignore_fuzzy]
data/test/test_string.rb CHANGED
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  class TestGetTextString < Test::Unit::TestCase
4
2
  class TestFormat < self
3
+ include Helper::Warning
4
+
5
5
  def test_basic
6
6
  assert_equal("foo is a number", "%{msg} is a number" % {:msg => "foo"})
7
7
  assert_equal("bar is a number", "%s is a number" % ["bar"])
@@ -22,7 +22,9 @@ class TestGetTextString < Test::Unit::TestCase
22
22
 
23
23
  def test_percent
24
24
  assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
25
- assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
25
+ suppress_warning do
26
+ assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
27
+ end
26
28
  end
27
29
 
28
30
  def test_percent_in_replacement
@@ -30,8 +32,10 @@ class TestGetTextString < Test::Unit::TestCase
30
32
  end
31
33
 
32
34
  def test_no_placeholder
33
- assert_equal("aaa", "aaa" % {:num => 1})
34
- assert_equal("bbb", "bbb" % [1])
35
+ suppress_warning do
36
+ assert_equal("aaa", "aaa" % {:num => 1})
37
+ assert_equal("bbb", "bbb" % [1])
38
+ end
35
39
  end
36
40
 
37
41
  def test_ruby19_style
@@ -0,0 +1,91 @@
1
+ # Copyright (C) 2009-2010 Masao Mutoh
2
+ # Copyright (C) 2021 Sutou Kouhei <kou@clear-code.com>
3
+ #
4
+ # License: Ruby's or LGPL
5
+ #
6
+ # This library is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require "gettext/tools/parser/glade"
20
+
21
+ class TestGladeParser < Test::Unit::TestCase
22
+ include Helper::Parser
23
+
24
+ def parse(file)
25
+ GetText::GladeParser.parse(fixture_path(file))
26
+ end
27
+
28
+ def test_2
29
+ assert_parse([
30
+ {
31
+ msgid: "window1",
32
+ references: ["glade/2.glade:8"],
33
+ },
34
+ {
35
+ msgid: "normal text",
36
+ references: ["glade/2.glade:29"],
37
+ },
38
+ {
39
+ msgid: "1st line\n2nd line\n3rd line",
40
+ references: ["glade/2.glade:50"],
41
+ },
42
+ {
43
+ msgid:
44
+ "<span color=\"red\" " +
45
+ "weight=\"bold\" " +
46
+ "size=\"large\">markup </span>",
47
+ references: ["glade/2.glade:73"],
48
+ },
49
+ {
50
+ msgid:
51
+ "<span color=\"red\">1st line markup </span>\n" +
52
+ "<span color=\"blue\">2nd line markup</span>",
53
+ references: ["glade/2.glade:94"],
54
+ },
55
+ {
56
+ msgid:
57
+ "<span>" +
58
+ "&quot;markup&quot; with &lt;escaped strings&gt;" +
59
+ "</span>",
60
+ references: ["glade/2.glade:116"],
61
+ },
62
+ {
63
+ msgid: "duplicated",
64
+ references: [
65
+ "glade/2.glade:137",
66
+ "glade/2.glade:158",
67
+ ],
68
+ },
69
+ ],
70
+ "glade/2.glade")
71
+ end
72
+
73
+
74
+ class TestDetect < self
75
+ def target?(file)
76
+ GetText::GladeParser.target?(fixture_path(file))
77
+ end
78
+
79
+ def test_2
80
+ assert do
81
+ target?("glade/2.glade")
82
+ end
83
+ end
84
+
85
+ def test_3
86
+ assert do
87
+ not target?("glade/3.glade")
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,63 @@
1
+ # Copyright (C) 2020 Sutou Kouhei <kou@clear-code.com>
2
+ #
3
+ # License: Ruby's or LGPL
4
+ #
5
+ # This library is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "gettext/tools/parser/gtk_builder_ui_definitions"
19
+
20
+ class TestGtkBuilderUIDefinitionsParser < Test::Unit::TestCase
21
+ include Helper::Parser
22
+
23
+ def parse(file)
24
+ GetText::GtkBuilderUIDefinitionsParser.parse(fixture_path(file))
25
+ end
26
+
27
+ def test_ui
28
+ assert_parse([
29
+ {
30
+ :msgid => "label with context",
31
+ :msgctxt => "context",
32
+ :references => ["gtk_builder_ui_definitions.ui:19"],
33
+ },
34
+ {
35
+ :msgid => "label simple",
36
+ :references => ["gtk_builder_ui_definitions.ui:31"],
37
+ },
38
+ {
39
+ :msgid => "multiple\n" + "lines\n" + "label",
40
+ :references => ["gtk_builder_ui_definitions.ui:55"],
41
+ },
42
+ ],
43
+ "gtk_builder_ui_definitions.ui")
44
+ end
45
+
46
+ class TestDetect < self
47
+ def target?(file)
48
+ GetText::GtkBuilderUIDefinitionsParser.target?(fixture_path(file))
49
+ end
50
+
51
+ def test_ui
52
+ assert do
53
+ target?("gtk_builder_ui_definitions.ui")
54
+ end
55
+ end
56
+
57
+ def test_glade_3
58
+ assert do
59
+ target?("glade/3.glade")
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2012-2020 Sutou Kouhei <kou@clear-code.com>
5
5
  # Copyright (C) 2010 masone (Christian Felder) <ema@rh-productions.ch>
6
6
  # Copyright (C) 2009 Vladimir Dobriakov <vladimir@geekq.net>
7
7
  # Copyright (C) 2009-2010 Masao Mutoh
@@ -24,49 +24,12 @@
24
24
  require "gettext/tools/parser/ruby"
25
25
 
26
26
  class TestRubyParser < Test::Unit::TestCase
27
- include GetTextTestUtils
27
+ include Helper::Parser
28
28
 
29
- private
30
29
  def parse(file)
31
30
  GetText::RubyParser.parse(fixture_path(file))
32
31
  end
33
32
 
34
- def assert_parse(expected, file)
35
- assert_equal(normalize_expected(expected),
36
- normalize_actual(parse(file)))
37
- end
38
-
39
- def normalize_expected(messages)
40
- messages.collect do |message|
41
- default = {
42
- :msgid => nil,
43
- :msgid_plural => nil,
44
- :msgstr => nil,
45
- :separator => nil,
46
- :references => nil,
47
- }
48
- default.merge(message)
49
- end
50
- end
51
-
52
- def normalize_actual(po)
53
- po.collect do |po_entry|
54
- {
55
- :msgid => po_entry.msgid,
56
- :msgid_plural => po_entry.msgid_plural,
57
- :msgstr => po_entry.msgstr,
58
- :separator => po_entry.separator,
59
- :references => normalize_references(po_entry.references),
60
- }
61
- end
62
- end
63
-
64
- def normalize_references(references)
65
- references.collect do |reference|
66
- reference.sub(/\A#{Regexp.escape(fixture_path)}\//, "")
67
- end
68
- end
69
-
70
33
  class TestDetectEncoding < self
71
34
  def test_ascii_and_hyphen
72
35
  assert_equal("euc-jp", detect_encoding("# coding: euc-jp"))
@@ -227,6 +190,53 @@ class TestRubyParser < Test::Unit::TestCase
227
190
  path)
228
191
  end
229
192
 
193
+
194
+ def test_percent_strings
195
+ path = "percent_strings.rb"
196
+ assert_parse([
197
+ {
198
+ :msgid => "in_symbol_array",
199
+ :references => ["#{path}:31"],
200
+ },
201
+ {
202
+ :msgid => "hello world",
203
+ :references => ["#{path}:39"],
204
+ },
205
+ {
206
+ :msgid => "in_string_array",
207
+ :references => ["#{path}:47"],
208
+ },
209
+ ],
210
+ path)
211
+ end
212
+
213
+ def test_quoted_symbol
214
+ path = "quoted_symbol.rb"
215
+ assert_parse([],
216
+ path)
217
+ end
218
+
219
+ def test_backtick
220
+ path = "backtick.rb"
221
+ assert_parse([],
222
+ path)
223
+ end
224
+
225
+ def test_pipe
226
+ path = "pipe.rb"
227
+ assert_parse([
228
+ {
229
+ :msgid => "Hello",
230
+ :references => ["#{path}:26"],
231
+ },
232
+ {
233
+ :msgid => "World",
234
+ :references => ["#{path}:28"],
235
+ },
236
+ ],
237
+ path)
238
+ end
239
+
230
240
  private
231
241
  def fixture_path(*components)
232
242
  super("_", *components)
@@ -271,4 +281,31 @@ class TestRubyParser < Test::Unit::TestCase
271
281
  super("ns_", *components)
272
282
  end
273
283
  end
284
+
285
+ sub_test_case("parse") do
286
+ def test_percent_w
287
+ assert_parse([],
288
+ "percent_lower_w.rb")
289
+ end
290
+
291
+ def test_percent_W
292
+ assert_parse([],
293
+ "percent_upper_w.rb")
294
+ end
295
+
296
+ def test_percent_i
297
+ assert_parse([],
298
+ "percent_lower_i.rb")
299
+ end
300
+
301
+ def test_percent_I
302
+ assert_parse([],
303
+ "percent_upper_i.rb")
304
+ end
305
+
306
+ private
307
+ def fixture_path(*components)
308
+ super("ruby", *components)
309
+ end
310
+ end
274
311
  end