gettext 2.3.9 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.yardopts +1 -0
  2. data/README.rdoc +28 -23
  3. data/Rakefile +29 -21
  4. data/doc/text/news.md +57 -0
  5. data/gettext.gemspec +1 -1
  6. data/lib/gettext.rb +13 -29
  7. data/lib/gettext/cgi.rb +1 -1
  8. data/lib/gettext/{runtime/class_info.rb → class_info.rb} +1 -1
  9. data/lib/gettext/{runtime/locale_path.rb → locale_path.rb} +1 -2
  10. data/lib/gettext/{runtime/mo.rb → mo.rb} +18 -33
  11. data/lib/gettext/{tools/po.rb → po.rb} +1 -1
  12. data/lib/gettext/{tools/po_entry.rb → po_entry.rb} +8 -4
  13. data/lib/gettext/{tools/poparser.rb → po_parser.rb} +41 -44
  14. data/lib/gettext/{runtime/textdomain.rb → text_domain.rb} +6 -16
  15. data/lib/gettext/text_domain_group.rb +26 -0
  16. data/lib/gettext/{runtime/textdomain_manager.rb → text_domain_manager.rb} +40 -40
  17. data/lib/gettext/tools.rb +1 -182
  18. data/lib/gettext/tools/msgfmt.rb +1 -1
  19. data/lib/gettext/tools/msginit.rb +1 -1
  20. data/lib/gettext/tools/msgmerge.rb +2 -221
  21. data/lib/gettext/tools/parser/erb.rb +49 -30
  22. data/lib/gettext/tools/parser/glade.rb +44 -36
  23. data/lib/gettext/tools/parser/ruby.rb +126 -37
  24. data/lib/gettext/tools/task.rb +225 -0
  25. data/lib/gettext/tools/xgettext.rb +25 -28
  26. data/lib/gettext/version.rb +1 -1
  27. data/locale/bg/LC_MESSAGES/gettext.mo +0 -0
  28. data/locale/bs/LC_MESSAGES/gettext.mo +0 -0
  29. data/locale/ca/LC_MESSAGES/gettext.mo +0 -0
  30. data/locale/cs/LC_MESSAGES/gettext.mo +0 -0
  31. data/locale/de/LC_MESSAGES/gettext.mo +0 -0
  32. data/locale/el/LC_MESSAGES/gettext.mo +0 -0
  33. data/locale/eo/LC_MESSAGES/gettext.mo +0 -0
  34. data/locale/es/LC_MESSAGES/gettext.mo +0 -0
  35. data/locale/et/LC_MESSAGES/gettext.mo +0 -0
  36. data/locale/fr/LC_MESSAGES/gettext.mo +0 -0
  37. data/locale/hr/LC_MESSAGES/gettext.mo +0 -0
  38. data/locale/hu/LC_MESSAGES/gettext.mo +0 -0
  39. data/locale/it/LC_MESSAGES/gettext.mo +0 -0
  40. data/locale/ja/LC_MESSAGES/gettext.mo +0 -0
  41. data/locale/ko/LC_MESSAGES/gettext.mo +0 -0
  42. data/locale/lv/LC_MESSAGES/gettext.mo +0 -0
  43. data/locale/nb/LC_MESSAGES/gettext.mo +0 -0
  44. data/locale/nl/LC_MESSAGES/gettext.mo +0 -0
  45. data/locale/pt_BR/LC_MESSAGES/gettext.mo +0 -0
  46. data/locale/ru/LC_MESSAGES/gettext.mo +0 -0
  47. data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
  48. data/locale/sv/LC_MESSAGES/gettext.mo +0 -0
  49. data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
  50. data/locale/vi/LC_MESSAGES/gettext.mo +0 -0
  51. data/locale/zh/LC_MESSAGES/gettext.mo +0 -0
  52. data/locale/zh_TW/LC_MESSAGES/gettext.mo +0 -0
  53. data/po/gettext.pot +171 -97
  54. data/samples/hello.rb +3 -2
  55. data/samples/hello2.rb +2 -1
  56. data/samples/hello_gtk2.rb +4 -1
  57. data/samples/hello_gtk_builder.rb +32 -0
  58. data/samples/hello_gtk_builder.ui +46 -0
  59. data/samples/hello_noop.rb +2 -1
  60. data/samples/hello_plural.rb +2 -1
  61. data/samples/hello_tk.rb +2 -1
  62. data/src/{poparser.ry → po_parser.ry} +31 -35
  63. data/test/fixtures/N_.rb +1 -1
  64. data/test/fixtures/_/double_quote_in_double_quote.rb +32 -0
  65. data/test/fixtures/_/double_quote_in_single_quote.rb +32 -0
  66. data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +36 -0
  67. data/test/fixtures/_/middle_new_line.rb +32 -0
  68. data/test/fixtures/_/multiple_lines_literal.rb +35 -0
  69. data/test/fixtures/_/multiple_messages_in_same_line.rb +32 -0
  70. data/test/fixtures/_/multiple_same_messages.rb +36 -0
  71. data/{lib/gettext/runtime/mofile.rb → test/fixtures/_/one_new_line.rb} +12 -6
  72. data/test/fixtures/{multi_textdomain.rb → multi_text_domain.rb} +1 -1
  73. data/test/fixtures/non_ascii.rb +1 -1
  74. data/test/fixtures/simple.rb +1 -1
  75. data/test/fixtures/untranslated.rb +1 -1
  76. data/test/gettext-test-utils.rb +1 -24
  77. data/test/po/ja/_.po +63 -13
  78. data/test/po/ja/non_ascii.po +2 -3
  79. data/test/po/ja/untranslated.po +1 -1
  80. data/test/test_class_info.rb +2 -2
  81. data/test/test_gettext.rb +11 -11
  82. data/test/test_mo.rb +2 -2
  83. data/test/test_parser.rb +93 -96
  84. data/test/test_po_entry.rb +237 -146
  85. data/test/test_po_parser.rb +107 -98
  86. data/test/test_string.rb +1 -1
  87. data/test/{test_textdomain_bind.rb → test_text_domain_bind.rb} +6 -6
  88. data/test/{test_textdomain_multi.rb → test_text_domain_multi.rb} +5 -5
  89. data/test/{test_textdomain_toplevel.rb → test_text_domain_toplevel.rb} +1 -1
  90. data/test/test_thread.rb +1 -1
  91. data/test/tools/files/simple_translation.rb +1 -1
  92. data/test/{parser → tools/parser}/test_ruby.rb +110 -14
  93. data/test/tools/test_msgmerge.rb +17 -276
  94. data/test/tools/test_po.rb +1 -1
  95. data/test/tools/test_xgettext.rb +175 -144
  96. metadata +59 -33
  97. data/lib/gettext/core_ext/iconv.rb +0 -110
  98. data/lib/gettext/core_ext/string.rb +0 -91
  99. data/lib/gettext/parser/erb.rb +0 -5
  100. data/lib/gettext/parser/glade.rb +0 -5
  101. data/lib/gettext/parser/ruby.rb +0 -172
  102. data/lib/gettext/runtime/textdomain_group.rb +0 -26
  103. data/lib/gettext/task.rb +0 -203
  104. data/lib/gettext/utils.rb +0 -39
  105. data/test/test_po_generation.rb +0 -45
  106. data/test/tools/test_tools.rb +0 -61
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # License: Ruby's or LGPL
6
+ #
7
+ # This library is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module Fixtures
21
+ module Method_
22
+ class MultipleMessagesInSameLine
23
+ include GetText
24
+
25
+ bindtextdomain("_", :path => GetTextTestUtils.locale_path)
26
+
27
+ def message
28
+ _("multiple") + " messages " + _("in same line")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # License: Ruby's or LGPL
6
+ #
7
+ # This library is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module Fixtures
21
+ module Method_
22
+ class MultipleSameMessages
23
+ include GetText
24
+
25
+ bindtextdomain("_", :path => GetTextTestUtils.locale_path)
26
+
27
+ def message
28
+ _("multiple same messages")
29
+ end
30
+
31
+ def same_message
32
+ _("multiple same messages")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
3
+ # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # License: Ruby's or LGPL
6
6
  #
