gettext 2.0.0 → 2.0.1
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/ChangeLog +15 -0
- data/README.rdoc +19 -19
- data/Rakefile +3 -3
- data/lib/gettext.rb +33 -19
- data/lib/gettext/class_info.rb +6 -3
- data/lib/gettext/core_ext/string.rb +5 -2
- data/lib/gettext/locale_path.rb +67 -51
- data/lib/gettext/mofile.rb +17 -11
- data/lib/gettext/parser/erb.rb +4 -1
- data/lib/gettext/textdomain.rb +6 -3
- data/lib/gettext/textdomain_group.rb +25 -0
- data/lib/gettext/textdomain_manager.rb +70 -86
- data/lib/gettext/tools.rb +19 -0
- data/lib/gettext/tools/rmsgfmt.rb +2 -1
- data/lib/gettext/version.rb +1 -1
- data/test/Rakefile +1 -1
- data/test/locale/ja/LC_MESSAGES/test3.mo +0 -0
- data/test/po/{fr/test6.po → ja/test3.po} +3 -7
- data/test/test_class_info.rb +0 -1
- data/test/test_gettext.rb +1 -0
- data/test/test_locale_path.rb +15 -2
- data/test/test_parser.rb +3 -3
- data/test/test_string.rb +23 -1
- data/test/test_textdomain_bind.rb +1 -1
- data/test/test_textdomain_multi.rb +10 -0
- data/test/test_thread.rb +1 -1
- data/test/testlib/multi_textdomain.rb +12 -0
- metadata +6 -7
- data/test/locale/fr/LC_MESSAGES/test6.mo +0 -0
- data/test/locale/ja/LC_MESSAGES/test6.mo +0 -0
- data/test/po/ja/test6.po +0 -23
data/ChangeLog
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
= Ruby-GetText-Package-2.0.1 (2009-04-17)
|
2
|
+
* Fixed bugs
|
3
|
+
* doesn't work with ruby-1.8.5. [Reported by Dan Coutu]
|
4
|
+
* GetText.locale= can't keep the locale. [Reported by Adam Ilan]
|
5
|
+
* Break backward compatibility of bindtextdomain
|
6
|
+
[Reported by Mamoru Tasaka(#24947), Mathieu Blondel]
|
7
|
+
* Other trivial fixes/improvement.
|
8
|
+
* 1.8 times faster than 2.0.0.
|
9
|
+
* GetText::LocalePath is separated from GetText::TextDomainManager.
|
10
|
+
Improve to find the locale path.
|
11
|
+
* Enhance to support ruby-1.9.x [by OZAWA Sakuro]
|
12
|
+
|
13
|
+
Thanks to:
|
14
|
+
OZAWA Sakuro, Tietew, Adam Ilan, Mamoru Tasaka, Mathieu Blondel.
|
15
|
+
|
1
16
|
= Ruby-GetText-Package-2.0.0 (2009-03-21)
|
2
17
|
* Separate this library to locale and rails-support to locale,
|
3
18
|
locale_rails, gettext_activerecord, gettext_rails.
|
data/README.rdoc
CHANGED
@@ -60,7 +60,7 @@ Rails / ActiveRecord specific code now lives in locale_rails[http://github.com/m
|
|
60
60
|
* (for compiling src/rmsgfmt.ry only)
|
61
61
|
|
62
62
|
== Install
|
63
|
-
* Uninstall old gettext if exists. (You need to do this when updating 1.93.0 -> 2.0.
|
63
|
+
* Uninstall old gettext if exists. (You need to do this when updating 1.93.0 -> 2.0.1)
|
64
64
|
(sudo/su on POSIX system)
|
65
65
|
gem uninstall gettext
|
66
66
|
|
@@ -220,32 +220,32 @@ This program is licenced under the same licence as Ruby.
|
|
220
220
|
|
221
221
|
== Status of translations
|
222
222
|
* Bosnian(bs) - 1.90.0 (old)
|
223
|
-
* Bulgarian(bg) - 2.0.
|
224
|
-
* Catalan(ca) - 2.0.
|
223
|
+
* Bulgarian(bg) - 2.0.1
|
224
|
+
* Catalan(ca) - 2.0.1
|
225
225
|
* Croatian(hr) - 1.90.0 (old)
|
226
|
-
* Chinese(zh_CN) - 2.0.
|
227
|
-
* Chinese(zh_TW) - 2.0.
|
226
|
+
* Chinese(zh_CN) - 2.0.1
|
227
|
+
* Chinese(zh_TW) - 2.0.1
|
228
228
|
* Czech(cs) - 1.9.0 (old)
|
229
229
|
* Dutch(nl) - 1.90.0 (old)
|
230
230
|
* English(default) - 1.90.0 (old)
|
231
|
-
* Esperanto(eo) - 2.0.
|
232
|
-
* Estonian(et) - 2.0.
|
233
|
-
* French(fr) - 2.0.
|
234
|
-
* German(de) - 2.0.
|
235
|
-
* Greek(el) - 2.0.
|
236
|
-
* Hungarian(hu) - 2.0.
|
231
|
+
* Esperanto(eo) - 2.0.1
|
232
|
+
* Estonian(et) - 2.0.1
|
233
|
+
* French(fr) - 2.0.1
|
234
|
+
* German(de) - 2.0.1
|
235
|
+
* Greek(el) - 2.0.1
|
236
|
+
* Hungarian(hu) - 2.0.1
|
237
237
|
* Italian(it) - 1.6.0 (old)
|
238
|
-
* Japanese(ja) - 2.0.
|
238
|
+
* Japanese(ja) - 2.0.1
|
239
239
|
* Korean(ko) - 1.9.0 (old)
|
240
|
-
* Latvian(lv) - 2.0.
|
241
|
-
* Norwegian(nb) - 2.0.
|
242
|
-
* Portuguese(Brazil)(pt_BR) - 2.0.
|
243
|
-
* Russian(ru) - 2.0.
|
240
|
+
* Latvian(lv) - 2.0.1
|
241
|
+
* Norwegian(nb) - 2.0.1
|
242
|
+
* Portuguese(Brazil)(pt_BR) - 2.0.1
|
243
|
+
* Russian(ru) - 2.0.1
|
244
244
|
* Serbian(sr) - 1.91.0 (old)
|
245
|
-
* Spanish(es) - 2.0.
|
245
|
+
* Spanish(es) - 2.0.1
|
246
246
|
* Swedish(sv) - 0.8.0 (too much old)
|
247
|
-
* Ukrainian(ua) - 2.0.
|
248
|
-
* Vietnamese(vi) - 2.0.
|
247
|
+
* Ukrainian(ua) - 2.0.1
|
248
|
+
* Vietnamese(vi) - 2.0.1
|
249
249
|
|
250
250
|
== Maintainer
|
251
251
|
Masao Mutoh <mutomasa at gmail.com>
|
data/Rakefile
CHANGED
@@ -172,7 +172,7 @@ spec = Gem::Specification.new do |s|
|
|
172
172
|
s.require_path = 'lib'
|
173
173
|
s.executables = Dir.entries('bin').delete_if {|item| /^\.|CVS|~$/ =~ item }
|
174
174
|
s.bindir = 'bin'
|
175
|
-
s.add_dependency('locale', '>= 2.0.
|
175
|
+
s.add_dependency('locale', '>= 2.0.1')
|
176
176
|
s.has_rdoc = true
|
177
177
|
s.description = <<-EOF
|
178
178
|
Ruby-GetText-Package is a GNU GetText-like program for Ruby.
|
@@ -216,13 +216,13 @@ Rake::RDocTask.new { |rdoc|
|
|
216
216
|
rdoc.rdoc_dir = 'doc'
|
217
217
|
rdoc.title = "Ruby-GetText-Package API Reference"
|
218
218
|
rdoc.options << '--line-numbers' << '--inline-source'
|
219
|
-
rdoc.rdoc_files.include('README', 'ChangeLog')
|
219
|
+
rdoc.rdoc_files.include('README.rdoc', 'ChangeLog')
|
220
220
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
221
221
|
rdoc.template = allison if allison.size > 0
|
222
222
|
}
|
223
223
|
|
224
224
|
desc "Publish the release files to RubyForge."
|
225
|
-
task :release => [ :package ] do
|
225
|
+
task :release => [:makemo, :package ] do
|
226
226
|
require 'rubyforge'
|
227
227
|
|
228
228
|
rubyforge = RubyForge.new
|
data/lib/gettext.rb
CHANGED
@@ -13,9 +13,19 @@
|
|
13
13
|
$Id: gettext.rb,v 1.46 2008/09/13 18:23:55 mutoh Exp $
|
14
14
|
=end
|
15
15
|
|
16
|
-
|
16
|
+
if respond_to? :gem
|
17
|
+
begin
|
18
|
+
begin
|
19
|
+
gem 'locale', '>=0.9'
|
20
|
+
rescue Gem::LoadError
|
21
|
+
end
|
22
|
+
rescue NoMethodError
|
23
|
+
else LoadError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
17
27
|
require 'locale'
|
18
|
-
raise "
|
28
|
+
raise "Install locale as gem or uninstall old gettext" unless Locale.respond_to? :candidates
|
19
29
|
|
20
30
|
require 'gettext/version'
|
21
31
|
require 'gettext/textdomain_manager'
|
@@ -27,7 +37,7 @@ module GetText
|
|
27
37
|
@domainname = domainname
|
28
38
|
end
|
29
39
|
def message
|
30
|
-
"#{domainname} is not bound."
|
40
|
+
"#{@domainname} is not bound."
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
@@ -53,27 +63,27 @@ module GetText
|
|
53
63
|
# library doesn't use this option. Application may use this once.
|
54
64
|
# * Returns: the GetText::TextDomainManager.
|
55
65
|
#
|
56
|
-
def bindtextdomain(domainname, options
|
57
|
-
bindtextdomain_to(self, domainname, options)
|
66
|
+
def bindtextdomain(domainname, *options)
|
67
|
+
bindtextdomain_to(self, domainname, *options)
|
58
68
|
end
|
59
69
|
|
60
70
|
# Includes GetText module and bind a textdomain to a class.
|
61
71
|
# * klass: the target ruby class.
|
62
72
|
# * domainname: the textdomain name.
|
63
73
|
# * options: options as an Hash. See GetText.bindtextdomain.
|
64
|
-
def bindtextdomain_to(klass, domainname, *
|
65
|
-
if
|
66
|
-
|
74
|
+
def bindtextdomain_to(klass, domainname, *options)
|
75
|
+
if options[0].kind_of? Hash
|
76
|
+
opts = options[0]
|
67
77
|
else
|
68
78
|
# for backward compatibility.
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
opts = {}
|
80
|
+
opts[:path] = options[0] if options[0]
|
81
|
+
opts[:output_charset] = options[2] if options[2]
|
72
82
|
end
|
73
83
|
unless (klass.kind_of? GetText or klass.include? GetText)
|
74
84
|
klass.__send__(:include, GetText)
|
75
85
|
end
|
76
|
-
TextDomainManager.bind_to(klass, domainname,
|
86
|
+
TextDomainManager.bind_to(klass, domainname, opts)
|
77
87
|
end
|
78
88
|
|
79
89
|
# Binds a existed textdomain to your program.
|
@@ -118,7 +128,7 @@ module GetText
|
|
118
128
|
# * msgid: the message id.
|
119
129
|
# * Returns: localized text by msgid. If there are not binded mo-file, it will return msgid.
|
120
130
|
def gettext(msgid)
|
121
|
-
TextDomainManager.
|
131
|
+
TextDomainManager.translate_singluar_message(self, msgid)
|
122
132
|
end
|
123
133
|
|
124
134
|
# call-seq:
|
@@ -135,7 +145,7 @@ module GetText
|
|
135
145
|
# <tt>Movie|Location -> Location</tt>
|
136
146
|
# See: http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151
|
137
147
|
def sgettext(msgid, seperator = "|")
|
138
|
-
TextDomainManager.
|
148
|
+
TextDomainManager.translate_singluar_message(self, msgid, seperator)
|
139
149
|
end
|
140
150
|
|
141
151
|
# call-seq:
|
@@ -152,7 +162,7 @@ module GetText
|
|
152
162
|
# it returns msgid.
|
153
163
|
# See: http://www.gnu.org/software/autoconf/manual/gettext/Contexts.html
|
154
164
|
def pgettext(msgctxt, msgid)
|
155
|
-
TextDomainManager.
|
165
|
+
TextDomainManager.translate_singluar_message(self, "#{msgctxt}\004#{msgid}", "\004")
|
156
166
|
end
|
157
167
|
|
158
168
|
# call-seq:
|
@@ -170,7 +180,7 @@ module GetText
|
|
170
180
|
# * Returns: the localized text which key is msgid_plural if n is plural(follow plural-rule) or msgid.
|
171
181
|
# "plural-rule" is defined in po-file.
|
172
182
|
def ngettext(msgid, msgid_plural, n = nil)
|
173
|
-
TextDomainManager.
|
183
|
+
TextDomainManager.translate_plural_message(self, msgid, msgid_plural, n)
|
174
184
|
end
|
175
185
|
|
176
186
|
# call-seq:
|
@@ -189,7 +199,7 @@ module GetText
|
|
189
199
|
# * Returns: the localized text which key is msgid_plural if n is plural(follow plural-rule) or msgid.
|
190
200
|
# "plural-rule" is defined in po-file.
|
191
201
|
def nsgettext(msgid, msgid_plural, n="|", seperator = "|")
|
192
|
-
TextDomainManager.
|
202
|
+
TextDomainManager.translate_plural_message(self, msgid, msgid_plural, n, seperator)
|
193
203
|
end
|
194
204
|
|
195
205
|
# call-seq:
|
@@ -221,7 +231,7 @@ module GetText
|
|
221
231
|
opt2 = nil
|
222
232
|
end
|
223
233
|
|
224
|
-
msgstr = TextDomainManager.
|
234
|
+
msgstr = TextDomainManager.translate_plural_message(self, msgid_ctxt, msgid_plural, opt1, opt2)
|
225
235
|
if msgstr == msgid_ctxt
|
226
236
|
msgid
|
227
237
|
else
|
@@ -262,7 +272,10 @@ module GetText
|
|
262
272
|
end
|
263
273
|
|
264
274
|
def set_locale(lang)
|
265
|
-
Locale.
|
275
|
+
Locale.default = lang
|
276
|
+
end
|
277
|
+
|
278
|
+
def set_current_locale(lang)
|
266
279
|
Locale.current = lang
|
267
280
|
end
|
268
281
|
|
@@ -271,6 +284,7 @@ module GetText
|
|
271
284
|
end
|
272
285
|
|
273
286
|
alias :locale= :set_locale #:nodoc:
|
287
|
+
alias :current_locale= :set_current_locale #:nodoc:
|
274
288
|
alias :_ :gettext #:nodoc:
|
275
289
|
alias :n_ :ngettext #:nodoc:
|
276
290
|
alias :s_ :sgettext #:nodoc:
|
data/lib/gettext/class_info.rb
CHANGED
@@ -8,7 +8,7 @@ module GetText
|
|
8
8
|
# normalize the klass name
|
9
9
|
def normalize_class(klass)
|
10
10
|
ret = (klass.kind_of? Module) ? klass : klass.class
|
11
|
-
if ret.name =~ /^\#<|^$/ or ret == GetText
|
11
|
+
if ret.name.to_s =~ /^\#<|^$/ or ret == GetText
|
12
12
|
ret = Object
|
13
13
|
end
|
14
14
|
ret
|
@@ -47,8 +47,11 @@ module GetText
|
|
47
47
|
# (klass's ancestors, included modules and nested modules)
|
48
48
|
def related_classes(klass, all_classes = [])
|
49
49
|
ret = related_classes_internal(klass, all_classes)
|
50
|
-
|
50
|
+
unless ret.include? Object
|
51
|
+
ret += [Object]
|
52
|
+
end
|
53
|
+
ret
|
51
54
|
end
|
52
55
|
memoize :related_classes
|
53
56
|
end
|
54
|
-
end
|
57
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#! /usr/bin/ruby
|
2
1
|
=begin
|
3
2
|
string.rb - Extension for String.
|
4
3
|
|
@@ -9,12 +8,16 @@
|
|
9
8
|
=end
|
10
9
|
|
11
10
|
if RUBY_VERSION < "1.9.0"
|
12
|
-
|
13
11
|
# Extension for String class. This feature is included in Ruby 1.9 or later.
|
14
12
|
#
|
15
13
|
# String#% method which accept "named argument". The translator can know
|
16
14
|
# the meaning of the msgids using "named argument" instead of %s/%d style.
|
17
15
|
class String
|
16
|
+
|
17
|
+
unless respond_to? :bytesize # For older ruby (such as ruby-1.8.5)
|
18
|
+
alias :bytesize :size
|
19
|
+
end
|
20
|
+
|
18
21
|
alias :_old_format_m :% # :nodoc:
|
19
22
|
|
20
23
|
# call-seq:
|
data/lib/gettext/locale_path.rb
CHANGED
@@ -9,59 +9,68 @@
|
|
9
9
|
=end
|
10
10
|
|
11
11
|
require 'rbconfig'
|
12
|
+
require 'gettext/core_ext/string'
|
12
13
|
|
13
14
|
module GetText
|
14
15
|
# Treats locale-path for mo-files.
|
15
16
|
class LocalePath
|
17
|
+
include Locale::Util::Memoizable
|
18
|
+
|
16
19
|
# The default locale paths.
|
17
20
|
CONFIG_PREFIX = Config::CONFIG['prefix'].gsub(/\/local/, "")
|
18
21
|
DEFAULT_RULES = [
|
22
|
+
"./locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
23
|
+
"./locale/%{lang}/%{name}.mo",
|
19
24
|
"#{Config::CONFIG['datadir']}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
20
25
|
"#{Config::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
21
26
|
"#{CONFIG_PREFIX}/share/locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
22
27
|
"#{CONFIG_PREFIX}/local/share/locale/%{lang}/LC_MESSAGES/%{name}.mo"
|
23
28
|
].uniq
|
24
|
-
|
25
|
-
# Add default locale path. Usually you should use GetText.add_default_locale_path instead.
|
26
|
-
# * path: a new locale path. (e.g.) "/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo"
|
27
|
-
# ('locale' => "ja_JP", 'name' => "textdomain")
|
28
|
-
# * Returns: the new DEFAULT_LOCALE_PATHS
|
29
|
-
def self.add_default_rule(path)
|
30
|
-
DEFAULT_RULES.unshift(path)
|
31
|
-
end
|
32
29
|
|
33
|
-
|
30
|
+
class << self
|
31
|
+
include Locale::Util::Memoizable
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
ENV["GETTEXT_PATH"].split(/,/).each {|i|
|
42
|
-
@@default_path_rules = ["#{i}/%{lang}/LC_MESSAGES/%{name}.mo", "#{i}/%{lang}/%{name}.mo"]
|
43
|
-
}
|
33
|
+
# Add default locale path. Usually you should use GetText.add_default_locale_path instead.
|
34
|
+
# * path: a new locale path. (e.g.) "/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo"
|
35
|
+
# ('locale' => "ja_JP", 'name' => "textdomain")
|
36
|
+
# * Returns: the new DEFAULT_LOCALE_PATHS
|
37
|
+
def add_default_rule(path)
|
38
|
+
DEFAULT_RULES.unshift(path)
|
44
39
|
end
|
45
|
-
|
46
|
-
@@default_path_rules += DEFAULT_RULES
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
"#{$1}/data/locale/%{lang}/%{name}.mo",
|
53
|
-
"#{$1}/locale/%{lang}/%{name}.mo"]
|
54
|
-
end
|
55
|
-
}
|
56
|
-
@@default_path_rules.dup
|
57
|
-
end
|
41
|
+
# Returns path rules as an Array.
|
42
|
+
# (e.g.) ["/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo", ...]
|
43
|
+
def default_path_rules
|
44
|
+
default_path_rules = []
|
58
45
|
|
59
|
-
|
60
|
-
|
61
|
-
|
46
|
+
if ENV["GETTEXT_PATH"]
|
47
|
+
ENV["GETTEXT_PATH"].split(/,/).each {|i|
|
48
|
+
default_path_rules = ["#{i}/%{lang}/LC_MESSAGES/%{name}.mo", "#{i}/%{lang}/%{name}.mo"]
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
default_path_rules += DEFAULT_RULES
|
53
|
+
|
54
|
+
load_path = $LOAD_PATH
|
55
|
+
if defined? ::Gem
|
56
|
+
load_path += Gem.all_load_paths.map{|v| v =~ /(.*)\/lib$/; $1}
|
57
|
+
end
|
58
|
+
|
59
|
+
load_path.each {|path|
|
60
|
+
default_path_rules += [
|
61
|
+
"#{path}/data/locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
62
|
+
"#{path}/data/locale/%{lang}/%{name}.mo",
|
63
|
+
"#{path}/locale/%{lang}/%{name}.mo"]
|
64
|
+
}
|
65
|
+
# paths existed only.
|
66
|
+
default_path_rules = default_path_rules.select{|path|
|
67
|
+
Dir.glob(path % {:lang => "*", :name => "*"}).size > 0}.uniq
|
68
|
+
default_path_rules
|
69
|
+
end
|
70
|
+
memoize_dup :default_path_rules
|
62
71
|
end
|
63
72
|
|
64
|
-
attr_reader :locale_paths
|
73
|
+
attr_reader :locale_paths, :supported_locales
|
65
74
|
|
66
75
|
# Creates a new GetText::TextDomain.
|
67
76
|
# * name: the textdomain name.
|
@@ -70,11 +79,22 @@ module GetText
|
|
70
79
|
@name = name
|
71
80
|
|
72
81
|
if topdir
|
73
|
-
|
82
|
+
path_rules = ["#{topdir}/%{lang}/LC_MESSAGES/%{name}.mo", "#{topdir}/%{lang}/%{name}.mo"]
|
74
83
|
else
|
75
|
-
|
84
|
+
path_rules = self.class.default_path_rules
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
@locale_paths = {}
|
89
|
+
path_rules.each do |rule|
|
90
|
+
this_path_rules = rule % {:lang => "([^\/]+)", :name => name}
|
91
|
+
Dir.glob(rule %{:lang => "*", :name => name}).each do |path|
|
92
|
+
if /#{this_path_rules}/ =~ path
|
93
|
+
@locale_paths[$1] = path unless @locale_paths[$1]
|
94
|
+
end
|
95
|
+
end
|
76
96
|
end
|
77
|
-
@locale_paths.
|
97
|
+
@supported_locales = @locale_paths.keys.sort
|
78
98
|
end
|
79
99
|
|
80
100
|
# Gets the current path.
|
@@ -83,25 +103,21 @@ module GetText
|
|
83
103
|
lang_candidates = lang.to_posix.candidates
|
84
104
|
search_files = []
|
85
105
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if File.exist?(fname)
|
93
|
-
warn "GetText::TextDomain#load_mo: mo-file is #{fname}" if $DEBUG
|
94
|
-
return fname
|
95
|
-
end
|
96
|
-
}
|
97
|
-
}
|
106
|
+
lang_candidates.each do |tag|
|
107
|
+
path = @locale_paths[tag.to_s]
|
108
|
+
warn "GetText::TextDomain#load_mo: mo-file is #{path}" if $DEBUG
|
109
|
+
return path if path
|
110
|
+
end
|
111
|
+
|
98
112
|
if $DEBUG
|
99
113
|
warn "MO file is not found in"
|
100
|
-
|
101
|
-
warn " #{
|
114
|
+
@locale_paths.each do |path|
|
115
|
+
warn " #{path}"
|
102
116
|
end
|
103
117
|
end
|
104
118
|
nil
|
105
119
|
end
|
120
|
+
memoize :current_path
|
121
|
+
|
106
122
|
end
|
107
123
|
end
|
data/lib/gettext/mofile.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
=begin
|
2
2
|
mofile.rb - A simple class for operating GNU MO file.
|
3
3
|
|
4
|
-
Copyright (C) 2003-
|
4
|
+
Copyright (C) 2003-2009 Masao Mutoh
|
5
5
|
Copyright (C) 2002 Masahiro Sakai, Masao Mutoh
|
6
6
|
Copyright (C) 2001 Masahiro Sakai
|
7
7
|
|
@@ -12,7 +12,6 @@
|
|
12
12
|
of Ruby. License of Ruby is included with Ruby distribution in
|
13
13
|
the file "README".
|
14
14
|
|
15
|
-
$Id: mo.rb,v 1.10 2008/06/17 16:40:52 mutoh Exp $
|
16
15
|
=end
|
17
16
|
|
18
17
|
require 'gettext/core_ext/iconv'
|
@@ -169,11 +168,18 @@ module GetText
|
|
169
168
|
('1' * number) !~ /^1?$|^(11+?)\1+$/
|
170
169
|
end
|
171
170
|
|
172
|
-
|
173
|
-
require '
|
174
|
-
|
175
|
-
|
176
|
-
|
171
|
+
begin
|
172
|
+
require 'prime'
|
173
|
+
def next_prime(seed)
|
174
|
+
Prime.instance.find{|x| x > seed }
|
175
|
+
end
|
176
|
+
rescue LoadError
|
177
|
+
def next_prime(seed)
|
178
|
+
require 'mathn'
|
179
|
+
prime = Prime.new
|
180
|
+
while current = prime.succ
|
181
|
+
return current if current > seed
|
182
|
+
end
|
177
183
|
end
|
178
184
|
end
|
179
185
|
|
@@ -223,17 +229,17 @@ module GetText
|
|
223
229
|
|
224
230
|
orig_table_data = Array.new()
|
225
231
|
ary.each{|item, _|
|
226
|
-
orig_table_data.push(item.
|
232
|
+
orig_table_data.push(item.bytesize)
|
227
233
|
orig_table_data.push(pos)
|
228
|
-
pos += item.
|
234
|
+
pos += item.bytesize + 1 # +1 is <NUL>
|
229
235
|
}
|
230
236
|
io.write(orig_table_data.pack('V*'))
|
231
237
|
|
232
238
|
trans_table_data = Array.new()
|
233
239
|
ary.each{|_, item|
|
234
|
-
trans_table_data.push(item.
|
240
|
+
trans_table_data.push(item.bytesize)
|
235
241
|
trans_table_data.push(pos)
|
236
|
-
pos += item.
|
242
|
+
pos += item.bytesize + 1 # +1 is <NUL>
|
237
243
|
}
|
238
244
|
io.write(trans_table_data.pack('V*'))
|
239
245
|
|
data/lib/gettext/parser/erb.rb
CHANGED
@@ -30,7 +30,10 @@ module GetText
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def parse(file, targets = []) # :nodoc:
|
33
|
-
|
33
|
+
src = ERB.new(IO.readlines(file).join).src
|
34
|
+
# Remove magic comment prepended by erb in Ruby 1.9.
|
35
|
+
src.sub!(/\A#.*?coding[:=].*?\n/, '') if src.respond_to?(:encode)
|
36
|
+
erb = src.split(/$/)
|
34
37
|
RubyParser.parse_lines(file, erb, targets)
|
35
38
|
end
|
36
39
|
|
data/lib/gettext/textdomain.rb
CHANGED
@@ -112,6 +112,9 @@ module GetText
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
DEFAULT_PLURAL_CALC = Proc.new{|n| "n != 1"}
|
116
|
+
DEFAULT_SINGLE_CALC = Proc.new{|n| 0}
|
117
|
+
|
115
118
|
# Translates the translated string.
|
116
119
|
# * lang: Locale::Tag::Simple's subclass.
|
117
120
|
# * msgid: the original message.
|
@@ -126,11 +129,11 @@ module GetText
|
|
126
129
|
elsif msg.include?("\000")
|
127
130
|
# [[msgstr[0], msgstr[1], msgstr[2],...], cond]
|
128
131
|
mofile = @mofiles[lang.to_posix.to_s]
|
129
|
-
cond = (mofile and mofile != :empty) ? mofile.plural : nil
|
130
|
-
cond ||=
|
132
|
+
cond = (mofile and mofile != :empty) ? Proc.new{|n| eval(mofile.plural)} : nil
|
133
|
+
cond ||= DEFAULT_PLURAL_CALC
|
131
134
|
ret = [msg.split("\000"), cond]
|
132
135
|
else
|
133
|
-
ret = [[msg],
|
136
|
+
ret = [[msg], DEFAULT_SINGLE_CALC]
|
134
137
|
end
|
135
138
|
ret
|
136
139
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
=begin
|
2
|
+
gettext/textdomain_group - GetText::TextDomainGroup class
|
3
|
+
|
4
|
+
Copyright (C) 2009 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby.
|
8
|
+
|
9
|
+
=end
|
10
|
+
|
11
|
+
module GetText
|
12
|
+
|
13
|
+
class TextDomainGroup
|
14
|
+
attr_reader :textdomains, :supported_language_tags
|
15
|
+
|
16
|
+
def initialize(supported_language_tags)
|
17
|
+
@textdomains = []
|
18
|
+
@supported_language_tags = supported_language_tags
|
19
|
+
end
|
20
|
+
|
21
|
+
def add(textdomain)
|
22
|
+
@textdomains.unshift(textdomain) unless @textdomains.include? textdomain
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -8,100 +8,87 @@
|
|
8
8
|
|
9
9
|
=end
|
10
10
|
|
11
|
-
require 'gettext/textdomain'
|
12
11
|
require 'gettext/class_info'
|
13
|
-
require '
|
12
|
+
require 'gettext/textdomain'
|
13
|
+
require 'gettext/textdomain_group'
|
14
14
|
|
15
15
|
module GetText
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
module TextDomainManager
|
18
18
|
|
19
19
|
@@textdomain_pool = {}
|
20
|
-
@@
|
20
|
+
@@textdomain_group_pool = {}
|
21
21
|
|
22
22
|
@@output_charset = nil
|
23
23
|
@@gettext_classes = []
|
24
24
|
|
25
|
+
@@singular_message_cache = {}
|
26
|
+
@@plural_message_cache = {}
|
27
|
+
@@cached = ! $DEBUG
|
28
|
+
|
29
|
+
extend self
|
30
|
+
|
25
31
|
# Find textdomain by name
|
26
|
-
def
|
32
|
+
def textdomain_pool(domainname)
|
27
33
|
@@textdomain_pool[domainname]
|
28
34
|
end
|
29
35
|
|
30
|
-
# create or find a textdomain-manager for an given object/class
|
31
|
-
def self.get(obj)
|
32
|
-
klass = ClassInfo.normalize_class(obj)
|
33
|
-
manager = @@textdomain_manager_pool[klass]
|
34
|
-
return manager if manager
|
35
|
-
@@textdomain_manager_pool[klass] = TextDomainManager.new
|
36
|
-
end
|
37
|
-
|
38
36
|
# Set the value whether cache messages or not.
|
39
37
|
# true to cache messages, otherwise false.
|
40
38
|
#
|
41
39
|
# Default is true. If $DEBUG is false, messages are not checked even if
|
42
40
|
# this value is true.
|
43
|
-
def
|
41
|
+
def cached=(val)
|
42
|
+
@@cached = val
|
44
43
|
TextDomain.cached = val
|
45
44
|
end
|
46
45
|
|
47
46
|
# Return the cached value.
|
48
|
-
def
|
47
|
+
def cached?
|
48
|
+
@@cached
|
49
49
|
TextDomain.cached?
|
50
50
|
end
|
51
51
|
|
52
52
|
# Gets the output charset.
|
53
|
-
def
|
53
|
+
def output_charset
|
54
54
|
@@output_charset
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Sets the output charset.The program can have a output charset.
|
58
|
-
def
|
58
|
+
def output_charset=(charset)
|
59
59
|
@@output_charset = charset
|
60
60
|
@@textdomain_pool.each do |key, textdomain|
|
61
61
|
textdomain.output_charset = charset
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
# bind textdomain to the class.
|
66
|
-
def
|
66
|
+
def bind_to(klass, domainname, options = {})
|
67
67
|
warn "Bind the domain '#{domainname}' to '#{klass}'. " if $DEBUG
|
68
68
|
|
69
69
|
charset = options[:output_charset] || self.output_charset
|
70
70
|
textdomain = create_or_find_textdomain(domainname,options[:path],charset)
|
71
71
|
|
72
72
|
target_klass = ClassInfo.normalize_class(klass)
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
create_or_find_textdomain_group(target_klass, options[:supported_language_tags]).add(textdomain)
|
74
|
+
@@gettext_classes << target_klass unless @@gettext_classes.include? target_klass
|
75
|
+
|
76
76
|
textdomain
|
77
77
|
end
|
78
|
-
|
79
|
-
def
|
78
|
+
|
79
|
+
def each_textdomains(klass) #:nodoc:
|
80
80
|
ClassInfo.related_classes(klass, @@gettext_classes).each do |target|
|
81
81
|
msg = nil
|
82
|
-
|
83
|
-
|
82
|
+
if group = @@textdomain_group_pool[target]
|
83
|
+
lang = Locale.candidates(:supported_language_tags => group.supported_language_tags,
|
84
|
+
:type => :posix)[0]
|
85
|
+
group.textdomains.each do |textdomain|
|
86
|
+
yield textdomain, lang
|
87
|
+
end
|
84
88
|
end
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
88
|
-
#
|
89
|
-
# Instance methods
|
90
|
-
#
|
91
|
-
|
92
|
-
# Returns the textdoman in the instance.
|
93
|
-
attr_reader :textdomains, :supported_language_tags
|
94
|
-
|
95
|
-
def initialize
|
96
|
-
@textdomains = []
|
97
|
-
@supported_language_tags = nil
|
98
|
-
end
|
99
|
-
|
100
|
-
def add(textdomain, supported_language_tags)
|
101
|
-
@textdomains.unshift(textdomain) unless @textdomains.include? textdomain
|
102
|
-
@supported_language_tags = supported_language_tags if supported_language_tags
|
103
|
-
end
|
104
|
-
|
105
92
|
# Translates msgid, but if there are no localized text,
|
106
93
|
# it returns a last part of msgid separeted "div" or whole of the msgid with no "div".
|
107
94
|
#
|
@@ -109,16 +96,12 @@ module GetText
|
|
109
96
|
# * div: separator or nil.
|
110
97
|
# * Returns: the localized text by msgid. If there are no localized text,
|
111
98
|
# it returns a last part of msgid separeted "div".
|
112
|
-
def translate_singluar_message(klass, msgid, div =
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
def translate_singluar_message_to(lang, klass, msgid, div = '|') #:nodoc:
|
119
|
-
msg = nil
|
99
|
+
def translate_singluar_message(klass, msgid, div = nil)
|
100
|
+
key = [Locale.current, klass, msgid, div].hash
|
101
|
+
msg = @@singular_message_cache[key]
|
102
|
+
return msg if msg and @@cached
|
120
103
|
# Find messages from related classes.
|
121
|
-
|
104
|
+
each_textdomains(klass) do |textdomain, lang|
|
122
105
|
msg = textdomain.translate_singluar_message(lang, msgid)
|
123
106
|
break if msg
|
124
107
|
end
|
@@ -130,10 +113,9 @@ module GetText
|
|
130
113
|
msg = msg[(index + 1)..-1]
|
131
114
|
end
|
132
115
|
end
|
133
|
-
msg
|
116
|
+
@@singular_message_cache[key] = msg
|
134
117
|
end
|
135
|
-
|
136
|
-
|
118
|
+
|
137
119
|
# This function is similar to the get_singluar_message function
|
138
120
|
# as it finds the message catalogs in the same way.
|
139
121
|
# But it takes two extra arguments for plural form.
|
@@ -157,12 +139,6 @@ module GetText
|
|
157
139
|
# * n: a number used to determine the plural form.
|
158
140
|
# * div: the separator. Default is "|".
|
159
141
|
def translate_plural_message(klass, arg1, arg2, arg3 = "|", arg4 = "|")
|
160
|
-
lang = Locale.candidates(:supported_language_tags => @supported_language_tags,
|
161
|
-
:type => :posix)[0]
|
162
|
-
translate_plural_message_to(lang, klass, arg1, arg2, arg3, arg4)
|
163
|
-
end
|
164
|
-
|
165
|
-
def translate_plural_message_to(lang, klass, arg1, arg2, arg3 = "|", arg4 = "|")
|
166
142
|
# parse arguments
|
167
143
|
if arg1.kind_of?(Array)
|
168
144
|
msgid = arg1[0]
|
@@ -179,45 +155,53 @@ module GetText
|
|
179
155
|
div = arg4
|
180
156
|
end
|
181
157
|
|
182
|
-
|
183
|
-
msgs =
|
184
|
-
|
185
|
-
msgs = textdomain.translate_plural_message(lang, msgid, msgid_plural)
|
186
|
-
break if msgs
|
187
|
-
end
|
188
|
-
|
189
|
-
# If not found, return msgid.
|
190
|
-
msgs = [[msgid, msgid_plural], "n != 1"] unless msgs
|
158
|
+
key = [Locale.current, klass, msgid, msgid_plural, div].hash
|
159
|
+
msgs = @@plural_message_cache[key]
|
160
|
+
unless (msgs and @@cached)
|
191
161
|
|
192
|
-
|
193
|
-
|
194
|
-
|
162
|
+
# Find messages from related classes.
|
163
|
+
msgs = nil
|
164
|
+
each_textdomains(klass) do |textdomain, lang|
|
165
|
+
msgs = textdomain.translate_plural_message(lang, msgid, msgid_plural)
|
166
|
+
break if msgs
|
167
|
+
end
|
168
|
+
|
169
|
+
msgs = [[msgid, msgid_plural], Proc.new{|n| eval("n != 1")}] unless msgs
|
170
|
+
|
171
|
+
msgstrs = msgs[0]
|
172
|
+
if div and msgstrs[0] == msgid and index = msgstrs[0].rindex(div)
|
173
|
+
msgstrs[0] = msgstrs[0][(index + 1)..-1]
|
174
|
+
end
|
175
|
+
@@plural_message_cache[key] = msgs
|
195
176
|
end
|
196
177
|
|
197
178
|
# Return the singular or plural message.
|
198
|
-
|
179
|
+
msgstrs = msgs[0]
|
180
|
+
plural = msgs[1].call(n)
|
199
181
|
return msgstrs[plural] if plural.kind_of?(Numeric)
|
200
182
|
return plural ? msgstrs[1] : msgstrs[0]
|
201
183
|
end
|
202
|
-
memoize :translate_plural_message_to unless $DEBUG
|
203
184
|
|
204
185
|
# for testing.
|
205
|
-
def
|
186
|
+
def clear_all_textdomains
|
206
187
|
@@textdomain_pool = {}
|
207
|
-
@@
|
188
|
+
@@textdomain_group_pool = {}
|
208
189
|
@@gettext_classes = []
|
190
|
+
@@singular_message_cache = {}
|
191
|
+
@@plural_message_cache = {}
|
209
192
|
end
|
210
|
-
|
211
|
-
private
|
212
193
|
|
213
|
-
def
|
214
|
-
|
194
|
+
def create_or_find_textdomain_group(klass, supported_language_tags = nil) #:nodoc:
|
195
|
+
group = @@textdomain_group_pool[klass]
|
196
|
+
return group if group
|
197
|
+
|
198
|
+
@@textdomain_group_pool[klass] = TextDomainGroup.new(supported_language_tags)
|
215
199
|
end
|
216
|
-
|
217
|
-
def
|
200
|
+
|
201
|
+
def create_or_find_textdomain(name, path, charset)#:nodoc:
|
218
202
|
textdomain = @@textdomain_pool[name]
|
219
203
|
return textdomain if textdomain
|
220
|
-
|
204
|
+
|
221
205
|
@@textdomain_pool[name] = TextDomain.new(name, path, charset)
|
222
206
|
end
|
223
207
|
end
|
data/lib/gettext/tools.rb
CHANGED
@@ -188,6 +188,25 @@ module GetText
|
|
188
188
|
mo_dir = mo_dir_rule % {:lang => lang}
|
189
189
|
File.join(mo_dir, "#{textdomain}.mo")
|
190
190
|
end
|
191
|
+
|
192
|
+
# In Ruby 1.9, we must detect proper encoding of a PO file.
|
193
|
+
def po_file_content(po_file)
|
194
|
+
args = [ po_file ]
|
195
|
+
if String.instance_methods.include?(:encode)
|
196
|
+
encoding = detect_po_file_encoding(po_file)
|
197
|
+
args << "r:#{encoding}"
|
198
|
+
end
|
199
|
+
File.open(*args) {|io| io.read }
|
200
|
+
end
|
201
|
+
|
202
|
+
def detect_po_file_encoding(po_file)
|
203
|
+
open(po_file, :encoding => 'ASCII-8BIT') do |input|
|
204
|
+
input.lines.each do |line|
|
205
|
+
return Encoding.find($1) if %r["Content-Type:.*\scharset=(.*)\\n"] =~ line
|
206
|
+
end
|
207
|
+
end
|
208
|
+
Encoding.default_external
|
209
|
+
end
|
191
210
|
end
|
192
211
|
|
193
212
|
if __FILE__ == $0
|
data/lib/gettext/version.rb
CHANGED
data/test/Rakefile
CHANGED
Binary file
|
@@ -6,7 +6,7 @@
|
|
6
6
|
msgid ""
|
7
7
|
msgstr ""
|
8
8
|
"Project-Id-Version: PACKAGE VERSION\n"
|
9
|
-
"POT-Creation-Date:
|
9
|
+
"POT-Creation-Date: 2001-10-28 01:39:53+0900\n"
|
10
10
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
11
11
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
12
12
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
@@ -14,10 +14,6 @@ msgstr ""
|
|
14
14
|
"Content-Type: text/plain; charset=utf-8\n"
|
15
15
|
"Content-Transfer-Encoding: ENCODING\n"
|
16
16
|
|
17
|
-
#:
|
17
|
+
#: test.rb:9 test.rb:11
|
18
18
|
msgid "language"
|
19
|
-
msgstr "
|
20
|
-
|
21
|
-
#: testlib1.rb:14
|
22
|
-
msgid "one is %d."
|
23
|
-
msgstr "ONE IS %d."
|
19
|
+
msgstr "JAPANESE"
|
data/test/test_class_info.rb
CHANGED
@@ -66,7 +66,6 @@ class TestClassInfo < Test::Unit::TestCase
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_rellated_classes_with_all_classes
|
69
|
-
# Evertime Object is returned as the fallback object.
|
70
69
|
assert_equal [M1, Object], related_classes(M1, [M1])
|
71
70
|
assert_equal [M1, Object], related_classes(M1::M3::M4, [M1])
|
72
71
|
assert_equal [M1::M3, Object], related_classes(M1::M3::M4, [M1::M3])
|
data/test/test_gettext.rb
CHANGED
data/test/test_locale_path.rb
CHANGED
@@ -12,6 +12,8 @@ class TestLocalePath < Test::Unit::TestCase
|
|
12
12
|
assert_equal("japanese", test.test)
|
13
13
|
prefix = GetText::LocalePath::CONFIG_PREFIX
|
14
14
|
default_locale_dirs = [
|
15
|
+
"./locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
16
|
+
"./locale/%{lang}/%{name}.mo",
|
15
17
|
"#{Config::CONFIG['datadir']}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
16
18
|
"#{Config::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
17
19
|
"#{prefix}/share/locale/%{lang}/LC_MESSAGES/%{name}.mo",
|
@@ -26,12 +28,23 @@ class TestLocalePath < Test::Unit::TestCase
|
|
26
28
|
def test_initialize_with_topdir
|
27
29
|
testdir = File.dirname(File.expand_path(__FILE__))
|
28
30
|
path = GetText::LocalePath.new("test1", "#{testdir}/locale")
|
29
|
-
assert_equal path.locale_paths,
|
30
|
-
"#{testdir}/locale
|
31
|
+
assert_equal path.locale_paths, { "ja" => "#{testdir}/locale/ja/LC_MESSAGES/test1.mo",
|
32
|
+
"fr" => "#{testdir}/locale/fr/LC_MESSAGES/test1.mo"}
|
31
33
|
assert_equal path.current_path(Locale::Tag.parse("ja")), "#{testdir}/locale/ja/LC_MESSAGES/test1.mo"
|
32
34
|
assert_equal path.current_path(Locale::Tag.parse("ja-JP")), "#{testdir}/locale/ja/LC_MESSAGES/test1.mo"
|
33
35
|
assert_equal path.current_path(Locale::Tag.parse("ja_JP.UTF-8")), "#{testdir}/locale/ja/LC_MESSAGES/test1.mo"
|
34
36
|
assert_equal path.current_path(Locale::Tag.parse("en")), nil
|
35
37
|
end
|
36
38
|
|
39
|
+
def test_supported_locales
|
40
|
+
testdir = File.dirname(File.expand_path(__FILE__))
|
41
|
+
path = GetText::LocalePath.new("test1", "#{testdir}/locale")
|
42
|
+
assert_equal ["fr", "ja"], path.supported_locales
|
43
|
+
|
44
|
+
path = GetText::LocalePath.new("plural", "#{testdir}/locale")
|
45
|
+
assert_equal ["cr", "da", "fr", "ir", "ja", "la", "li", "po", "sl"], path.supported_locales
|
46
|
+
|
47
|
+
path = GetText::LocalePath.new("nodomain", "#{testdir}/locale")
|
48
|
+
assert_equal [], path.supported_locales
|
49
|
+
end
|
37
50
|
end
|
data/test/test_parser.rb
CHANGED
@@ -92,20 +92,20 @@ class TestGetTextParser < Test::Unit::TestCase
|
|
92
92
|
|
93
93
|
def test_rgettext_parse
|
94
94
|
GetText::ErbParser.init(:extnames => ['.rhtml', '.rxml'])
|
95
|
-
ary = GetText::RGetText.parse('testlib/erb.rhtml')
|
95
|
+
ary = GetText::RGetText.parse(['testlib/erb.rhtml'])
|
96
96
|
assert_equal(['aaa', 'testlib/erb.rhtml:8'], ary[0])
|
97
97
|
assert_equal(['aaa\n', 'testlib/erb.rhtml:11'], ary[1])
|
98
98
|
assert_equal(['bbb', 'testlib/erb.rhtml:12'], ary[2])
|
99
99
|
assert_equal(["ccc1\000ccc2", 'testlib/erb.rhtml:13'], ary[3])
|
100
100
|
|
101
|
-
ary = GetText::RGetText.parse('testlib/erb.rxml')
|
101
|
+
ary = GetText::RGetText.parse(['testlib/erb.rxml'])
|
102
102
|
assert_equal(['aaa', 'testlib/erb.rxml:9'], ary[0])
|
103
103
|
assert_equal(['aaa\n', 'testlib/erb.rxml:12'], ary[1])
|
104
104
|
assert_equal(['bbb', 'testlib/erb.rxml:13'], ary[2])
|
105
105
|
assert_equal(["ccc1\000ccc2", 'testlib/erb.rxml:14'], ary[3])
|
106
106
|
|
107
107
|
|
108
|
-
ary = GetText::RGetText.parse('testlib/ngettext.rb')
|
108
|
+
ary = GetText::RGetText.parse(['testlib/ngettext.rb'])
|
109
109
|
assert_equal(["ooo\000ppp", 'testlib/ngettext.rb:64', 'testlib/ngettext.rb:65'], ary[12])
|
110
110
|
assert_equal(["qqq\000rrr", 'testlib/ngettext.rb:69', 'testlib/ngettext.rb:70'], ary[13])
|
111
111
|
end
|
data/test/test_string.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'testlib/helper.rb'
|
2
2
|
|
3
3
|
class TestGetTextString < Test::Unit::TestCase
|
4
|
-
def
|
4
|
+
def test_sprintf
|
5
5
|
assert_equal("foo is a number", "%{msg} is a number" % {:msg => "foo"})
|
6
6
|
assert_equal("bar is a number", "%s is a number" % ["bar"])
|
7
7
|
assert_equal("bar is a number", "%s is a number" % "bar")
|
@@ -11,4 +11,26 @@ class TestGetTextString < Test::Unit::TestCase
|
|
11
11
|
assert_equal("test, 1", "%2$s, %1$d" % [1, "test"])
|
12
12
|
assert_raise(ArgumentError) { "%-%" % [1] }
|
13
13
|
end
|
14
|
+
|
15
|
+
=begin
|
16
|
+
def test_sprintf_lack_argument
|
17
|
+
assert_equal("%{num}, test", "%{num}, %{record}" % {:record => "test"})
|
18
|
+
assert_equal("%{record}", "%{record}" % {:num => 1})
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_sprintf_ruby19
|
22
|
+
assert_equal("1", "%<num>d" % {:num => 1})
|
23
|
+
assert_equal("1", "%<num>#b" % {:num => 1})
|
24
|
+
assert_equal("foo", "%<msg>s" % {:msg => "foo"})
|
25
|
+
assert_equal("1.000000", "%<num>f" % {:num => 1.0})
|
26
|
+
assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
|
27
|
+
assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
|
28
|
+
assert_equal("0x64", "%<num>#x" % {:num => 100.0})
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_percent
|
32
|
+
assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
|
33
|
+
end
|
34
|
+
=end
|
35
|
+
|
14
36
|
end
|
@@ -11,7 +11,7 @@ class TestGetTextBind < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
def test_bindtextdomain
|
13
13
|
domain = GetText.bindtextdomain("foo")
|
14
|
-
assert_equal domain, GetText::TextDomainManager.
|
14
|
+
assert_equal domain, GetText::TextDomainManager.create_or_find_textdomain_group(Object).textdomains[0]
|
15
15
|
assert_equal domain, GetText::TextDomainManager.textdomain_pool("foo")
|
16
16
|
end
|
17
17
|
|
@@ -2,6 +2,7 @@ require 'testlib/helper.rb'
|
|
2
2
|
require 'testlib/multi_textdomain.rb'
|
3
3
|
|
4
4
|
class TestGetTextMulti < Test::Unit::TestCase
|
5
|
+
|
5
6
|
def setup
|
6
7
|
GetText.locale = "ja_JP.EUC-JP"
|
7
8
|
end
|
@@ -65,5 +66,14 @@ class TestGetTextMulti < Test::Unit::TestCase
|
|
65
66
|
assert_equal("no data", test.test3) # No po file.
|
66
67
|
end
|
67
68
|
|
69
|
+
def test_same_msgid_but_different_textdomain
|
70
|
+
test1 = C12.new # test1 domain
|
71
|
+
test2 = C51.new # test3 domain
|
72
|
+
test3 = C52.new # test3 domain but inherited C11.
|
73
|
+
|
74
|
+
assert_equal("japanese", test1.test) # Use text1 message
|
75
|
+
assert_equal("JAPANESE", test2.test) # Use text3 message
|
76
|
+
assert_equal("JAPANESE", test3.test) # Use text3 message
|
77
|
+
end
|
68
78
|
|
69
79
|
end
|
data/test/test_thread.rb
CHANGED
@@ -15,7 +15,7 @@ class TestThread < Test::Unit::TestCase
|
|
15
15
|
Thread.start do
|
16
16
|
@mutex.synchronize {
|
17
17
|
Thread.current["language"] = language
|
18
|
-
GetText.
|
18
|
+
GetText.current_locale = tag
|
19
19
|
}
|
20
20
|
(1..10).each do |v|
|
21
21
|
assert_equal Thread.current["language"], _("language")
|
@@ -117,3 +117,15 @@ class C4 < C3
|
|
117
117
|
_("no data")
|
118
118
|
end
|
119
119
|
end
|
120
|
+
|
121
|
+
class C51
|
122
|
+
include GetText
|
123
|
+
bindtextdomain("test3", :path => "locale")
|
124
|
+
def test
|
125
|
+
_("language")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class C52 < C12
|
130
|
+
bindtextdomain("test3", :path => "locale")
|
131
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gettext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Mutoh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-19 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.0.
|
23
|
+
version: 2.0.1
|
24
24
|
version:
|
25
25
|
description: Ruby-GetText-Package is a GNU GetText-like program for Ruby. The catalog file(po-file) is same format with GNU GetText. So you can use GNU GetText tools for maintaining.
|
26
26
|
email: mutomasa at gmail.com
|
@@ -828,6 +828,7 @@ files:
|
|
828
828
|
- lib/gettext/poparser.rb
|
829
829
|
- lib/gettext/textdomain.rb
|
830
830
|
- lib/gettext/textdomain_manager.rb
|
831
|
+
- lib/gettext/textdomain_group.rb
|
831
832
|
- lib/gettext/utils.rb
|
832
833
|
- lib/gettext/version.rb
|
833
834
|
- lib/gettext/mofile.rb
|
@@ -860,7 +861,6 @@ files:
|
|
860
861
|
- test/po/sl
|
861
862
|
- test/po/sl/plural.po
|
862
863
|
- test/po/fr
|
863
|
-
- test/po/fr/test6.po
|
864
864
|
- test/po/fr/plural_error.po
|
865
865
|
- test/po/fr/plural.po
|
866
866
|
- test/po/fr/test2.po
|
@@ -868,12 +868,12 @@ files:
|
|
868
868
|
- test/po/li
|
869
869
|
- test/po/li/plural.po
|
870
870
|
- test/po/ja
|
871
|
-
- test/po/ja/test6.po
|
872
871
|
- test/po/ja/pgettext.po
|
873
872
|
- test/po/ja/sgettext.po
|
874
873
|
- test/po/ja/nsgettext.po
|
875
874
|
- test/po/ja/plural_error.po
|
876
875
|
- test/po/ja/rubyparser.po
|
876
|
+
- test/po/ja/test3.po
|
877
877
|
- test/po/ja/plural.po
|
878
878
|
- test/po/ja/test2.po
|
879
879
|
- test/po/ja/npgettext.po
|
@@ -902,7 +902,6 @@ files:
|
|
902
902
|
- test/locale/sl/LC_MESSAGES/plural.mo
|
903
903
|
- test/locale/fr
|
904
904
|
- test/locale/fr/LC_MESSAGES
|
905
|
-
- test/locale/fr/LC_MESSAGES/test6.mo
|
906
905
|
- test/locale/fr/LC_MESSAGES/plural_error.mo
|
907
906
|
- test/locale/fr/LC_MESSAGES/test2.mo
|
908
907
|
- test/locale/fr/LC_MESSAGES/plural.mo
|
@@ -912,7 +911,6 @@ files:
|
|
912
911
|
- test/locale/li/LC_MESSAGES/plural.mo
|
913
912
|
- test/locale/ja
|
914
913
|
- test/locale/ja/LC_MESSAGES
|
915
|
-
- test/locale/ja/LC_MESSAGES/test6.mo
|
916
914
|
- test/locale/ja/LC_MESSAGES/plural_error.mo
|
917
915
|
- test/locale/ja/LC_MESSAGES/pgettext.mo
|
918
916
|
- test/locale/ja/LC_MESSAGES/test2.mo
|
@@ -921,6 +919,7 @@ files:
|
|
921
919
|
- test/locale/ja/LC_MESSAGES/npgettext.mo
|
922
920
|
- test/locale/ja/LC_MESSAGES/rubyparser.mo
|
923
921
|
- test/locale/ja/LC_MESSAGES/nsgettext.mo
|
922
|
+
- test/locale/ja/LC_MESSAGES/test3.mo
|
924
923
|
- test/locale/ja/LC_MESSAGES/test1.mo
|
925
924
|
- test/locale/cr
|
926
925
|
- test/locale/cr/LC_MESSAGES
|
Binary file
|
Binary file
|
data/test/po/ja/test6.po
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# SOME DESCRIPTIVE TITLE.
|
2
|
-
# Copyright (C) YEAR ORGANIZATION
|
3
|
-
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
4
|
-
#
|
5
|
-
#, fuzzy
|
6
|
-
msgid ""
|
7
|
-
msgstr ""
|
8
|
-
"Project-Id-Version: PACKAGE VERSION\n"
|
9
|
-
"POT-Creation-Date: 2002-01-01 02:24:56+0900\n"
|
10
|
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
11
|
-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
12
|
-
"Language-Team: LANGUAGE <LL@li.org>\n"
|
13
|
-
"MIME-Version: 1.0\n"
|
14
|
-
"Content-Type: text/plain; charset=utf-8\n"
|
15
|
-
"Content-Transfer-Encoding: ENCODING\n"
|
16
|
-
|
17
|
-
#: testlib1.rb:10
|
18
|
-
msgid "language"
|
19
|
-
msgstr "japanese"
|
20
|
-
|
21
|
-
#: testlib1.rb:14
|
22
|
-
msgid "one is %d."
|
23
|
-
msgstr "ONE IS %d."
|