gettext 2.0.4 → 2.1.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/COPYING +9 -8
- data/ChangeLog +21 -0
- data/README.rdoc +7 -13
- data/Rakefile +7 -5
- data/benchmark/1.93.0.txt +8 -0
- data/benchmark/2.0.0.txt +8 -0
- data/benchmark/2.0.4.txt +11 -0
- data/benchmark/2.1.0.txt +11 -0
- data/benchmark/benchmark.rb +68 -0
- data/benchmark/test.rb +28 -0
- data/bin/rgettext +1 -2
- data/bin/rmsgfmt +1 -3
- data/bin/rmsgmerge +0 -2
- data/data/locale/bg/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/bs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/et/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/hr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/hu/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/lv/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nb/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ua/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/vi/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
- data/lib/gettext.rb +4 -6
- data/lib/gettext/cgi.rb +1 -3
- data/lib/gettext/core_ext/iconv.rb +2 -4
- data/lib/gettext/core_ext/string.rb +3 -3
- data/lib/gettext/parser/erb.rb +2 -53
- data/lib/gettext/parser/glade.rb +2 -99
- data/lib/gettext/parser/ruby.rb +7 -5
- data/lib/gettext/{class_info.rb → runtime/class_info.rb} +2 -1
- data/lib/gettext/{locale_path.rb → runtime/locale_path.rb} +1 -2
- data/lib/gettext/{mofile.rb → runtime/mofile.rb} +0 -0
- data/lib/gettext/{textdomain.rb → runtime/textdomain.rb} +3 -5
- data/lib/gettext/{textdomain_group.rb → runtime/textdomain_group.rb} +1 -1
- data/lib/gettext/{textdomain_manager.rb → runtime/textdomain_manager.rb} +11 -5
- data/lib/gettext/tools.rb +2 -2
- data/lib/gettext/tools/parser/erb.rb +52 -0
- data/lib/gettext/tools/parser/glade.rb +98 -0
- data/lib/gettext/tools/parser/ruby.rb +226 -0
- data/lib/gettext/tools/pomessage.rb +197 -0
- data/lib/gettext/{poparser.rb → tools/poparser.rb} +128 -122
- data/lib/gettext/tools/rgettext.rb +47 -92
- data/lib/gettext/tools/rmsgfmt.rb +2 -2
- data/lib/gettext/tools/rmsgmerge.rb +2 -2
- data/lib/gettext/utils.rb +1 -1
- data/lib/gettext/version.rb +2 -2
- data/po/bg/rgettext.po +68 -64
- data/po/bs/rgettext.po +69 -65
- data/po/ca/rgettext.po +67 -64
- data/po/cs/rgettext.po +73 -70
- data/po/de/rgettext.po +69 -65
- data/po/el/rgettext.po +67 -64
- data/po/eo/rgettext.po +67 -63
- data/po/es/rgettext.po +67 -63
- data/po/et/rgettext.po +66 -63
- data/po/fr/rgettext.po +69 -66
- data/po/hr/rgettext.po +77 -73
- data/po/hu/rgettext.po +68 -65
- data/po/it/rgettext.po +69 -65
- data/po/ja/rgettext.po +69 -65
- data/po/ko/rgettext.po +73 -70
- data/po/lv/rgettext.po +68 -65
- data/po/nb/rgettext.po +68 -65
- data/po/nl/rgettext.po +74 -70
- data/po/pt_BR/rgettext.po +69 -66
- data/po/rgettext.pot +52 -48
- data/po/ru/rgettext.po +69 -66
- data/po/sr/rgettext.po +68 -64
- data/po/sv/rgettext.po +59 -55
- data/po/ua/rgettext.po +69 -66
- data/po/vi/rgettext.po +67 -63
- data/po/zh/rgettext.po +65 -62
- data/po/zh_TW/rgettext.po +65 -62
- data/replace.rb +8 -0
- data/samples/cgi/hellolib.rb +1 -3
- data/samples/cgi/http.rb +2 -4
- data/samples/cgi/locale/bg/LC_MESSAGES/main.mo +0 -0
- data/samples/cgi/po/bg/#main.po# +84 -0
- data/samples/cgi/po/bg/main.po +1 -1
- data/samples/hello.rb +1 -1
- data/src/poparser.ry +2 -1
- data/test.rb +33 -0
- data/test/test_class_info.rb +1 -1
- data/test/test_gettext.rb +1 -0
- data/test/test_parser.rb +120 -75
- data/test/test_po_generation.rb +20 -0
- data/test/test_pomessage.rb +99 -0
- data/test/test_string.rb +8 -0
- data/test/testlib/gettext.rb +17 -0
- data/test/testlib/ngettext.rb +6 -1
- data/test/testlib/pgettext.rb +5 -0
- metadata +726 -985
data/samples/cgi/po/bg/main.po
CHANGED
|
@@ -32,7 +32,7 @@ msgstr ""
|
|
|
32
32
|
|
|
33
33
|
#: index.cgi:38
|
|
34
34
|
msgid "an ERB/CGI sample (Auto-Detect charset)."
|
|
35
|
-
msgstr "ERB/CGI пример (автоматично разпознаване на кодирането)."
|
|
35
|
+
msgstr "ERB/CGI пример (автоматично разпознаване на кодирането)."
|
|
36
36
|
|
|
37
37
|
#: index.cgi:50 cookie.cgi:44
|
|
38
38
|
msgid "Sample script for CGI/ERB and Ruby-GetText-Package"
|
data/samples/hello.rb
CHANGED
data/src/poparser.ry
CHANGED
|
@@ -36,7 +36,7 @@ class GetText::PoParser
|
|
|
36
36
|
if @fuzzy and $ignore_fuzzy
|
|
37
37
|
if val[1] != ""
|
|
38
38
|
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
39
|
-
$stderr.print "
|
|
39
|
+
$stderr.print " #{@po_file}: msgid '#{val[1]}'\n"
|
|
40
40
|
else
|
|
41
41
|
on_message('', unescape(val[3]))
|
|
42
42
|
end
|
|
@@ -201,6 +201,7 @@ end
|
|
|
201
201
|
encoding = detect_file_encoding(po_file)
|
|
202
202
|
args << "r:#{encoding}"
|
|
203
203
|
end
|
|
204
|
+
@po_file = po_file
|
|
204
205
|
parse(File.open(*args) {|io| io.read }, data, ignore_fuzzy)
|
|
205
206
|
end
|
|
206
207
|
|
data/test.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
## hello_gtk2.rb - sample for Ruby/GTK2
|
|
3
|
+
##
|
|
4
|
+
## Copyright (C) 2001-2006 Masao Mutoh
|
|
5
|
+
## This file is distributed under the same license as Ruby-GetText-Package.
|
|
6
|
+
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
require 'gettext'
|
|
9
|
+
require 'gtk2'
|
|
10
|
+
|
|
11
|
+
class LocalizedWindow < Gtk::Window
|
|
12
|
+
include GetText
|
|
13
|
+
|
|
14
|
+
bindtextdomain("hello_gtk", :path => "locale", :output_charset => "utf-8")
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
super
|
|
18
|
+
signal_connect('delete-event') do
|
|
19
|
+
Gtk.main_quit
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
add(Gtk::Label.new( "sdaf" )
|
|
23
|
+
np_("Special", "An apple", "%{num} Apples", num)
|
|
24
|
+
p_("File", "New")
|
|
25
|
+
s_("File|New")
|
|
26
|
+
n_("Special|An apple", "%{num} Apples", num)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
LocalizedWindow.new.show_all
|
|
31
|
+
Gtk.main
|
|
32
|
+
|
|
33
|
+
|
data/test/test_class_info.rb
CHANGED
data/test/test_gettext.rb
CHANGED
data/test/test_parser.rb
CHANGED
|
@@ -1,75 +1,89 @@
|
|
|
1
1
|
require 'testlib/helper.rb'
|
|
2
|
-
require 'gettext/parser/ruby'
|
|
3
|
-
require 'gettext/parser/glade'
|
|
4
|
-
require 'gettext/parser/erb'
|
|
2
|
+
require 'gettext/tools/parser/ruby'
|
|
3
|
+
require 'gettext/tools/parser/glade'
|
|
4
|
+
require 'gettext/tools/parser/erb'
|
|
5
5
|
|
|
6
6
|
require 'gettext/tools/rgettext'
|
|
7
7
|
|
|
8
8
|
class TestGetTextParser < Test::Unit::TestCase
|
|
9
9
|
def test_ruby
|
|
10
|
-
ary = GetText::
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
@ary = GetText::RGetText.parse('testlib/gettext.rb')
|
|
11
|
+
|
|
12
|
+
assert_target 'aaa', ['testlib/gettext.rb:8']
|
|
13
|
+
assert_target 'aaa\n', ['testlib/gettext.rb:12']
|
|
14
|
+
assert_target 'bbb\nccc', ['testlib/gettext.rb:16']
|
|
15
|
+
assert_target 'bbb\nccc\nddd\n', ['testlib/gettext.rb:20']
|
|
16
|
+
assert_target 'eee', ['testlib/gettext.rb:27', 'testlib/gettext.rb:31']
|
|
17
|
+
assert_target 'fff', ['testlib/gettext.rb:31']
|
|
18
|
+
assert_target 'ggghhhiii', ['testlib/gettext.rb:35']
|
|
19
|
+
assert_target 'a"b"c"', ['testlib/gettext.rb:41']
|
|
20
|
+
assert_target 'd"e"f"', ['testlib/gettext.rb:45']
|
|
21
|
+
assert_target 'jjj', ['testlib/gettext.rb:49']
|
|
22
|
+
assert_target 'kkk', ['testlib/gettext.rb:50']
|
|
23
|
+
assert_target 'lllmmm', ['testlib/gettext.rb:54']
|
|
24
|
+
assert_target 'nnn\nooo', ['testlib/gettext.rb:62']
|
|
25
|
+
assert_target "\#", ['testlib/gettext.rb:66', 'testlib/gettext.rb:70']
|
|
26
|
+
assert_target "\\taaa", ['testlib/gettext.rb:74']
|
|
27
|
+
assert_target "Here document1\\nHere document2\\n", ['testlib/gettext.rb:78']
|
|
28
|
+
assert_target "Francois Pinard", ['testlib/gettext.rb:97'] do |t|
|
|
29
|
+
assert_match /proper name/, t.comment
|
|
30
|
+
assert_match /Pronunciation/, t.comment
|
|
31
|
+
end
|
|
32
|
+
assert_target "self explaining", ['testlib/gettext.rb:102'] do |t|
|
|
33
|
+
assert_nil t.comment
|
|
34
|
+
end
|
|
35
|
+
# TODO: assert_target "in_quote", ['testlib/gettext.rb:96']
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
def test_ruby_N
|
|
32
|
-
ary = GetText::
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
@ary = GetText::RGetText.parse('testlib/N_.rb')
|
|
40
|
+
|
|
41
|
+
assert_target 'aaa', ['testlib/N_.rb:8']
|
|
42
|
+
assert_target 'aaa\n', ['testlib/N_.rb:12']
|
|
43
|
+
assert_target 'bbb\nccc', ['testlib/N_.rb:16']
|
|
44
|
+
assert_target 'bbb\nccc\nddd\n', ['testlib/N_.rb:20']
|
|
45
|
+
assert_target 'eee', ['testlib/N_.rb:27', 'testlib/N_.rb:31']
|
|
46
|
+
assert_target 'fff', ['testlib/N_.rb:31']
|
|
47
|
+
assert_target 'ggghhhiii', ['testlib/N_.rb:35']
|
|
48
|
+
assert_target 'a"b"c"', ['testlib/N_.rb:41']
|
|
49
|
+
assert_target 'd"e"f"', ['testlib/N_.rb:45']
|
|
50
|
+
assert_target 'jjj', ['testlib/N_.rb:49']
|
|
51
|
+
assert_target 'kkk', ['testlib/N_.rb:50']
|
|
52
|
+
assert_target 'lllmmm', ['testlib/N_.rb:54']
|
|
53
|
+
assert_target 'nnn\nooo', ['testlib/N_.rb:62']
|
|
47
54
|
end
|
|
48
55
|
|
|
49
56
|
def test_ruby_n
|
|
50
|
-
ary = GetText::
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
@ary = GetText::RGetText.parse('testlib/ngettext.rb')
|
|
58
|
+
assert_plural_target "aaa", "aaa2", ['testlib/ngettext.rb:8']
|
|
59
|
+
assert_plural_target "bbb\\n", "ccc2\\nccc2", ['testlib/ngettext.rb:12']
|
|
60
|
+
assert_plural_target "ddd\\nddd", "ddd2\\nddd2", ['testlib/ngettext.rb:16']
|
|
61
|
+
assert_plural_target "eee\\neee\\n", "eee2\\neee2\\n", ['testlib/ngettext.rb:21']
|
|
62
|
+
assert_plural_target "ddd\\neee\\n", "ddd\\neee2", ['testlib/ngettext.rb:27']
|
|
63
|
+
assert_plural_target "fff", "fff2", ['testlib/ngettext.rb:34', 'testlib/ngettext.rb:38']
|
|
64
|
+
assert_plural_target "ggg", "ggg2", ['testlib/ngettext.rb:38']
|
|
65
|
+
assert_plural_target "ggghhhiii", "jjjkkklll", ['testlib/ngettext.rb:42']
|
|
66
|
+
assert_plural_target "a\"b\"c\"", "a\"b\"c\"2", ['testlib/ngettext.rb:51']
|
|
67
|
+
assert_plural_target "mmmmmm", "mmm2mmm2", ['testlib/ngettext.rb:59']
|
|
68
|
+
assert_plural_target "nnn", "nnn2", ['testlib/ngettext.rb:60']
|
|
69
|
+
assert_plural_target "comment", "comments", ['testlib/ngettext.rb:76'] do |t|
|
|
70
|
+
assert_equal "please provide translations for all \n the plural forms!", t.comment
|
|
71
|
+
end
|
|
62
72
|
end
|
|
63
73
|
|
|
64
74
|
def test_ruby_p
|
|
65
|
-
ary = GetText::
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
@ary = GetText::RGetText.parse('testlib/pgettext.rb')
|
|
76
|
+
assert_target_in_context "AAA", "BBB", ["testlib/pgettext.rb:8", "testlib/pgettext.rb:12"]
|
|
77
|
+
assert_target_in_context "AAA|BBB", "CCC", ["testlib/pgettext.rb:16"]
|
|
78
|
+
assert_target_in_context "AAA", "CCC", ["testlib/pgettext.rb:20"]
|
|
79
|
+
assert_target_in_context "CCC", "BBB", ["testlib/pgettext.rb:24"]
|
|
80
|
+
assert_target_in_context "program", "name", ['testlib/pgettext.rb:34'] do |t|
|
|
81
|
+
assert_equal "please translate 'name' in the context of 'program'.\n Hint: the translation should NOT contain the translation of 'program'.", t.comment
|
|
82
|
+
end
|
|
70
83
|
end
|
|
71
84
|
|
|
72
85
|
def test_glade
|
|
86
|
+
# Old style (~2.0.4)
|
|
73
87
|
ary = GetText::GladeParser.parse('testlib/gladeparser.glade')
|
|
74
88
|
|
|
75
89
|
assert_equal(['window1', 'testlib/gladeparser.glade:8'], ary[0])
|
|
@@ -82,32 +96,63 @@ class TestGetTextParser < Test::Unit::TestCase
|
|
|
82
96
|
end
|
|
83
97
|
|
|
84
98
|
def testlib_erb
|
|
85
|
-
ary = GetText::ErbParser.parse('testlib/erb.rhtml')
|
|
99
|
+
@ary = GetText::ErbParser.parse('testlib/erb.rhtml')
|
|
86
100
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
assert_target 'aaa', ['testlib/erb.rhtml:8']
|
|
102
|
+
assert_target 'aaa\n', ['testlib/erb.rhtml:11']
|
|
103
|
+
assert_target 'bbb', ['testlib/erb.rhtml:12']
|
|
104
|
+
assert_plural_target "ccc1", "ccc2", ['testlib/erb.rhtml:13']
|
|
91
105
|
end
|
|
92
106
|
|
|
93
107
|
def test_rgettext_parse
|
|
94
108
|
GetText::ErbParser.init(:extnames => ['.rhtml', '.rxml'])
|
|
95
|
-
ary = GetText::RGetText.parse(['testlib/erb.rhtml'])
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
ary = GetText::RGetText.parse(['testlib/erb.rxml'])
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
@ary = GetText::RGetText.parse(['testlib/erb.rhtml'])
|
|
110
|
+
assert_target 'aaa', ['testlib/erb.rhtml:8']
|
|
111
|
+
assert_target 'aaa\n', ['testlib/erb.rhtml:11']
|
|
112
|
+
assert_target 'bbb', ['testlib/erb.rhtml:12']
|
|
113
|
+
assert_plural_target "ccc1", "ccc2", ['testlib/erb.rhtml:13']
|
|
114
|
+
|
|
115
|
+
@ary = GetText::RGetText.parse(['testlib/erb.rxml'])
|
|
116
|
+
assert_target 'aaa', ['testlib/erb.rxml:9']
|
|
117
|
+
assert_target 'aaa\n', ['testlib/erb.rxml:12']
|
|
118
|
+
assert_target 'bbb', ['testlib/erb.rxml:13']
|
|
119
|
+
assert_plural_target "ccc1", "ccc2", ['testlib/erb.rxml:14']
|
|
120
|
+
|
|
121
|
+
@ary = GetText::RGetText.parse(['testlib/ngettext.rb'])
|
|
122
|
+
assert_plural_target "ooo", "ppp", ['testlib/ngettext.rb:64', 'testlib/ngettext.rb:65']
|
|
123
|
+
assert_plural_target "qqq", "rrr", ['testlib/ngettext.rb:69', 'testlib/ngettext.rb:70']
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
private
|
|
127
|
+
|
|
128
|
+
def assert_target(msgid, sources = nil)
|
|
129
|
+
t = @ary.detect {|elem| elem.msgid == msgid}
|
|
130
|
+
if t
|
|
131
|
+
if sources
|
|
132
|
+
assert_equal sources.sort, t.sources.sort, 'Translation target sources do not match.'
|
|
133
|
+
end
|
|
134
|
+
yield t if block_given?
|
|
135
|
+
else
|
|
136
|
+
flunk "Expected a translation target with id '#{msgid}'. Not found."
|
|
137
|
+
end
|
|
111
138
|
end
|
|
112
139
|
|
|
140
|
+
def assert_plural_target(msgid, plural, sources = nil)
|
|
141
|
+
assert_target msgid, sources do |t|
|
|
142
|
+
assert_equal plural, t.msgid_plural, 'Expected plural form'
|
|
143
|
+
yield t if block_given?
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def assert_target_in_context(msgctxt, msgid, sources = nil)
|
|
148
|
+
t = @ary.detect {|elem| elem.msgid == msgid && elem.msgctxt == msgctxt}
|
|
149
|
+
if t
|
|
150
|
+
if sources
|
|
151
|
+
assert_equal sources.sort, t.sources.sort, 'Translation target sources do not match.'
|
|
152
|
+
end
|
|
153
|
+
yield t if block_given?
|
|
154
|
+
else
|
|
155
|
+
flunk "Expected a translation target with id '#{msgid}' and context '#{msgctxt}'. Not found."
|
|
156
|
+
end
|
|
157
|
+
end
|
|
113
158
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'testlib/helper.rb'
|
|
2
|
+
require 'gettext'
|
|
3
|
+
require 'gettext/tools/rgettext.rb'
|
|
4
|
+
require 'stringio'
|
|
5
|
+
|
|
6
|
+
class TestPoGeneration < Test::Unit::TestCase
|
|
7
|
+
def test_extracted_comments
|
|
8
|
+
GetText::RGetText.run(
|
|
9
|
+
File.join(File.dirname(__FILE__), 'testlib/gettext.rb'),
|
|
10
|
+
out = StringIO.new)
|
|
11
|
+
res = out.string
|
|
12
|
+
|
|
13
|
+
# Use following to debug the content of the
|
|
14
|
+
# created file: File.open('/tmp/test.po', 'w').write(res)
|
|
15
|
+
|
|
16
|
+
assert_match '#. "Fran\u00e7ois" or (with HTML entities) "François".', res
|
|
17
|
+
assert_no_match /Ignored/, res, 'Only comments starting with TRANSLATORS should be extracted'
|
|
18
|
+
assert_no_match /TRANSLATORS: This is a proper name/, res, 'The prefix "TRANSLATORS:" should be skipped'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require 'testlib/helper.rb'
|
|
2
|
+
require 'gettext/tools/parser/ruby'
|
|
3
|
+
|
|
4
|
+
# Most functionality of PoMessage is thoroughly tested together
|
|
5
|
+
# with the parser and po file generator. Here only tests for some special
|
|
6
|
+
# functionality.
|
|
7
|
+
class TestPoMessage < Test::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
def test_context_match
|
|
10
|
+
tt1 = GetText::PoMessage.new(:msgctxt)
|
|
11
|
+
tt1.msgid = 'hello'
|
|
12
|
+
tt1.msgctxt = 'world'
|
|
13
|
+
tt2 = GetText::PoMessage.new(:normal)
|
|
14
|
+
tt2.msgid = 'hello'
|
|
15
|
+
assert_raise GetText::ParseError do
|
|
16
|
+
tt1.merge tt2
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_attribute_accumulation
|
|
21
|
+
tt = GetText::PoMessage.new(:plural)
|
|
22
|
+
tt.set_current_attribute 'long'
|
|
23
|
+
tt.set_current_attribute ' tail'
|
|
24
|
+
tt.advance_to_next_attribute
|
|
25
|
+
tt.set_current_attribute 'long tails'
|
|
26
|
+
assert_equal 'long tail', tt.msgid
|
|
27
|
+
assert_equal 'long tails', tt.msgid_plural
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_to_po_str_normal
|
|
31
|
+
po = GetText::PoMessage.new(:normal)
|
|
32
|
+
po.msgid = 'hello'
|
|
33
|
+
po.sources = ["file1:1", "file2:10"]
|
|
34
|
+
assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_po_str
|
|
35
|
+
|
|
36
|
+
po.msgctxt = 'context'
|
|
37
|
+
po.msgid_plural = 'hello2'
|
|
38
|
+
# Ignore these properties.
|
|
39
|
+
assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_po_str
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_to_po_str_plural
|
|
43
|
+
po = GetText::PoMessage.new(:plural)
|
|
44
|
+
po.msgid = 'hello'
|
|
45
|
+
po.msgid_plural = 'hello2'
|
|
46
|
+
po.sources = ["file1:1", "file2:10"]
|
|
47
|
+
assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_po_str
|
|
48
|
+
|
|
49
|
+
po.msgctxt = 'context'
|
|
50
|
+
# Ignore this property
|
|
51
|
+
assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_po_str
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_to_po_str_msgctxt
|
|
55
|
+
po = GetText::PoMessage.new(:msgctxt)
|
|
56
|
+
po.msgctxt = 'context'
|
|
57
|
+
po.msgid = 'hello'
|
|
58
|
+
po.sources = ["file1:1", "file2:10"]
|
|
59
|
+
assert_equal "\n#: file1:1 file2:10\nmsgctxt \"context\"\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_po_str
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_to_po_str_msgctxt_plural
|
|
63
|
+
po = GetText::PoMessage.new(:msgctxt_plural)
|
|
64
|
+
po.msgctxt = 'context'
|
|
65
|
+
po.msgid = 'hello'
|
|
66
|
+
po.msgid_plural = 'hello2'
|
|
67
|
+
po.sources = ["file1:1", "file2:10"]
|
|
68
|
+
assert_equal "\n#: file1:1 file2:10\nmsgctxt \"context\"\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_po_str
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_to_po_str_exception
|
|
72
|
+
po = GetText::PoMessage.new(:normal)
|
|
73
|
+
po.sources = ["file1:1", "file2:10"]
|
|
74
|
+
assert_raise(RuntimeError){ po.to_po_str }
|
|
75
|
+
|
|
76
|
+
po.sources = nil
|
|
77
|
+
assert_raise(RuntimeError){ po.to_po_str }
|
|
78
|
+
|
|
79
|
+
po = GetText::PoMessage.new(:plural)
|
|
80
|
+
po.msgid = 'hello'
|
|
81
|
+
po.sources = ["file1:1", "file2:10"]
|
|
82
|
+
assert_raise(RuntimeError){ po.to_po_str }
|
|
83
|
+
|
|
84
|
+
po.msgid_plural = 'hello2'
|
|
85
|
+
po.sources = nil
|
|
86
|
+
assert_raise(RuntimeError){ po.to_po_str }
|
|
87
|
+
|
|
88
|
+
po = GetText::PoMessage.new(:msgctxt)
|
|
89
|
+
po.msgid = 'hello'
|
|
90
|
+
po.sources = ["file1:1", "file2:10"]
|
|
91
|
+
assert_raise(RuntimeError){ po.to_po_str }
|
|
92
|
+
|
|
93
|
+
po = GetText::PoMessage.new(:msgctxt_plural)
|
|
94
|
+
po.msgctxt = 'context'
|
|
95
|
+
po.msgid = 'hello'
|
|
96
|
+
po.sources = ["file1:1", "file2:10"]
|
|
97
|
+
assert_raise(RuntimeError){ po.to_po_str }
|
|
98
|
+
end
|
|
99
|
+
end
|
data/test/test_string.rb
CHANGED
|
@@ -12,6 +12,13 @@ class TestGetTextString < Test::Unit::TestCase
|
|
|
12
12
|
assert_raise(ArgumentError) { "%-%" % [1] }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def test_sprintf_placeholder_include_non_english
|
|
16
|
+
assert_equal("a", "%{foo+foo}" % {"foo+foo".to_sym => "a"})
|
|
17
|
+
assert_equal("a", "%{foo.foo}" % {"foo.foo".to_sym => "a"})
|
|
18
|
+
assert_equal("a }", "%{foo+foo} }" % {"foo+foo".to_sym => "a"})
|
|
19
|
+
assert_equal("a { b }", "%{foo+foo} { %{bar bar-} }" % {"foo+foo".to_sym => "a", "bar bar-".to_sym => "b"})
|
|
20
|
+
end
|
|
21
|
+
|
|
15
22
|
def test_percent
|
|
16
23
|
assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
|
|
17
24
|
assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
|
|
@@ -39,6 +46,7 @@ class TestGetTextString < Test::Unit::TestCase
|
|
|
39
46
|
assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
|
|
40
47
|
assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
|
|
41
48
|
assert_equal("0x64", "%<num>#x" % {:num => 100.0})
|
|
49
|
+
assert_equal("a", "%<foo.foo>s" % {"foo.foo".to_sym => "a"})
|
|
42
50
|
assert_raise(ArgumentError) { "%<num>,d" % {:num => 100} }
|
|
43
51
|
assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
|
|
44
52
|
end
|