@@ -17,10 +17,16 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require "gettext/runtime/mo"
20
+ module Fixtures
21
+ module Method_
22
+ class OneNewLine
23
+ include GetText
21
24
 
22
- # Just for backward compatibility.
23
- module GetText
24
- MoFile = MO
25
- MOFile = MO
25
+ bindtextdomain("_", :path => GetTextTestUtils.locale_path)
26
+
27
+ def message
28
+ _("one new line\n")
29
+ end
30
+ end
31
+ end
26
32
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  module MultiTextDomain
4
4
  class C11
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'gettext'
4
4
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'gettext'
4
4
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'gettext'
4
4
 
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # License: Ruby's or LGPL
6
6
  #
@@ -22,10 +22,6 @@ require "tmpdir"
22
22
  require "tempfile"
23
23
  require "time"
24
24
 
25
- unless String.method_defined?(:encode)
26
- require "iconv"
27
- end
28
-
29
25
  require "gettext"
30
26
 
31
27
  module GetTextTestUtils
@@ -45,23 +41,4 @@ module GetTextTestUtils
45
41
  def teardown_tmpdir
46
42
  FileUtils.rm_rf(@tmpdir, :secure => true) if @tmpdir
47
43
  end
48
-
49
- def need_encoding
50
- unless defined?(Encoding)
51
- omit("This test needs encoding.")
52
- end
53
- end
54
-
55
- def set_encoding(string, encoding)
56
- return unless string.respond_to?(:force_encoding)
57
- string.force_encoding(encoding)
58
- end
59
-
60
- def encode(string, encoding)
61
- if string.respond_to?(:encode)
62
- string.encode(encoding)
63
- else
64
- Iconv.iconv(encoding, "UTF-8", string).join("")
65
- end
66
- end
67
44
  end
