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.
- data/.yardopts +1 -0
- data/README.rdoc +28 -23
- data/Rakefile +29 -21
- data/doc/text/news.md +57 -0
- data/gettext.gemspec +1 -1
- data/lib/gettext.rb +13 -29
- data/lib/gettext/cgi.rb +1 -1
- data/lib/gettext/{runtime/class_info.rb → class_info.rb} +1 -1
- data/lib/gettext/{runtime/locale_path.rb → locale_path.rb} +1 -2
- data/lib/gettext/{runtime/mo.rb → mo.rb} +18 -33
- data/lib/gettext/{tools/po.rb → po.rb} +1 -1
- data/lib/gettext/{tools/po_entry.rb → po_entry.rb} +8 -4
- data/lib/gettext/{tools/poparser.rb → po_parser.rb} +41 -44
- data/lib/gettext/{runtime/textdomain.rb → text_domain.rb} +6 -16
- data/lib/gettext/text_domain_group.rb +26 -0
- data/lib/gettext/{runtime/textdomain_manager.rb → text_domain_manager.rb} +40 -40
- data/lib/gettext/tools.rb +1 -182
- data/lib/gettext/tools/msgfmt.rb +1 -1
- data/lib/gettext/tools/msginit.rb +1 -1
- data/lib/gettext/tools/msgmerge.rb +2 -221
- data/lib/gettext/tools/parser/erb.rb +49 -30
- data/lib/gettext/tools/parser/glade.rb +44 -36
- data/lib/gettext/tools/parser/ruby.rb +126 -37
- data/lib/gettext/tools/task.rb +225 -0
- data/lib/gettext/tools/xgettext.rb +25 -28
- data/lib/gettext/version.rb +1 -1
- 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/sv/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/gettext.pot +171 -97
- data/samples/hello.rb +3 -2
- data/samples/hello2.rb +2 -1
- data/samples/hello_gtk2.rb +4 -1
- data/samples/hello_gtk_builder.rb +32 -0
- data/samples/hello_gtk_builder.ui +46 -0
- data/samples/hello_noop.rb +2 -1
- data/samples/hello_plural.rb +2 -1
- data/samples/hello_tk.rb +2 -1
- data/src/{poparser.ry → po_parser.ry} +31 -35
- data/test/fixtures/N_.rb +1 -1
- data/test/fixtures/_/double_quote_in_double_quote.rb +32 -0
- data/test/fixtures/_/double_quote_in_single_quote.rb +32 -0
- data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +36 -0
- data/test/fixtures/_/middle_new_line.rb +32 -0
- data/test/fixtures/_/multiple_lines_literal.rb +35 -0
- data/test/fixtures/_/multiple_messages_in_same_line.rb +32 -0
- data/test/fixtures/_/multiple_same_messages.rb +36 -0
- data/{lib/gettext/runtime/mofile.rb → test/fixtures/_/one_new_line.rb} +12 -6
- data/test/fixtures/{multi_textdomain.rb → multi_text_domain.rb} +1 -1
- data/test/fixtures/non_ascii.rb +1 -1
- data/test/fixtures/simple.rb +1 -1
- data/test/fixtures/untranslated.rb +1 -1
- data/test/gettext-test-utils.rb +1 -24
- data/test/po/ja/_.po +63 -13
- data/test/po/ja/non_ascii.po +2 -3
- data/test/po/ja/untranslated.po +1 -1
- data/test/test_class_info.rb +2 -2
- data/test/test_gettext.rb +11 -11
- data/test/test_mo.rb +2 -2
- data/test/test_parser.rb +93 -96
- data/test/test_po_entry.rb +237 -146
- data/test/test_po_parser.rb +107 -98
- data/test/test_string.rb +1 -1
- data/test/{test_textdomain_bind.rb → test_text_domain_bind.rb} +6 -6
- data/test/{test_textdomain_multi.rb → test_text_domain_multi.rb} +5 -5
- data/test/{test_textdomain_toplevel.rb → test_text_domain_toplevel.rb} +1 -1
- data/test/test_thread.rb +1 -1
- data/test/tools/files/simple_translation.rb +1 -1
- data/test/{parser → tools/parser}/test_ruby.rb +110 -14
- data/test/tools/test_msgmerge.rb +17 -276
- data/test/tools/test_po.rb +1 -1
- data/test/tools/test_xgettext.rb +175 -144
- metadata +59 -33
- data/lib/gettext/core_ext/iconv.rb +0 -110
- data/lib/gettext/core_ext/string.rb +0 -91
- data/lib/gettext/parser/erb.rb +0 -5
- data/lib/gettext/parser/glade.rb +0 -5
- data/lib/gettext/parser/ruby.rb +0 -172
- data/lib/gettext/runtime/textdomain_group.rb +0 -26
- data/lib/gettext/task.rb +0 -203
- data/lib/gettext/utils.rb +0 -39
- data/test/test_po_generation.rb +0 -45
- data/test/tools/test_tools.rb +0 -61
data/test/test_po_parser.rb
CHANGED
|
@@ -18,85 +18,46 @@
|
|
|
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/
|
|
21
|
+
require "gettext/po_parser"
|
|
22
22
|
|
|
23
23
|
class TestPOParser < Test::Unit::TestCase
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
private
|
|
25
|
+
def create_po_file(content)
|
|
26
|
+
po_file = Tempfile.new("hello.po")
|
|
27
|
+
po_file.print(content)
|
|
28
|
+
po_file.close
|
|
29
|
+
po_file
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def parse_po_file(po_file, parsed_entries)
|
|
33
|
+
parser = GetText::POParser.new
|
|
34
|
+
parser.parse_file(po_file.path, parsed_entries)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class TestMsgStr < self
|
|
38
|
+
class TestEmpty < self
|
|
39
|
+
def test_normal
|
|
40
|
+
po_file = create_po_file(<<-EOP)
|
|
26
41
|
msgid "Hello"
|
|
27
42
|
msgstr ""
|
|
28
43
|
EOP
|
|
29
|
-
|
|
44
|
+
messages = parse_po_file(po_file, MO.new)
|
|
30
45
|
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
assert_equal(nil, messages["Hello"])
|
|
47
|
+
end
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
def test_plural
|
|
50
|
+
po_file = create_po_file(<<-EOP)
|
|
36
51
|
msgid "He"
|
|
37
52
|
msgid_plural "They"
|
|
38
53
|
msgstr[0] ""
|
|
39
54
|
msgstr[1] ""
|
|
40
55
|
EOP
|
|
41
|
-
|
|
56
|
+
messages = parse_po_file(po_file, MO.new)
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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)
|
|
58
|
+
assert_true(messages.has_key?("He\000They"))
|
|
59
|
+
assert_equal(nil, messages["He\000They"])
|
|
60
|
+
end
|
|
100
61
|
end
|
|
101
62
|
end
|
|
102
63
|
|
|
@@ -113,16 +74,45 @@ EOP
|
|
|
113
74
|
assert_equal("bonjour", entries["hello"].msgstr)
|
|
114
75
|
end
|
|
115
76
|
|
|
116
|
-
|
|
117
|
-
|
|
77
|
+
class TestReferences < self
|
|
78
|
+
def test_single
|
|
79
|
+
po_file = create_po_file(<<-EOP)
|
|
118
80
|
# This is the comment.
|
|
119
81
|
#: file.rb:10
|
|
120
82
|
msgid "hello"
|
|
121
83
|
msgstr "bonjour"
|
|
122
84
|
EOP
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
85
|
+
entries = parse_po_file(po_file)
|
|
86
|
+
assert_true(entries.has_key?(nil, "hello"))
|
|
87
|
+
assert_equal(["file.rb:10"], entries["hello"].references)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_per_line
|
|
91
|
+
po_file = create_po_file(<<-PO)
|
|
92
|
+
# This is the comment.
|
|
93
|
+
#: file.rb:10
|
|
94
|
+
#: file.rb:20
|
|
95
|
+
msgid "hello"
|
|
96
|
+
msgstr "bonjour"
|
|
97
|
+
PO
|
|
98
|
+
entries = parse_po_file(po_file)
|
|
99
|
+
assert_true(entries.has_key?(nil, "hello"))
|
|
100
|
+
assert_equal(["file.rb:10", "file.rb:20"],
|
|
101
|
+
entries["hello"].references)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_same_line
|
|
105
|
+
po_file = create_po_file(<<-PO)
|
|
106
|
+
# This is the comment.
|
|
107
|
+
#: file.rb:10 file.rb:20
|
|
108
|
+
msgid "hello"
|
|
109
|
+
msgstr "bonjour"
|
|
110
|
+
PO
|
|
111
|
+
entries = parse_po_file(po_file)
|
|
112
|
+
assert_true(entries.has_key?(nil, "hello"))
|
|
113
|
+
assert_equal(["file.rb:10", "file.rb:20"],
|
|
114
|
+
entries["hello"].references)
|
|
115
|
+
end
|
|
126
116
|
end
|
|
127
117
|
|
|
128
118
|
def test_translator_comment
|
|
@@ -245,20 +235,7 @@ EOP
|
|
|
245
235
|
end
|
|
246
236
|
end
|
|
247
237
|
|
|
248
|
-
|
|
249
|
-
def create_po_file(content)
|
|
250
|
-
po_file = Tempfile.new("hello.po")
|
|
251
|
-
po_file.print(content)
|
|
252
|
-
po_file.close
|
|
253
|
-
po_file
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
def parse_po_file(po_file, parsed_entries)
|
|
257
|
-
parser = GetText::POParser.new
|
|
258
|
-
parser.parse_file(po_file.path, parsed_entries)
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
class FuzzyTest < self
|
|
238
|
+
class TestFuzzy < self
|
|
262
239
|
def setup
|
|
263
240
|
@po = <<-EOP
|
|
264
241
|
#, fuzzy
|
|
@@ -270,7 +247,21 @@ EOP
|
|
|
270
247
|
@po_file.close
|
|
271
248
|
end
|
|
272
249
|
|
|
273
|
-
|
|
250
|
+
private
|
|
251
|
+
def parse
|
|
252
|
+
parser = GetText::POParser.new
|
|
253
|
+
class << parser
|
|
254
|
+
def _(message_id)
|
|
255
|
+
message_id
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
messages = MO.new
|
|
259
|
+
yield parser
|
|
260
|
+
parser.parse_file(@po_file.path, messages)
|
|
261
|
+
messages
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
class TestIgnore < self
|
|
274
265
|
def test_report_warning
|
|
275
266
|
mock($stderr).print("Warning: fuzzy message was ignored.\n")
|
|
276
267
|
mock($stderr).print(" #{@po_file.path}: msgid 'Hello'\n")
|
|
@@ -292,7 +283,7 @@ EOP
|
|
|
292
283
|
end
|
|
293
284
|
end
|
|
294
285
|
|
|
295
|
-
class
|
|
286
|
+
class TestNotIgnore < self
|
|
296
287
|
def test_report_warning
|
|
297
288
|
mock($stderr).print("Warning: fuzzy message was used.\n")
|
|
298
289
|
mock($stderr).print(" #{@po_file.path}: msgid 'Hello'\n")
|
|
@@ -313,19 +304,37 @@ EOP
|
|
|
313
304
|
assert_equal("Bonjour", messages["Hello"])
|
|
314
305
|
end
|
|
315
306
|
end
|
|
307
|
+
end
|
|
316
308
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
309
|
+
class TestHeader < self
|
|
310
|
+
class TestEncoding < self
|
|
311
|
+
def test_known
|
|
312
|
+
assert_equal(Encoding::EUC_JP, detect_encoding("EUC-JP"))
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def test_unknown
|
|
316
|
+
assert_equal(Encoding.default_external, detect_encoding("CHARSET"))
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def test_fuzzy
|
|
320
|
+
assert_equal(Encoding::EUC_JP,
|
|
321
|
+
detect_encoding("EUC-JP", :fuzzy => true))
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
private
|
|
325
|
+
def detect_encoding(encoding, options={})
|
|
326
|
+
comments = []
|
|
327
|
+
comments << "#, fuzzy" if options[:fuzzy]
|
|
328
|
+
po_file = create_po_file(<<-PO)
|
|
329
|
+
#{comments.join("\n")}
|
|
330
|
+
msgid ""
|
|
331
|
+
msgstr ""
|
|
332
|
+
"Content-Type: text/plain; charset=#{encoding}\\n"
|
|
333
|
+
PO
|
|
334
|
+
|
|
335
|
+
parser = GetText::POParser.new
|
|
336
|
+
parser.send(:detect_file_encoding, po_file.path)
|
|
324
337
|
end
|
|
325
|
-
messages = MO.new
|
|
326
|
-
yield parser
|
|
327
|
-
parser.parse_file(@po_file.path, messages)
|
|
328
|
-
messages
|
|
329
338
|
end
|
|
330
339
|
end
|
|
331
340
|
end
|
data/test/test_string.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
class Foo
|
|
4
4
|
end
|
|
@@ -6,18 +6,18 @@ end
|
|
|
6
6
|
class TestGetTextBind < Test::Unit::TestCase
|
|
7
7
|
def setup
|
|
8
8
|
GetText.locale = "ja_JP.EUC-JP"
|
|
9
|
-
@
|
|
10
|
-
GetText::TextDomainManager.
|
|
9
|
+
@dumped_all_text_domains = GetText::TextDomainManager.dump_all_text_domains
|
|
10
|
+
GetText::TextDomainManager.clear_all_text_domains
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def teardown
|
|
14
|
-
GetText::TextDomainManager.
|
|
14
|
+
GetText::TextDomainManager.restore_all_text_domains(@dumped_all_text_domains)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def test_bindtextdomain
|
|
18
18
|
domain = GetText.bindtextdomain("foo")
|
|
19
|
-
assert_equal domain, GetText::TextDomainManager.
|
|
20
|
-
assert_equal domain, GetText::TextDomainManager.
|
|
19
|
+
assert_equal domain, GetText::TextDomainManager.create_or_find_text_domain_group(Object).text_domains[0]
|
|
20
|
+
assert_equal domain, GetText::TextDomainManager.text_domain_pool("foo")
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def test_textdomain
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
|
-
require 'fixtures/
|
|
3
|
+
require 'fixtures/multi_text_domain'
|
|
4
4
|
|
|
5
5
|
class TestGetTextMulti < Test::Unit::TestCase
|
|
6
6
|
include MultiTextDomain
|
|
@@ -24,7 +24,7 @@ class TestGetTextMulti < Test::Unit::TestCase
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def test_inheritance
|
|
27
|
-
# inheritance. only parent has a
|
|
27
|
+
# inheritance. only parent has a text domain and it's methods
|
|
28
28
|
test = C21.new
|
|
29
29
|
assert_equal("japanese", test.test) # Use C11's po(test1.po)
|
|
30
30
|
assert_equal("JAPANESE", test.test2) # Use C11's po(test2.po)
|
|
@@ -38,7 +38,7 @@ class TestGetTextMulti < Test::Unit::TestCase
|
|
|
38
38
|
# module
|
|
39
39
|
assert_equal("japanese", M1.test)
|
|
40
40
|
|
|
41
|
-
# sub-module. only an included module has a
|
|
41
|
+
# sub-module. only an included module has a text domain and it's methods
|
|
42
42
|
assert_equal("japanese", M1::M1M1.test) # Same method with M1.
|
|
43
43
|
assert_equal("LANGUAGE", M1::M1M1.test2) # No influence from ancestors.
|
|
44
44
|
|
|
@@ -72,7 +72,7 @@ class TestGetTextMulti < Test::Unit::TestCase
|
|
|
72
72
|
assert_equal("no data", test.test3) # No po file.
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
def
|
|
75
|
+
def test_same_msgid_but_different_text_domain
|
|
76
76
|
test1 = C12.new # test1 domain
|
|
77
77
|
test2 = C51.new # test3 domain
|
|
78
78
|
test3 = C52.new # test3 domain but inherited C11.
|
data/test/test_thread.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 Kouhei Sutou <kou@clear-code.com>
|
|
4
|
+
# Copyright (C) 2012-2013 Kouhei Sutou <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
|
|
@@ -43,7 +43,7 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
43
43
|
:msgid_plural => nil,
|
|
44
44
|
:msgstr => nil,
|
|
45
45
|
:separator => nil,
|
|
46
|
-
:references
|
|
46
|
+
:references => nil,
|
|
47
47
|
}
|
|
48
48
|
default.merge(message)
|
|
49
49
|
end
|
|
@@ -56,7 +56,7 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
56
56
|
:msgid_plural => po_entry.msgid_plural,
|
|
57
57
|
:msgstr => po_entry.msgstr,
|
|
58
58
|
:separator => po_entry.separator,
|
|
59
|
-
:references
|
|
59
|
+
:references => normalize_references(po_entry.references),
|
|
60
60
|
}
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -68,8 +68,6 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
class TestDetectEncoding < self
|
|
71
|
-
setup :need_encoding
|
|
72
|
-
|
|
73
71
|
def test_ascii_and_hyphen
|
|
74
72
|
assert_equal("euc-jp", detect_encoding("# coding: euc-jp"))
|
|
75
73
|
end
|
|
@@ -96,7 +94,8 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
96
94
|
|
|
97
95
|
private
|
|
98
96
|
def detect_encoding(content)
|
|
99
|
-
GetText::RubyParser.
|
|
97
|
+
parser = GetText::RubyParser.new("/tmp/source.rb")
|
|
98
|
+
parser.detect_encoding(content)
|
|
100
99
|
end
|
|
101
100
|
|
|
102
101
|
class NewLineStyle < self
|
|
@@ -114,7 +113,7 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
114
113
|
end
|
|
115
114
|
end
|
|
116
115
|
|
|
117
|
-
|
|
116
|
+
sub_test_case("_") do
|
|
118
117
|
def test_one_line
|
|
119
118
|
assert_parse([
|
|
120
119
|
{
|
|
@@ -125,20 +124,117 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
125
124
|
"one_line.rb")
|
|
126
125
|
end
|
|
127
126
|
|
|
127
|
+
def test_one_new_line
|
|
128
|
+
path = "one_new_line.rb"
|
|
129
|
+
assert_parse([
|
|
130
|
+
{
|
|
131
|
+
:msgid => "one new line\n",
|
|
132
|
+
:references => ["#{path}:28"],
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
path)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_middle_new_line
|
|
139
|
+
path = "middle_new_line.rb"
|
|
140
|
+
assert_parse([
|
|
141
|
+
{
|
|
142
|
+
:msgid => "middle\nnew line",
|
|
143
|
+
:references => ["#{path}:28"],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
path)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def test_multiple_lines_literal
|
|
150
|
+
path = "multiple_lines_literal.rb"
|
|
151
|
+
assert_parse([
|
|
152
|
+
{
|
|
153
|
+
:msgid => "multiple\nlines\nliteral\n",
|
|
154
|
+
:references => ["#{path}:28"],
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
path)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_multiple_same_messages
|
|
161
|
+
path = "multiple_same_messages.rb"
|
|
162
|
+
assert_parse([
|
|
163
|
+
{
|
|
164
|
+
:msgid => "multiple same messages",
|
|
165
|
+
:references => ["#{path}:28"],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
:msgid => "multiple same messages",
|
|
169
|
+
:references => ["#{path}:32"],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
path)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_multiple_messages_in_same_line
|
|
176
|
+
path = "multiple_messages_in_same_line.rb"
|
|
177
|
+
assert_parse([
|
|
178
|
+
{
|
|
179
|
+
:msgid => "multiple",
|
|
180
|
+
:references => ["#{path}:28"],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
:msgid => "in same line",
|
|
184
|
+
:references => ["#{path}:28"],
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
path)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def test_literal_concatenation_with_continuation_line
|
|
191
|
+
path = "literal_concatenation_with_continuation_line.rb"
|
|
192
|
+
msgid = "literal concatenation with continuation line"
|
|
193
|
+
assert_parse([
|
|
194
|
+
{
|
|
195
|
+
:msgid => msgid,
|
|
196
|
+
:references => ["#{path}:28"],
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
path)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def test_double_quote_in_single_quote
|
|
203
|
+
path = "double_quote_in_single_quote.rb"
|
|
204
|
+
assert_parse([
|
|
205
|
+
{
|
|
206
|
+
:msgid => "double \"quote\" in single quote",
|
|
207
|
+
:references => ["#{path}:28"],
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
path)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def test_double_quote_in_double_quote
|
|
214
|
+
path = "double_quote_in_double_quote.rb"
|
|
215
|
+
assert_parse([
|
|
216
|
+
{
|
|
217
|
+
:msgid => "double \"quote\" in double quote",
|
|
218
|
+
:references => ["#{path}:28"],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
path)
|
|
222
|
+
end
|
|
223
|
+
|
|
128
224
|
private
|
|
129
225
|
def fixture_path(*components)
|
|
130
226
|
super("_", *components)
|
|
131
227
|
end
|
|
132
228
|
end
|
|
133
229
|
|
|
134
|
-
|
|
230
|
+
sub_test_case("s_") do
|
|
135
231
|
def test_custom
|
|
136
232
|
assert_parse([
|
|
137
233
|
{
|
|
138
|
-
:msgid
|
|
139
|
-
:msgstr
|
|
140
|
-
:separator
|
|
141
|
-
:references
|
|
234
|
+
:msgid => "context|context$message",
|
|
235
|
+
:msgstr => nil,
|
|
236
|
+
:separator => "$",
|
|
237
|
+
:references => ["custom.rb:28"],
|
|
142
238
|
}
|
|
143
239
|
],
|
|
144
240
|
"custom.rb")
|
|
@@ -150,7 +246,7 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
150
246
|
end
|
|
151
247
|
end
|
|
152
248
|
|
|
153
|
-
|
|
249
|
+
sub_test_case("ns_") do
|
|
154
250
|
def test_custom
|
|
155
251
|
assert_parse([
|
|
156
252
|
{
|
|
@@ -158,7 +254,7 @@ class TestRubyParser < Test::Unit::TestCase
|
|
|
158
254
|
:msgid_plural => "context|context$messages",
|
|
159
255
|
:msgstr => nil,
|
|
160
256
|
:separator => "$",
|
|
161
|
-
:references
|
|
257
|
+
:references => ["custom.rb:28"],
|
|
162
258
|
}
|
|
163
259
|
],
|
|
164
260
|
"custom.rb")
|