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.
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
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
-
3
- =begin
4
- gettext/textdomain_group - GetText::TextDomainGroup class
5
-
6
- Copyright (C) 2009 Masao Mutoh
7
-
8
- You may redistribute it and/or modify it under the same
9
- license terms as Ruby or LGPL.
10
-
11
- =end
12
-
13
- module GetText
14
-
15
- class TextDomainGroup
16
- attr_reader :textdomains
17
-
18
- def initialize
19
- @textdomains = []
20
- end
21
-
22
- def add(textdomain)
23
- @textdomains.unshift(textdomain) unless @textdomains.include? textdomain
24
- end
25
- end
26
- end
@@ -1,203 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2012 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
- require "gettext/tools"
21
-
22
- module GetText
23
- class Task
24
- include GetText
25
- include Rake::DSL
26
-
27
- attr_accessor :locales, :po_base_directory, :mo_base_directory, :domain
28
- attr_accessor :namespace_prefix, :files
29
- def initialize(spec)
30
- @spec = spec
31
- @locales = []
32
- @po_base_directory = "po"
33
- @mo_base_directory = "."
34
- @files = target_files
35
- @domain = @spec.name
36
- @namespace_prefix = nil
37
- yield(self) if block_given?
38
- @locales = detect_locales if @locales.empty?
39
- raise("must set locales: #{inspect}") if @locales.empty?
40
- define
41
- end
42
-
43
- private
44
- def define
45
- define_file_tasks
46
- if namespace_prefix
47
- namespace_recursive namespace_prefix do
48
- define_named_tasks
49
- end
50
- else
51
- define_named_tasks
52
- end
53
- end
54
-
55
- def define_file_tasks
56
- unless files.empty?
57
- pot_dependencies = files.dup
58
- unless File.exist?(po_base_directory)
59
- directory po_base_directory
60
- pot_dependencies << po_base_directory
61
- end
62
- file pot_file => pot_dependencies do
63
- GetText::Tools::XGetText.run("--package-name", @spec.name,
64
- "--package-version", @spec.version.to_s,
65
- "--output", pot_file,
66
- *files)
67
- end
68
- end
69
-
70
- locales.each do |locale|
71
- _po_file = po_file(locale)
72
- unless files.empty?
73
- po_dependencies = [pot_file]
74
- _po_directory = po_directory(locale)
75
- unless File.exist?(_po_directory)
76
- directory _po_directory
77
- po_dependencies << _po_directory
78
- end
79
- file _po_file => po_dependencies do
80
- if File.exist?(_po_file)
81
- GetText::Tools::MsgMerge.run(po_file(locale), pot_file,
82
- "--output", _po_file)
83
- else
84
- GetText::Tools::MsgInit.run("--input", pot_file,
85
- "--output", _po_file,
86
- "--locale", locale.to_s)
87
- end
88
- end
89
- end
90
-
91
- mo_dependencies = [_po_file]
92
- _mo_directory = mo_directory(locale)
93
- unless File.exist?(_mo_directory)
94
- directory _mo_directory
95
- mo_dependencies << _mo_directory
96
- end
97
- _mo_file = mo_file(locale)
98
- file _mo_file => mo_dependencies do
99
- GetText::Tools::MsgFmt.run(_po_file, "--output", _mo_file)
100
- end
101
- end
102
- end
103
-
104
- def define_named_tasks
105
- namespace :gettext do
106
- namespace :pot do
107
- desc "Create #{pot_file}"
108
- task :create => pot_file
109
- end
110
-
111
- namespace :po do
112
- update_tasks = []
113
- @locales.each do |locale|
114
- namespace locale do
115
- desc "Update #{po_file(locale)}"
116
- task :update => po_file(locale)
117
- update_tasks << (current_scope + ["update"]).join(":")
118
- end
119
- end
120
-
121
- desc "Update *.po"
122
- task :update => update_tasks
123
- end
124
-
125
- namespace :mo do
126
- update_tasks = []
127
- @locales.each do |locale|
128
- namespace locale do
129
- desc "Update #{mo_file(locale)}"
130
- task :update => mo_file(locale)
131
- update_tasks << (current_scope + ["update"]).join(":")
132
- end
133
- end
134
-
135
- desc "Update *.mo"
136
- task :update => update_tasks
137
- end
138
- end
139
-
140
- desc "Update *.mo"
141
- task :gettext => (current_scope + ["gettext", "mo", "update"]).join(":")
142
- end
143
-
144
- def pot_file
145
- File.join(po_base_directory, "#{domain}.pot")
146
- end
147
-
148
- def po_directory(locale)
149
- File.join(po_base_directory, locale.to_s)
150
- end
151
-
152
- def po_file(locale)
153
- File.join(po_directory(locale), "#{domain}.po")
154
- end
155
-
156
- def mo_directory(locale)
157
- File.join(mo_base_directory, "locale", locale.to_s, "LC_MESSAGES")
158
- end
159
-
160
- def mo_file(locale)
161
- File.join(mo_directory(locale), "#{domain}.mo")
162
- end
163
-
164
- def target_files
165
- files = @spec.files.find_all do |file|
166
- /\.(?:rb|erb|glade)/i =~ File.extname(file)
167
- end
168
- files += @spec.executables.collect do |executable|
169
- "bin/#{executable}"
170
- end
171
- files
172
- end
173
-
174
- def detect_locales
175
- locales = []
176
- return locales unless File.exist?(po_base_directory)
177
-
178
- Dir.open(po_base_directory) do |dir|
179
- dir.each do |entry|
180
- next unless /\A[a-z]{2}(?:_[A-Z]{2})?\z/ =~ entry
181
- next unless File.directory?(File.join(dir.path, entry))
182
- locales << entry
183
- end
184
- end
185
- locales
186
- end
187
-
188
- def current_scope
189
- Rake.application.current_scope
190
- end
191
-
192
- def namespace_recursive(namespace_spec, &block)
193
- first, rest = namespace_spec.split(/:/, 2)
194
- namespace first do
195
- if rest.nil?
196
- block.call
197
- else
198
- namespace_recursive(rest, &block)
199
- end
200
- end
201
- end
202
- end
203
- end
@@ -1,39 +0,0 @@
1
- # encoding: utf-8
2
-
3
- =begin
4
- utils.rb - Utility functions
5
-
6
- Copyright (C) 2005,2006 Masao Mutoh
7
-
8
- You may redistribute it and/or modify it under the same
9
- license terms as Ruby or LGPL.
10
- =end
11
-
12
- require 'gettext/tools'
13
-
14
- warn "'gettext/utils.rb' is deprecated. Use gettext/tools.rb."
15
-
16
- module GetText
17
-
18
- alias :create_mofiles_org :create_mofiles #:nodoc:
19
- alias :update_pofiles_org :update_pofiles #:nodoc:
20
-
21
-
22
- # Deprecated. Use gettext/tools instead.
23
- def create_mofiles(verbose = false,
24
- podir = "./po", targetdir = "./data/locale",
25
- targetpath_rule = "%s/LC_MESSAGES") # :nodoc:
26
- warn "'gettext/utils.rb' is deprecated. Use gettext/tools.rb."
27
- create_mofiles_org(:verbose => verbose,
28
- :po_root => podir,
29
- :mo_root => targetdir,
30
- :mo_root_rule => targetpath_rule)
31
- end
32
-
33
- # Deprecated. Use gettext/tools instead.
34
- def update_pofiles(textdomain, files, app_version, po_root = "po", refpot = "tmp.pot") # :nodoc:
35
- warn "'gettext/utils.rb' is deprecated. Use gettext/tools.rb."
36
- options = {:po_root => po_root}
37
- update_pofiles_org(textdomain, files, app_version, options)
38
- end
39
- end
@@ -1,45 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
- # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
5
- # Copyright (C) 2010 masone (Christian Felder) <ema@rh-productions.ch>
6
- # Copyright (C) 2009 Masao Mutoh
7
- # Copyright (C) 2009 Vladimir Dobriakov <vladimir@geekq.net>
8
- #
9
- # License: Ruby's or LGPL
10
- #
11
- # This library is free software: you can redistribute it and/or modify
12
- # it under the terms of the GNU Lesser General Public License as published by
13
- # the Free Software Foundation, either version 3 of the License, or
14
- # (at your option) any later version.
15
- #
16
- # This library is distributed in the hope that it will be useful,
17
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- # GNU Lesser General Public License for more details.
20
- #
21
- # You should have received a copy of the GNU Lesser General Public License
22
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
-
24
- require 'gettext'
25
- require 'gettext/tools/xgettext.rb'
26
-
27
- class TestPoGeneration < Test::Unit::TestCase
28
- def test_extracted_comments
29
- input_file = File.join(File.dirname(__FILE__), 'fixtures/_.rb')
30
- res = ""
31
- Dir.mktmpdir do |dir|
32
- Dir.chdir(dir) do
33
- out = "comments.pot"
34
- GetText::Tools::XGetText.run(input_file, "-o", out)
35
- res = File.read(out)
36
- end
37
- end
38
- # Use following to debug the content of the
39
- # created file: File.open('/tmp/test.po', 'w').write(res)
40
-
41
- assert_match '#. "Fran\u00e7ois" or (with HTML entities) "Fran&ccedil;ois".', res
42
- assert_no_match(/Ignored/, res, 'Only comments starting with TRANSLATORS should be extracted')
43
- assert_no_match(/TRANSLATORS: This is a proper name/, res, 'The prefix "TRANSLATORS:" should be skipped')
44
- end
45
- end
@@ -1,61 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'gettext/tools'
4
- class TestToolsTools < Test::Unit::TestCase
5
- def setup
6
- FileUtils.cp_r "tools/files", "tools/test_files"
7
- end
8
- def teardown
9
- FileUtils.rm_rf "tools/test_files"
10
- end
11
-
12
- def test_msgmerge_merges_old_and_new_po_file
13
- GetText.msgmerge(path('simple_1.po'),path('simple_2.po'),'X',:msgmerge=>[:sort_output,:no_location])
14
- assert_equal File.read(path('simple_1.po')), <<EOF
15
- msgid "a"
16
- msgstr "b"
17
-
18
- #~ msgid "x"
19
- #~ msgstr "y"
20
- EOF
21
- end
22
-
23
- def test_msgmerge_inserts_the_new_version
24
- old = backup('version.po')
25
- GetText.msgmerge(old,path('version.po'),'NEW')
26
- assert File.read(old) =~ /"Project-Id-Version: NEW\\n"/
27
- end
28
-
29
- def test_update_pofiles_updates_a_single_language
30
- GetText.update_pofiles('app',[path('simple_translation.rb')],'x',:po_root=>path('.'),:lang=>'en',:msgmerge=>[:no_location])
31
- text = <<EOF
32
- msgid "a translation"
33
- msgstr ""
34
- EOF
35
- assert_equal text, File.read(path('app.pot'))
36
- assert_equal text, File.read(path('en/app.po'))
37
- assert_equal '', File.read(path('de/app.po'))
38
- end
39
-
40
- def test_update_pofiles_updates_creates_po_folder_if_missing
41
- GetText.update_pofiles('app',[path('simple_translation.rb')],'x',:po_root=>path('./xx'))
42
- assert File.exist?(path('xx/app.pot'))
43
- end
44
-
45
- def test_create_mofiles_generates_mo_for_each_po
46
- GetText.create_mofiles(:po_root=>path('.'),:mo_root=>path('mo'))
47
- assert File.exist?(path('mo/en/LC_MESSAGES/app.mo'))
48
- assert File.exist?(path('mo/de/LC_MESSAGES/app.mo'))
49
- end
50
- private
51
-
52
- def backup(name)
53
- copy = path(name+".bak")
54
- FileUtils.cp path(name), copy
55
- copy
56
- end
57
-
58
- def path(name)
59
- File.join(File.dirname(__FILE__),'test_files',name)
60
- end
61
- end