@@ -5,8 +5,8 @@
5
5
  msgid ""
6
6
  msgstr ""
7
7
  "Project-Id-Version: PACKAGE VERSION\n"
8
- "POT-Creation-Date: 2012-08-19 23:15+0900\n"
9
- "PO-Revision-Date: 2012-08-19 17:43+0900\n"
8
+ "POT-Creation-Date: 2013-08-30 23:15+0900\n"
9
+ "PO-Revision-Date: 2013-08-30 23:17+0900\n"
10
10
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
11
11
  "Language-Team: LANGUAGE <LL@li.org>\n"
12
12
  "MIME-Version: 1.0\n"
@@ -19,12 +19,18 @@ msgid "aaa"
19
19
  msgstr "AAA"
20
20
 
21
21
  #: ../fixtures/_.rb:34
22
- msgid "aaa\n"
23
- msgstr "AAA\n"
22
+ msgid ""
23
+ "aaa\n"
24
+ msgstr ""
25
+ "AAA\n"
24
26
 
25
27
  #: ../fixtures/_.rb:38
26
- msgid "bbb\nccc"
27
- msgstr "BBB\nCCC"
28
+ msgid ""
29
+ "bbb\n"
30
+ "ccc"
31
+ msgstr ""
32
+ "BBB\n"
33
+ "CCC"
28
34
 
29
35
  #: ../fixtures/_.rb:42
30
36
  msgid ""
@@ -69,7 +75,9 @@ msgid "lllmmm"
69
75
  msgstr ""
70
76
 
71
77
  #: ../fixtures/_.rb:84
72
- msgid "nnn\nooo"
78
+ msgid ""
79
+ "nnn\n"
80
+ "ooo"
73
81
  msgstr ""
74
82
 
75
83
  #: ../fixtures/_.rb:88 ../fixtures/_.rb:92
@@ -77,7 +85,7 @@ msgid "#"
77
85
  msgstr ""
78
86
 
79
87
  #: ../fixtures/_.rb:96
80
- msgid " aaa"
88
+ msgid "\taaa"
81
89
  msgstr ""
82
90
 
83
91
  #: ../fixtures/_.rb:100
@@ -86,29 +94,71 @@ msgid ""
86
94
  "Here document2\n"
87
95
  msgstr ""
88
96
 
89
- #. This is a proper name. See the gettext
97
+ #. TRANSLATORS: This is a proper name. See the gettext
90
98
  #. manual, section Names. Note this is actually a non-ASCII
91
99
  #. name: The first name is (with Unicode escapes)
92
100
  #. "Fran\u00e7ois" or (with HTML entities) "Fran&ccedil;ois".
93
101
  #. Pronunciation is like "fraa-swa pee-nar".
94
102
  #. This is an example from GNU gettext documentation.
95
- #: ../fixtures/_.rb:119
103
+ #: ../fixtures/_.rb:120
96
104
  msgid "Francois Pinard"
97
105
  msgstr ""
98
106
 
99
- #: ../fixtures/_.rb:122
107
+ #: ../fixtures/_.rb:123
100
108
  msgid "No TRANSLATORS comment"
101
109
  msgstr ""
102
110
 
103
- #: ../fixtures/_.rb:127
111
+ #: ../fixtures/_.rb:128
104
112
  msgid "self explaining"
105
113
  msgstr ""
106
114
 
107
- #: ../fixtures/_.rb:131
115
+ #: ../fixtures/_.rb:132
108
116
  msgid "This is a # including string."
109
117
  msgstr ""
110
118
 
