gettext 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/COPYING +9 -8
  2. data/ChangeLog +21 -0
  3. data/README.rdoc +7 -13
  4. data/Rakefile +7 -5
  5. data/benchmark/1.93.0.txt +8 -0
  6. data/benchmark/2.0.0.txt +8 -0
  7. data/benchmark/2.0.4.txt +11 -0
  8. data/benchmark/2.1.0.txt +11 -0
  9. data/benchmark/benchmark.rb +68 -0
  10. data/benchmark/test.rb +28 -0
  11. data/bin/rgettext +1 -2
  12. data/bin/rmsgfmt +1 -3
  13. data/bin/rmsgmerge +0 -2
  14. data/data/locale/bg/LC_MESSAGES/rgettext.mo +0 -0
  15. data/data/locale/bs/LC_MESSAGES/rgettext.mo +0 -0
  16. data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
  17. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  18. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  20. data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  22. data/data/locale/et/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  24. data/data/locale/hr/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/hu/LC_MESSAGES/rgettext.mo +0 -0
  26. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  27. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  28. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  29. data/data/locale/lv/LC_MESSAGES/rgettext.mo +0 -0
  30. data/data/locale/nb/LC_MESSAGES/rgettext.mo +0 -0
  31. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  32. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  33. data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
  34. data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
  35. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  36. data/data/locale/ua/LC_MESSAGES/rgettext.mo +0 -0
  37. data/data/locale/vi/LC_MESSAGES/rgettext.mo +0 -0
  38. data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
  39. data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
  40. data/lib/gettext.rb +4 -6
  41. data/lib/gettext/cgi.rb +1 -3
  42. data/lib/gettext/core_ext/iconv.rb +2 -4
  43. data/lib/gettext/core_ext/string.rb +3 -3
  44. data/lib/gettext/parser/erb.rb +2 -53
  45. data/lib/gettext/parser/glade.rb +2 -99
  46. data/lib/gettext/parser/ruby.rb +7 -5
  47. data/lib/gettext/{class_info.rb → runtime/class_info.rb} +2 -1
  48. data/lib/gettext/{locale_path.rb → runtime/locale_path.rb} +1 -2
  49. data/lib/gettext/{mofile.rb → runtime/mofile.rb} +0 -0
  50. data/lib/gettext/{textdomain.rb → runtime/textdomain.rb} +3 -5
  51. data/lib/gettext/{textdomain_group.rb → runtime/textdomain_group.rb} +1 -1
  52. data/lib/gettext/{textdomain_manager.rb → runtime/textdomain_manager.rb} +11 -5
  53. data/lib/gettext/tools.rb +2 -2
  54. data/lib/gettext/tools/parser/erb.rb +52 -0
  55. data/lib/gettext/tools/parser/glade.rb +98 -0
  56. data/lib/gettext/tools/parser/ruby.rb +226 -0
  57. data/lib/gettext/tools/pomessage.rb +197 -0
  58. data/lib/gettext/{poparser.rb → tools/poparser.rb} +128 -122
  59. data/lib/gettext/tools/rgettext.rb +47 -92
  60. data/lib/gettext/tools/rmsgfmt.rb +2 -2
  61. data/lib/gettext/tools/rmsgmerge.rb +2 -2
  62. data/lib/gettext/utils.rb +1 -1
  63. data/lib/gettext/version.rb +2 -2
  64. data/po/bg/rgettext.po +68 -64
  65. data/po/bs/rgettext.po +69 -65
  66. data/po/ca/rgettext.po +67 -64
  67. data/po/cs/rgettext.po +73 -70
  68. data/po/de/rgettext.po +69 -65
  69. data/po/el/rgettext.po +67 -64
  70. data/po/eo/rgettext.po +67 -63
  71. data/po/es/rgettext.po +67 -63
  72. data/po/et/rgettext.po +66 -63
  73. data/po/fr/rgettext.po +69 -66
  74. data/po/hr/rgettext.po +77 -73
  75. data/po/hu/rgettext.po +68 -65
  76. data/po/it/rgettext.po +69 -65
  77. data/po/ja/rgettext.po +69 -65
  78. data/po/ko/rgettext.po +73 -70
  79. data/po/lv/rgettext.po +68 -65
  80. data/po/nb/rgettext.po +68 -65
  81. data/po/nl/rgettext.po +74 -70
  82. data/po/pt_BR/rgettext.po +69 -66
  83. data/po/rgettext.pot +52 -48
  84. data/po/ru/rgettext.po +69 -66
  85. data/po/sr/rgettext.po +68 -64
  86. data/po/sv/rgettext.po +59 -55
  87. data/po/ua/rgettext.po +69 -66
  88. data/po/vi/rgettext.po +67 -63
  89. data/po/zh/rgettext.po +65 -62
  90. data/po/zh_TW/rgettext.po +65 -62
  91. data/replace.rb +8 -0
  92. data/samples/cgi/hellolib.rb +1 -3
  93. data/samples/cgi/http.rb +2 -4
  94. data/samples/cgi/locale/bg/LC_MESSAGES/main.mo +0 -0
  95. data/samples/cgi/po/bg/#main.po# +84 -0
  96. data/samples/cgi/po/bg/main.po +1 -1
  97. data/samples/hello.rb +1 -1
  98. data/src/poparser.ry +2 -1
  99. data/test.rb +33 -0
  100. data/test/test_class_info.rb +1 -1
  101. data/test/test_gettext.rb +1 -0
  102. data/test/test_parser.rb +120 -75
  103. data/test/test_po_generation.rb +20 -0
  104. data/test/test_pomessage.rb +99 -0
  105. data/test/test_string.rb +8 -0
  106. data/test/testlib/gettext.rb +17 -0
  107. data/test/testlib/ngettext.rb +6 -1
  108. data/test/testlib/pgettext.rb +5 -0
  109. metadata +726 -985
