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.
- checksums.yaml +4 -4
- data/README.md +276 -198
- data/Rakefile +7 -4
- data/doc/text/news.md +451 -0
- data/gettext.gemspec +10 -7
- data/lib/gettext/locale_path.rb +17 -9
- data/lib/gettext/mo.rb +12 -19
- data/lib/gettext/po.rb +4 -4
- data/lib/gettext/po_entry.rb +47 -27
- data/lib/gettext/po_parser.rb +65 -59
- data/lib/gettext/text_domain.rb +1 -1
- data/lib/gettext/text_domain_manager.rb +6 -5
- data/lib/gettext/tools/msgcat.rb +9 -2
- data/lib/gettext/tools/msginit.rb +226 -54
- data/lib/gettext/tools/msgmerge.rb +24 -6
- data/lib/gettext/tools/parser/erb.rb +9 -1
- data/lib/gettext/tools/parser/erubi.rb +88 -0
- data/lib/gettext/tools/parser/glade.rb +38 -40
- data/lib/gettext/tools/parser/gtk_builder_ui_definitions.rb +129 -0
- data/lib/gettext/tools/parser/ruby.rb +288 -221
- data/lib/gettext/tools/task.rb +4 -5
- data/lib/gettext/tools/xgettext.rb +21 -10
- data/lib/gettext/version.rb +3 -3
- data/locale/bg/LC_MESSAGES/gettext.mo +0 -0
- data/locale/bs/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ca/LC_MESSAGES/gettext.mo +0 -0
- data/locale/cs/LC_MESSAGES/gettext.mo +0 -0
- data/locale/de/LC_MESSAGES/gettext.mo +0 -0
- data/locale/el/LC_MESSAGES/gettext.mo +0 -0
- data/locale/eo/LC_MESSAGES/gettext.mo +0 -0
- data/locale/es/LC_MESSAGES/gettext.mo +0 -0
- data/locale/et/LC_MESSAGES/gettext.mo +0 -0
- data/locale/fr/LC_MESSAGES/gettext.mo +0 -0
- data/locale/hr/LC_MESSAGES/gettext.mo +0 -0
- data/locale/hu/LC_MESSAGES/gettext.mo +0 -0
- data/locale/it/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ja/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ko/LC_MESSAGES/gettext.mo +0 -0
- data/locale/lv/LC_MESSAGES/gettext.mo +0 -0
- data/locale/nb/LC_MESSAGES/gettext.mo +0 -0
- data/locale/nl/LC_MESSAGES/gettext.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ru/LC_MESSAGES/gettext.mo +0 -0
- data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
- data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
- data/locale/vi/LC_MESSAGES/gettext.mo +0 -0
- data/locale/zh/LC_MESSAGES/gettext.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/gettext.mo +0 -0
- data/po/bg/gettext.edit.po +81 -572
- data/po/bg/gettext.po +7 -409
- data/po/bs/gettext.edit.po +81 -572
- data/po/bs/gettext.po +7 -409
- data/po/ca/gettext.edit.po +81 -572
- data/po/ca/gettext.po +7 -409
- data/po/cs/gettext.edit.po +81 -572
- data/po/cs/gettext.po +7 -409
- data/po/de/gettext.edit.po +81 -572
- data/po/de/gettext.po +7 -409
- data/po/el/gettext.edit.po +81 -572
- data/po/el/gettext.po +7 -409
- data/po/eo/gettext.edit.po +81 -572
- data/po/eo/gettext.po +7 -409
- data/po/es/gettext.edit.po +81 -572
- data/po/es/gettext.po +7 -409
- data/po/et/gettext.edit.po +81 -572
- data/po/et/gettext.po +7 -409
- data/po/fr/gettext.edit.po +81 -572
- data/po/fr/gettext.po +7 -409
- data/po/gettext.pot +93 -645
- data/po/hr/gettext.edit.po +81 -572
- data/po/hr/gettext.po +7 -409
- data/po/hu/gettext.edit.po +81 -572
- data/po/hu/gettext.po +7 -409
- data/po/it/gettext.edit.po +81 -572
- data/po/it/gettext.po +7 -409
- data/po/ja/gettext.edit.po +83 -574
- data/po/ja/gettext.po +9 -411
- data/po/ko/gettext.edit.po +81 -572
- data/po/ko/gettext.po +7 -409
- data/po/lv/gettext.edit.po +81 -572
- data/po/lv/gettext.po +7 -409
- data/po/nb/gettext.edit.po +81 -572
- data/po/nb/gettext.po +7 -409
- data/po/nl/gettext.edit.po +81 -572
- data/po/nl/gettext.po +7 -409
- data/po/pt_BR/gettext.edit.po +81 -572
- data/po/pt_BR/gettext.po +7 -409
- data/po/ru/gettext.edit.po +81 -572
- data/po/ru/gettext.po +7 -409
- data/po/sr/gettext.edit.po +81 -572
- data/po/sr/gettext.po +7 -409
- data/po/sv/gettext.edit.po +81 -572
- data/po/sv/gettext.po +7 -409
- data/po/uk/gettext.edit.po +81 -572
- data/po/uk/gettext.po +7 -409
- data/po/vi/gettext.edit.po +81 -572
- data/po/vi/gettext.po +7 -409
- data/po/zh/gettext.edit.po +81 -572
- data/po/zh/gettext.po +7 -409
- data/po/zh_TW/gettext.edit.po +81 -572
- data/po/zh_TW/gettext.po +7 -409
- data/samples/cgi/po/helloerb1.pot +3 -3
- data/samples/cgi/po/helloerb2.pot +3 -3
- data/samples/cgi/po/hellolib.pot +3 -3
- data/samples/cgi/po/main.pot +3 -3
- data/samples/po/bg/hello_gtk_builder.edit.po +15 -0
- data/samples/po/bg/hello_gtk_builder.po +12 -0
- data/samples/po/bs/hello_gtk_builder.edit.po +15 -0
- data/samples/po/bs/hello_gtk_builder.po +12 -0
- data/samples/po/ca/hello_gtk_builder.edit.po +15 -0
- data/samples/po/ca/hello_gtk_builder.po +12 -0
- data/samples/po/cs/hello_gtk_builder.edit.po +15 -0
- data/samples/po/cs/hello_gtk_builder.po +12 -0
- data/samples/po/de/hello_gtk_builder.edit.po +15 -0
- data/samples/po/de/hello_gtk_builder.po +12 -0
- data/samples/po/el/hello_gtk_builder.edit.po +15 -0
- data/samples/po/el/hello_gtk_builder.po +12 -0
- data/samples/po/eo/hello_gtk_builder.edit.po +15 -0
- data/samples/po/eo/hello_gtk_builder.po +12 -0
- data/samples/po/es/hello_gtk_builder.edit.po +15 -0
- data/samples/po/es/hello_gtk_builder.po +12 -0
- data/samples/po/fr/hello_gtk_builder.edit.po +15 -0
- data/samples/po/fr/hello_gtk_builder.po +12 -0
- data/samples/po/hello.pot +3 -3
- data/samples/po/hello2.pot +4 -4
- data/samples/po/hello_glade2.pot +8 -5
- data/samples/po/hello_gtk2.pot +4 -4
- data/samples/po/hello_gtk_builder.pot +18 -4
- data/samples/po/hello_noop.pot +4 -4
- data/samples/po/hello_plural.pot +4 -4
- data/samples/po/hello_tk.pot +4 -4
- data/samples/po/hr/hello_gtk_builder.edit.po +15 -0
- data/samples/po/hr/hello_gtk_builder.po +12 -0
- data/samples/po/hu/hello_gtk_builder.edit.po +15 -0
- data/samples/po/hu/hello_gtk_builder.po +12 -0
- data/samples/po/it/hello_gtk_builder.edit.po +15 -0
- data/samples/po/it/hello_gtk_builder.po +12 -0
- data/samples/po/ja/hello_gtk_builder.edit.po +15 -0
- data/samples/po/ja/hello_gtk_builder.po +12 -0
- data/samples/po/ko/hello_gtk_builder.edit.po +15 -0
- data/samples/po/ko/hello_gtk_builder.po +12 -0
- data/samples/po/lv/hello_gtk_builder.edit.po +15 -0
- data/samples/po/lv/hello_gtk_builder.po +12 -0
- data/samples/po/nb/hello_gtk_builder.edit.po +15 -0
- data/samples/po/nb/hello_gtk_builder.po +12 -0
- data/samples/po/nl/hello_gtk_builder.edit.po +15 -0
- data/samples/po/nl/hello_gtk_builder.po +12 -0
- data/samples/po/pt_BR/hello_gtk_builder.edit.po +15 -0
- data/samples/po/pt_BR/hello_gtk_builder.po +12 -0
- data/samples/po/ru/hello_gtk_builder.edit.po +15 -0
- data/samples/po/ru/hello_gtk_builder.po +12 -0
- data/samples/po/sr/hello_gtk_builder.edit.po +15 -0
- data/samples/po/sr/hello_gtk_builder.po +12 -0
- data/samples/po/sv/hello_gtk_builder.edit.po +15 -0
- data/samples/po/sv/hello_gtk_builder.po +12 -0
- data/samples/po/uk/hello_gtk_builder.edit.po +15 -0
- data/samples/po/uk/hello_gtk_builder.po +12 -0
- data/samples/po/vi/hello_gtk_builder.edit.po +15 -0
- data/samples/po/vi/hello_gtk_builder.po +12 -0
- data/samples/po/zh/hello_gtk_builder.edit.po +15 -0
- data/samples/po/zh/hello_gtk_builder.po +12 -0
- data/samples/po/zh_TW/hello_gtk_builder.edit.po +15 -0
- data/samples/po/zh_TW/hello_gtk_builder.po +12 -0
- data/src/po_parser.ry +48 -42
- data/test/fixtures/_/backtick.rb +30 -0
- data/test/fixtures/_/block_parameter.rb +2 -2
- data/test/fixtures/_/double_quote_in_double_quote.rb +2 -2
- data/test/fixtures/_/double_quote_in_single_quote.rb +2 -2
- data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +2 -2
- data/test/fixtures/_/middle_new_line.rb +2 -2
- data/test/fixtures/_/multiple_lines_literal.rb +2 -2
- data/test/fixtures/_/multiple_messages_in_same_line.rb +2 -2
- data/test/fixtures/_/multiple_same_messages.rb +2 -2
- data/test/fixtures/_/one_line.rb +2 -2
- data/test/fixtures/_/one_new_line.rb +2 -2
- data/test/fixtures/_/percent_strings.rb +55 -0
- data/test/fixtures/_/pipe.rb +32 -0
- data/test/{gettext-test-utils.rb → fixtures/_/quoted_symbol.rb} +13 -23
- data/test/fixtures/_.rb +10 -1
- data/test/fixtures/erb/case.rhtml +16 -0
- data/test/fixtures/erb/minus.rhtml +12 -0
- data/test/fixtures/erb/non_ascii.rhtml +1 -0
- data/test/fixtures/glade/3.glade +63 -0
- data/test/fixtures/gtk_builder_ui_definitions.ui +68 -0
- data/test/fixtures/multi_text_domain.rb +12 -12
- data/test/fixtures/np_.rb +1 -1
- data/test/fixtures/ns_/custom.rb +2 -2
- data/test/fixtures/ns_.rb +1 -1
- data/test/fixtures/p_.rb +1 -1
- data/test/fixtures/ruby/percent_lower_i.rb +1 -0
- data/test/fixtures/ruby/percent_lower_w.rb +1 -0
- data/test/fixtures/ruby/percent_upper_i.rb +1 -0
- data/test/fixtures/ruby/percent_upper_w.rb +1 -0
- data/test/fixtures/s_/custom.rb +2 -2
- data/test/fixtures/s_.rb +1 -1
- data/test/fixtures/simple.rb +5 -1
- data/test/fixtures/upper_nn_.rb +77 -0
- data/test/helper.rb +99 -0
- data/test/locale/fr/LC_MESSAGES/plural_error.mo +0 -0
- data/test/locale/fr/LC_MESSAGES/test1.mo +0 -0
- data/test/locale/fr_BE/LC_MESSAGES/test1.mo +0 -0
- data/test/locale/fr_BE_Foo/LC_MESSAGES/test1.mo +0 -0
- data/test/locale/ja/LC_MESSAGES/_.mo +0 -0
- data/test/po/_.pot +28 -4
- data/test/po/backslash.pot +6 -4
- data/test/po/fr/plural_error.po +7 -0
- data/test/po/fr/test1.po +7 -0
- data/test/po/fr_BE/test1.po +24 -0
- data/test/po/fr_BE_Foo/test1.po +20 -0
- data/test/po/hello.pot +3 -3
- data/test/po/ja/_.edit.po +27 -3
- data/test/po/ja/_.po +20 -2
- data/test/po/ja/hello.edit.po +0 -1
- data/test/po/non_ascii.pot +4 -4
- data/test/po/np_.pot +8 -5
- data/test/po/ns_.pot +6 -4
- data/test/po/p_.pot +3 -3
- data/test/po/s_.pot +6 -4
- data/test/po/untranslated.pot +4 -4
- data/test/run-test.rb +2 -3
- data/test/test_class_info.rb +8 -9
- data/test/test_gettext.rb +30 -1
- data/test/test_locale_path.rb +12 -4
- data/test/test_parser.rb +113 -25
- data/test/test_po_entry.rb +21 -17
- data/test/test_po_parser.rb +49 -4
- data/test/test_string.rb +9 -5
- data/test/tools/parser/test_glade.rb +91 -0
- data/test/tools/parser/test_gtk_builder_ui_definitions.rb +63 -0
- data/test/tools/parser/test_ruby.rb +76 -39
- data/test/tools/test_msgcat.rb +21 -1
- data/test/tools/test_msginit.rb +82 -3
- data/test/tools/test_msgmerge.rb +81 -6
- data/test/tools/test_xgettext.rb +106 -5
- metadata +82 -34
- data/lib/gettext/tools/parser/haml.rb +0 -61
- /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-
|
|
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
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
163
|
-
include
|
|
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
|
-
|
|
172
|
-
encoding = GetText::
|
|
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
|
-
|
|
250
|
+
path = fixture_path("erb", "ascii.rhtml")
|
|
251
|
+
@ary = GetText::ErubiParser.parse(path)
|
|
179
252
|
|
|
180
|
-
assert_target 'aaa', [
|
|
181
|
-
assert_target "aaa\n", [
|
|
182
|
-
assert_target 'bbb', [
|
|
183
|
-
assert_plural_target "ccc1", "ccc2", [
|
|
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
|
-
|
|
188
|
-
@ary = GetText::
|
|
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(
|
|
277
|
+
assert_target("Hello", ["#{path}:11"])
|
|
278
|
+
assert_target("World", ["#{path}:14"]) # Detected with Erubi
|
|
191
279
|
end
|
|
192
280
|
end
|
|
193
281
|
|
data/test/test_po_entry.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
3
1
|
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
|
|
4
|
-
# Copyright (C) 2012-
|
|
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 "
|
|
254
|
-
|
|
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"
|
data/test/test_po_parser.rb
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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
|
+
""markup" with <escaped strings>" +
|
|
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-
|
|
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
|
|
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
|