119
+ #: ../fixtures/_/double_quote_in_double_quote.rb:28
120
+ msgid "double \"quote\" in double quote"
121
+ msgstr ""
122
+
123
+ #: ../fixtures/_/double_quote_in_single_quote.rb:28
124
+ msgid "double \"quote\" in single quote"
125
+ msgstr ""
126
+
127
+ #: ../fixtures/_/literal_concatenation_with_continuation_line.rb:28
128
+ msgid "literal concatenation with continuation line"
129
+ msgstr ""
130
+
131
+ #: ../fixtures/_/middle_new_line.rb:28
132
+ msgid ""
133
+ "middle\n"
134
+ "new line"
135
+ msgstr ""
136
+
137
+ #: ../fixtures/_/multiple_lines_literal.rb:28
138
+ msgid ""
139
+ "multiple\n"
140
+ "lines\n"
141
+ "literal\n"
142
+ msgstr ""
143
+
144
+ #: ../fixtures/_/multiple_messages_in_same_line.rb:28
145
+ msgid "in same line"
146
+ msgstr ""
147
+
148
+ #: ../fixtures/_/multiple_messages_in_same_line.rb:28
149
+ msgid "multiple"
150
+ msgstr ""
151
+
152
+ #: ../fixtures/_/multiple_same_messages.rb:28
153
+ #: ../fixtures/_/multiple_same_messages.rb:32
154
+ msgid "multiple same messages"
155
+ msgstr ""
156
+
111
157
  #: ../fixtures/_/one_line.rb:28
112
158
  msgid "one line"
113
159
  msgstr "ONE LINE"
114
160
 
161
+ #: ../fixtures/_/one_new_line.rb:28
162
+ msgid ""
163
+ "one new line\n"
164
+ msgstr ""
@@ -3,11 +3,10 @@
3
3
  # This file is distributed under the same license as the PACKAGE package.
4
4
  # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
5
  #
6
- #, fuzzy
7
6
  msgid ""
8
7
  msgstr ""
9
8
  "Project-Id-Version: PACKAGE VERSION\n"
10
- "POT-Creation-Date: 2012-03-31 19:22+0900\n"
9
+ "POT-Creation-Date: 2013-08-30 22:00+0900\n"
11
10
  "PO-Revision-Date: 2012-03-31 19:22+0900\n"
12
11
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
12
  "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -16,6 +15,6 @@ msgstr ""
16
15
  "Content-Transfer-Encoding: 8bit\n"
17
16
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
17
 
19
- #: test/fixtures/non_ascii.rb:10
18
+ #: ../fixtures/non_ascii.rb:10
20
19
  msgid "こんにちは"
21
20
  msgstr "Hello in Japanese"
@@ -7,7 +7,7 @@ msgid ""
7
7
  msgstr ""
8
8
  "Project-Id-Version: gettext 2.3.1\n"
9
9
  "Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2012-09-11 11:11+0900\n"
10
+ "POT-Creation-Date: 2013-08-30 22:00+0900\n"
11
11
  "PO-Revision-Date: 2012-09-11 11:11+0900\n"
12
12
  "Last-Translator: Haruka Yoshihara <yoshihara@clear-code.com>\n"
13
13
  "Language-Team: Japanese\n"
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
- require 'gettext/runtime/class_info'
3
+ require 'gettext/class_info'
4
4
 
5
5
  module M1; end
6
6
  module M2; end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  # Copyright (C) 2009-2010 Masao Mutoh
5
5
  # Copyright (C) 2009 OZAWA Sakuro <github@2238club.org>
6
6
  # Copyright (C) 2009 grosser <grosser.michael@gmail.com>
@@ -20,13 +20,13 @@
20
20
  # You should have received a copy of the GNU Lesser General Public License
21
21
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
 
23
- require 'fixtures/simple.rb'
24
- require 'fixtures/_.rb'
23
+ require 'fixtures/simple'
24
+ require 'fixtures/_'
25
25
  require "fixtures/_/one_line"
26
- require 'fixtures/s_.rb'
27
- require 'fixtures/ns_.rb'
28
- require 'fixtures/p_.rb'
29
- require 'fixtures/np_.rb'
26
+ require 'fixtures/s_'
27
+ require 'fixtures/ns_'
28
+ require 'fixtures/p_'
29
+ require 'fixtures/np_'
30
30
 
31
31
  class TestGetText < Test::Unit::TestCase
32
32
 
@@ -236,16 +236,16 @@ DDD
236
236
  assert_equal("fr_first", n_("first", "second", 0))
237
237
  assert_equal("fr_first", n_("first", "second", 1))
238
238
  assert_equal("fr_first", n_("first", "second", 2))
239
- setlocale("da") # Invalid Plural-Forms.
239
+ set_locale("da") # Invalid Plural-Forms.
240
240
  assert_equal("da_first", n_("first", "second", 0))