@@ -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"
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
  # hello.rb - sample for _() and class.
3
3
  #
4
- # Copyright (C) 2001-2006 Masao Mutoh
4
+ # Copyright (C) 2001-2009 Masao Mutoh
5
5
  # This file is distributed under the same license as Ruby-GetText-Package.
6
6
 
7
7
  require 'rubygems'
@@ -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 " msgid '#{val[1]}'\n"
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
+
@@ -1,5 +1,5 @@
1
1
  require 'testlib/helper.rb'
2
- require 'gettext/class_info'
2
+ require 'gettext/runtime/class_info'
3
3
 
4
4
  module M1; end
5
5
  module M2; end
@@ -14,6 +14,7 @@ class TestGetText < Test::Unit::TestCase
14
14
  ENV["LC_ALL"] = "ja_JP.UTF-8"
15
15
  ENV["LANG"] = "ja_JP.UTF-8"
16
16
  GetText.locale = nil
17
+ GetText::TextDomainManager.clear_caches
17
18
  end
18
19
 
19
20
  def test_change_locale
@@ -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::RubyParser.parse('testlib/gettext.rb')
11
-
12
- assert_equal(['aaa', 'testlib/gettext.rb:8'], ary[0])
13
- assert_equal(['aaa\n', 'testlib/gettext.rb:12'], ary[1])
14
- assert_equal(['bbb\nccc', 'testlib/gettext.rb:16'], ary[2])
15
- assert_equal(['bbb\nccc\nddd\n', 'testlib/gettext.rb:20'], ary[3])
16
- assert_equal(['eee', 'testlib/gettext.rb:27', 'testlib/gettext.rb:31'], ary[4])
17
- assert_equal(['fff', 'testlib/gettext.rb:31'], ary[5])
18
- assert_equal(['ggghhhiii', 'testlib/gettext.rb:35'], ary[6])
19
- assert_equal(['a"b"c"', 'testlib/gettext.rb:41'], ary[7])
20
- assert_equal(['d"e"f"', 'testlib/gettext.rb:45'], ary[8])
21
- assert_equal(['jjj', 'testlib/gettext.rb:49'], ary[9])
22
- assert_equal(['kkk', 'testlib/gettext.rb:50'], ary[10])
23
- assert_equal(['lllmmm', 'testlib/gettext.rb:54'], ary[11])
24
- assert_equal(['nnn\nooo', 'testlib/gettext.rb:62'], ary[12])
25
- assert_equal(["\#", 'testlib/gettext.rb:66', 'testlib/gettext.rb:70'], ary[13])
26
- assert_equal(["\\taaa", 'testlib/gettext.rb:74'], ary[14])
27
- assert_equal(["Here document1\\nHere document2\\n", 'testlib/gettext.rb:78'], ary[15])
28
- # assert_equal(["in_quote", 'testlib/gettext.rb:96'], ary[16])
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::RubyParser.parse('testlib/N_.rb')
33
-
34
- assert_equal(['aaa', 'testlib/N_.rb:8'], ary[0])
35
- assert_equal(['aaa\n', 'testlib/N_.rb:12'], ary[1])
36
- assert_equal(['bbb\nccc', 'testlib/N_.rb:16'], ary[2])
37
- assert_equal(['bbb\nccc\nddd\n', 'testlib/N_.rb:20'], ary[3])
38
- assert_equal(['eee', 'testlib/N_.rb:27', 'testlib/N_.rb:31'], ary[4])
39
- assert_equal(['fff', 'testlib/N_.rb:31'], ary[5])
40
- assert_equal(['ggghhhiii', 'testlib/N_.rb:35'], ary[6])
41
- assert_equal(['a"b"c"', 'testlib/N_.rb:41'], ary[7])
42
- assert_equal(['d"e"f"', 'testlib/N_.rb:45'], ary[8])
43
- assert_equal(['jjj', 'testlib/N_.rb:49'], ary[9])
44
- assert_equal(['kkk', 'testlib/N_.rb:50'], ary[10])
45
- assert_equal(['lllmmm', 'testlib/N_.rb:54'], ary[11])
46
- assert_equal(['nnn\nooo', 'testlib/N_.rb:62'], ary[12])
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::RubyParser.parse('testlib/ngettext.rb')
51
- assert_equal(["aaa\000aaa2", 'testlib/ngettext.rb:8'], ary[0])
52
- assert_equal(["bbb\\n\000ccc2\\nccc2", 'testlib/ngettext.rb:12'], ary[1])
53
- assert_equal(["ddd\\nddd\000ddd2\\nddd2", 'testlib/ngettext.rb:16'], ary[2])
54
- assert_equal(["eee\\neee\\n\000eee2\\neee2\\n", 'testlib/ngettext.rb:21'], ary[3])
55
- assert_equal(["ddd\\neee\\n\000ddd\\neee2", 'testlib/ngettext.rb:27'], ary[4])
56
- assert_equal(["fff\000fff2", 'testlib/ngettext.rb:34', 'testlib/ngettext.rb:38'], ary[5])
57
- assert_equal(["ggg\000ggg2", 'testlib/ngettext.rb:38'], ary[6])
58
- assert_equal(["ggghhhiii\000jjjkkklll", 'testlib/ngettext.rb:42'], ary[7])
59
- assert_equal(["a\"b\"c\"\000a\"b\"c\"2", 'testlib/ngettext.rb:51'], ary[8])
60
- assert_equal(["mmmmmm\000mmm2mmm2", 'testlib/ngettext.rb:59'], ary[10])
61
- assert_equal(["nnn\000nnn2", 'testlib/ngettext.rb:60'], ary[11])
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::RubyParser.parse('testlib/pgettext.rb')
66
- assert_equal(["AAA\004BBB", "testlib/pgettext.rb:8", "testlib/pgettext.rb:12"], ary[0])
67
- assert_equal(["AAA|BBB\004CCC", "testlib/pgettext.rb:16"], ary[1])
68
- assert_equal(["AAA\004CCC", "testlib/pgettext.rb:20"], ary[2])
69
- assert_equal(["CCC\004BBB", "testlib/pgettext.rb:24"], ary[3])
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
- assert_equal(['aaa', 'testlib/erb.rhtml:8'], ary[0])
88
- assert_equal(['aaa\n', 'testlib/erb.rhtml:11'], ary[1])
89
- assert_equal(['bbb', 'testlib/erb.rhtml:12'], ary[2])
90
- assert_equal(["ccc1\000ccc2", 'testlib/erb.rhtml:13'], ary[3])
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
- assert_equal(['aaa', 'testlib/erb.rhtml:8'], ary[0])
97
- assert_equal(['aaa\n', 'testlib/erb.rhtml:11'], ary[1])
98
- assert_equal(['bbb', 'testlib/erb.rhtml:12'], ary[2])
99
- assert_equal(["ccc1\000ccc2", 'testlib/erb.rhtml:13'], ary[3])
100
-
101
- ary = GetText::RGetText.parse(['testlib/erb.rxml'])
102
- assert_equal(['aaa', 'testlib/erb.rxml:9'], ary[0])
103
- assert_equal(['aaa\n', 'testlib/erb.rxml:12'], ary[1])
104
- assert_equal(['bbb', 'testlib/erb.rxml:13'], ary[2])
105
- assert_equal(["ccc1\000ccc2", 'testlib/erb.rxml:14'], ary[3])
106
-
107
-
108
- ary = GetText::RGetText.parse(['testlib/ngettext.rb'])
109
- assert_equal(["ooo\000ppp", 'testlib/ngettext.rb:64', 'testlib/ngettext.rb:65'], ary[12])
110
- assert_equal(["qqq\000rrr", 'testlib/ngettext.rb:69', 'testlib/ngettext.rb:70'], ary[13])
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&ccedil;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
@@ -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