241
241
  assert_equal("da_first", n_("first", "second", 1))
242
242
  assert_equal("da_first", n_("first", "second", 2))
243
- setlocale("la") # wrong number of msgstr.
243
+ set_locale("la") # wrong number of msgstr.
244
244
  assert_equal("la_first", n_("first", "second", 0))
245
245
  assert_equal("la_first", n_("first", "second", 1))
246
246
  assert_equal("la_first", n_("first", "second", 2))
247
247
 
248
- setlocale("li") # Invalid Plural-Forms: nplurals is set, but wrong plural=.
248
+ set_locale("li") # Invalid Plural-Forms: nplurals is set, but wrong plural=.
249
249
  assert_equal("li_first", n_("first", "second", 0))
250
250
  assert_equal("li_first", n_("first", "second", 1))
251
251
  assert_equal("li_first", n_("first", "second", 2))
@@ -292,7 +292,7 @@ DDD
292
292
  assert_equal(["one", "two"], Nn_("one", "two"))
293
293
  end
294
294
 
295
- def test_setlocale
295
+ def test_set_locale
296
296
  bindtextdomain("test1", :path => "locale")
297
297
  assert_equal("japanese", _("language"))
298
298
  set_locale("en")
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
- require 'gettext/runtime/mo'
3
+ require 'gettext/mo'
4
4
 
5
5
  class TestMo < Test::Unit::TestCase
6
6
  def test_not_exist_msgid
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
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
@@ -22,127 +22,124 @@
22
22
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
23
 
24
24
  require "tempfile"
25
- require 'gettext/tools/parser/ruby'
26
- require 'gettext/tools/parser/glade'
27
- require 'gettext/tools/parser/erb'
25
+ require "gettext/tools/parser/ruby"
26
+ require "gettext/tools/parser/glade"
27
+ require "gettext/tools/parser/erb"
28
28
 
29
- require 'gettext/tools/xgettext'
29
+ require "gettext/tools/xgettext"
30
30
 
31
31
  class TestGetTextParser < Test::Unit::TestCase
32
32
  def setup
33
33
  @xgettext = GetText::Tools::XGetText.new
34
34
  end
35
35
 
36
- def test_ruby
37
- @ary = @xgettext.parse(['fixtures/_.rb'])
38
-
39
- assert_target 'aaa\n', ['fixtures/_.rb:34']
40
- assert_target 'bbb\nccc', ['fixtures/_.rb:38']
41
- assert_target 'bbb\nccc\nddd\n', ['fixtures/_.rb:42']
42
- assert_target 'eee', ['fixtures/_.rb:49', 'fixtures/_.rb:53']
43
- assert_target 'fff', ['fixtures/_.rb:53']
44
- assert_target 'ggghhhiii', ['fixtures/_.rb:57']
45
- assert_target 'a"b"c"', ['fixtures/_.rb:63']
46
- assert_target 'd"e"f"', ['fixtures/_.rb:67']
47
- assert_target 'jjj', ['fixtures/_.rb:71']
48
- assert_target 'kkk', ['fixtures/_.rb:72']
49
- assert_target 'lllmmm', ['fixtures/_.rb:76']
50
- assert_target 'nnn\nooo', ['fixtures/_.rb:84']
51
- assert_target "\#", ['fixtures/_.rb:88', 'fixtures/_.rb:92']
52
- assert_target "\\taaa", ['fixtures/_.rb:96']
53
- assert_target "Here document1\\nHere document2\\n", ['fixtures/_.rb:100']
54
- assert_target "Francois Pinard", ['fixtures/_.rb:120'] do |t|
55
- assert_match(/proper name/, t.extracted_comment)
56
- assert_match(/Pronunciation/, t.extracted_comment)
57
- end
36
+ class TestRuby < self
37
+ def test__
38
+ @xgettext.parse_options[:comment_tag] = "TRANSLATORS:"
39
+ @ary = @xgettext.parse(['fixtures/_.rb'])
40
+
41
+ assert_target 'jjj', ['fixtures/_.rb:71']
42
+ assert_target 'kkk', ['fixtures/_.rb:72']
43
+ assert_target 'lllmmm', ['fixtures/_.rb:76']
44
+ assert_target "nnn\nooo", ['fixtures/_.rb:84']
45
+ assert_target "\#", ['fixtures/_.rb:88', 'fixtures/_.rb:92']
46
+ assert_target "\\taaa", ['fixtures/_.rb:96']
47
+ assert_target "Here document1\nHere document2\n", ['fixtures/_.rb:100']
48
+ assert_target "Francois Pinard", ['fixtures/_.rb:120'] do |t|
49
+ assert_match(/proper name/, t.extracted_comment)
50
+ assert_match(/Pronunciation/, t.extracted_comment)
51
+ end
58
52
 
59
- assert_target("No TRANSLATORS comment", ["fixtures/_.rb:123"]) do |t|
60
- assert_nil(t.comment)
61
- end
53
+ assert_target("No TRANSLATORS comment", ["fixtures/_.rb:123"]) do |t|
54
+ assert_nil(t.comment)
55
+ end
62
56
 
63
- assert_target "self explaining", ['fixtures/_.rb:128'] do |t|
64
- assert_nil t.comment
65
- end
57
+ assert_target "self explaining", ['fixtures/_.rb:128'] do |t|
58
+ assert_nil t.comment
59
+ end
66
60
 
67
- assert_target "This is a # including string.", ["fixtures/_.rb:132"]
61
+ assert_target "This is a # including string.", ["fixtures/_.rb:132"]
68
62
 
69
- # TODO: assert_target "in_quote", ['fixtures/_.rb:118']
70
- end
63
+ # TODO: assert_target "in_quote", ['fixtures/_.rb:118']
64
+ end
71
65
 
72
- def test_ruby_N
73
- @ary = @xgettext.parse(['fixtures/N_.rb'])
74
-
75
- assert_target 'aaa', ['fixtures/N_.rb:10']
76
- assert_target 'aaa\n', ['fixtures/N_.rb:14']
77
- assert_target 'bbb\nccc', ['fixtures/N_.rb:18']
78
- assert_target 'bbb\nccc\nddd\n', ['fixtures/N_.rb:22']
79
- assert_target 'eee', ['fixtures/N_.rb:29', 'fixtures/N_.rb:33']
80
- assert_target 'fff', ['fixtures/N_.rb:33']
81
- assert_target 'ggghhhiii', ['fixtures/N_.rb:37']
82
- assert_target 'a"b"c"', ['fixtures/N_.rb:43']
83
- assert_target 'd"e"f"', ['fixtures/N_.rb:47']
84
- assert_target 'jjj', ['fixtures/N_.rb:51']
85
- assert_target 'kkk', ['fixtures/N_.rb:52']
86
- assert_target 'lllmmm', ['fixtures/N_.rb:56']
87
- assert_target 'nnn\nooo', ['fixtures/N_.rb:64']
88
- end
66
+ def test_N_
67
+ @ary = @xgettext.parse(['fixtures/N_.rb'])
68
+
69
+ assert_target 'aaa', ['fixtures/N_.rb:10']
70
+ assert_target "aaa\n", ['fixtures/N_.rb:14']
71
+ assert_target "bbb\nccc", ['fixtures/N_.rb:18']
72
+ assert_target "bbb\nccc\nddd\n", ['fixtures/N_.rb:22']
73
+ assert_target 'eee', ['fixtures/N_.rb:29', 'fixtures/N_.rb:33']
74
+ assert_target 'fff', ['fixtures/N_.rb:33']
75
+ assert_target 'ggghhhiii', ['fixtures/N_.rb:37']
76
+ assert_target 'a"b"c"', ['fixtures/N_.rb:43']
77
+ assert_target 'd"e"f"', ['fixtures/N_.rb:47']
78
+ assert_target 'jjj', ['fixtures/N_.rb:51']
79
+ assert_target 'kkk', ['fixtures/N_.rb:52']
80
+ assert_target 'lllmmm', ['fixtures/N_.rb:56']
81
+ assert_target "nnn\nooo", ['fixtures/N_.rb:64']
82
+ end
89
83
 
90
- def test_ruby_n
91
- @ary = @xgettext.parse(['fixtures/n_.rb'])
92
- assert_plural_target "aaa", "aaa2", ['fixtures/n_.rb:29']
93
- assert_plural_target "bbb\\n", "ccc2\\nccc2", ['fixtures/n_.rb:33']
94
- assert_plural_target "ddd\\nddd", "ddd2\\nddd2", ['fixtures/n_.rb:37']
95
- assert_plural_target "eee\\neee\\n", "eee2\\neee2\\n", ['fixtures/n_.rb:42']
96
- assert_plural_target "ddd\\neee\\n", "ddd\\neee2", ['fixtures/n_.rb:48']
97
- assert_plural_target "fff", "fff2", ['fixtures/n_.rb:55', 'fixtures/n_.rb:59']
98
- assert_plural_target "ggg", "ggg2", ['fixtures/n_.rb:59']
99
- assert_plural_target "ggghhhiii", "jjjkkklll", ['fixtures/n_.rb:63']
100
- assert_plural_target "a\"b\"c\"", "a\"b\"c\"2", ['fixtures/n_.rb:72']
101
- assert_plural_target "mmmmmm", "mmm2mmm2", ['fixtures/n_.rb:80']
102
- assert_plural_target "nnn", "nnn2", ['fixtures/n_.rb:81']
103
- assert_plural_target "comment", "comments", ['fixtures/n_.rb:97'] do |t|
104
- assert_equal "please provide translations for all\n the plural forms!",
105
- t.extracted_comment
84
+ def test_n_
85
+ @xgettext.parse_options[:comment_tag] = "TRANSLATORS:"
86
+ @ary = @xgettext.parse(['fixtures/n_.rb'])
87
+ assert_plural_target "aaa", "aaa2", ['fixtures/n_.rb:29']
88
+ assert_plural_target "bbb\n", "ccc2\nccc2", ['fixtures/n_.rb:33']
89
+ assert_plural_target "ddd\nddd", "ddd2\nddd2", ['fixtures/n_.rb:37']
90
+ assert_plural_target "eee\neee\n", "eee2\neee2\n", ['fixtures/n_.rb:42']
91
+ assert_plural_target "ddd\neee\n", "ddd\neee2", ['fixtures/n_.rb:48']
92
+ assert_plural_target "fff", "fff2", ['fixtures/n_.rb:55', 'fixtures/n_.rb:59']
93
+ assert_plural_target "ggg", "ggg2", ['fixtures/n_.rb:59']
94
+ assert_plural_target "ggghhhiii", "jjjkkklll", ['fixtures/n_.rb:63']
95
+ assert_plural_target "a\"b\"c\"", "a\"b\"c\"2", ['fixtures/n_.rb:72']
96
+ assert_plural_target "mmmmmm", "mmm2mmm2", ['fixtures/n_.rb:80']
97
+ assert_plural_target "nnn", "nnn2", ['fixtures/n_.rb:81']
98
+ assert_plural_target "comment", "comments", ['fixtures/n_.rb:97'] do |t|
99
+ assert_equal "TRANSLATORS:please provide translations for all\n the plural forms!",
100
+ t.extracted_comment
101
+ end
106
102
  end
107
- end
108
103
 
109
- def test_ruby_p
110
- @ary = @xgettext.parse(['fixtures/p_.rb'])
111
- assert_target_in_context "AAA", "BBB", ["fixtures/p_.rb:29", "fixtures/p_.rb:33"]
112
- assert_target_in_context "AAA|BBB", "CCC", ["fixtures/p_.rb:37"]
113
- assert_target_in_context "AAA", "CCC", ["fixtures/p_.rb:41"]
114
- assert_target_in_context "CCC", "BBB", ["fixtures/p_.rb:45"]
115
- assert_target_in_context "program", "name", ['fixtures/p_.rb:55'] do |t|
116
- assert_equal "please translate 'name' in the context of 'program'.\n Hint: the translation should NOT contain the translation of 'program'.", t.extracted_comment
104
+ def test_p_
105
+ @xgettext.parse_options[:comment_tag] = "TRANSLATORS:"
106
+ @ary = @xgettext.parse(['fixtures/p_.rb'])
107
+ assert_target_in_context "AAA", "BBB", ["fixtures/p_.rb:29", "fixtures/p_.rb:33"]
108
+ assert_target_in_context "AAA|BBB", "CCC", ["fixtures/p_.rb:37"]
109
+ assert_target_in_context "AAA", "CCC", ["fixtures/p_.rb:41"]
110
+ assert_target_in_context "CCC", "BBB", ["fixtures/p_.rb:45"]
111
+ assert_target_in_context "program", "name", ['fixtures/p_.rb:55'] do |t|
112
+ assert_equal "TRANSLATORS:please translate 'name' in the context of 'program'.\n Hint: the translation should NOT contain the translation of 'program'.", t.extracted_comment
113
+ end
117
114
  end
118
115
  end
119
116
 
120
- def test_glade
121
- # Old style (~2.0.4)
122
- ary = GetText::GladeParser.parse('fixtures/gladeparser.glade')
123
-
124
- assert_equal(['window1', 'fixtures/gladeparser.glade:8'], ary[0])
125
- assert_equal(['normal text', 'fixtures/gladeparser.glade:29'], ary[1])
126
- assert_equal(['1st line\n2nd line\n3rd line', 'fixtures/gladeparser.glade:50'], ary[2])
127
- assert_equal(['<span color="red" weight="bold" size="large">markup </span>', 'fixtures/gladeparser.glade:73'], ary[3])
128
- assert_equal(['<span color="red">1st line markup </span>\n<span color="blue">2nd line markup</span>', 'fixtures/gladeparser.glade:94'], ary[4])
129
- assert_equal(['<span>&quot;markup&quot; with &lt;escaped strings&gt;</span>', 'fixtures/gladeparser.glade:116'], ary[5])
130
- assert_equal(['duplicated', 'fixtures/gladeparser.glade:137', 'fixtures/gladeparser.glade:158'], ary[6])
117
+ class TestGlade < self
118
+ def test_old_style
119
+ # Old style (~2.0.4)
120
+ ary = GetText::GladeParser.parse('fixtures/gladeparser.glade')
121
+
122
+ assert_equal(['window1', 'fixtures/gladeparser.glade:8'], ary[0])
123
+ assert_equal(['normal text', 'fixtures/gladeparser.glade:29'], ary[1])
124
+ assert_equal(['1st line\n2nd line\n3rd line', 'fixtures/gladeparser.glade:50'], ary[2])
125
+ assert_equal(['<span color="red" weight="bold" size="large">markup </span>', 'fixtures/gladeparser.glade:73'], ary[3])
126
+ assert_equal(['<span color="red">1st line markup </span>\n<span color="blue">2nd line markup</span>', 'fixtures/gladeparser.glade:94'], ary[4])
127
+ assert_equal(['<span>&quot;markup&quot; with &lt;escaped strings&gt;</span>', 'fixtures/gladeparser.glade:116'], ary[5])
128
+ assert_equal(['duplicated', 'fixtures/gladeparser.glade:137', 'fixtures/gladeparser.glade:158'], ary[6])
129
+ end
131
130
  end
132
131
 
133
132
  class TestErbParser < self
134
133
  include GetTextTestUtils
135
134
 
136
135
  def test_detect_encoding
137
- need_encoding
138
-
139
136
  euc_file = Tempfile.new("euc-jp.rhtml")
140
137
  euc_file.open
141
138
  euc_file.puts("<%#-*- coding: euc-jp -*-%>")
142
139
  euc_file.close
143
140
 
144
141
  erb_source = ERB.new(File.read(euc_file.path)).src
145
- encoding = GetText::ErbParser.detect_encoding(erb_source)
142
+ encoding = GetText::ErbParser.new(euc_file.path).detect_encoding(erb_source)
146
143
 
147
144
  assert_equal("EUC-JP", encoding)
148
145
  end
@@ -151,7 +148,7 @@ class TestGetTextParser < Test::Unit::TestCase
151
148
  @ary = GetText::ErbParser.parse('fixtures/erb/ascii.rhtml')
152
149
 
153
150
  assert_target 'aaa', ['fixtures/erb/ascii.rhtml:8']
154
- assert_target 'aaa\n', ['fixtures/erb/ascii.rhtml:11']
151
+ assert_target "aaa\n", ['fixtures/erb/ascii.rhtml:11']
155
152
  assert_target 'bbb', ['fixtures/erb/ascii.rhtml:12']
156
153
  assert_plural_target "ccc1", "ccc2", ['fixtures/erb/ascii.rhtml:13']
157
154
  end
@@ -168,13 +165,13 @@ class TestGetTextParser < Test::Unit::TestCase
168
165
  GetText::ErbParser.init(:extnames => ['.rhtml', '.rxml'])
169
166
  @ary = @xgettext.parse(['fixtures/erb/ascii.rhtml'])
170
167
  assert_target 'aaa', ['fixtures/erb/ascii.rhtml:8']
171
- assert_target 'aaa\n', ['fixtures/erb/ascii.rhtml:11']
168
+ assert_target "aaa\n", ['fixtures/erb/ascii.rhtml:11']
172
169
  assert_target 'bbb', ['fixtures/erb/ascii.rhtml:12']
173
170
  assert_plural_target "ccc1", "ccc2", ['fixtures/erb/ascii.rhtml:13']
174
171
 
175
172
  @ary = @xgettext.parse(['fixtures/erb/ascii.rxml'])
176
173
  assert_target 'aaa', ['fixtures/erb/ascii.rxml:9']
177
- assert_target 'aaa\n', ['fixtures/erb/ascii.rxml:12']
174
+ assert_target "aaa\n", ['fixtures/erb/ascii.rxml:12']
178
175
  assert_target 'bbb', ['fixtures/erb/ascii.rxml:13']
179
176
  assert_plural_target "ccc1", "ccc2", ['fixtures/erb/ascii.rxml:14']
180
177