gettext 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +128 -0
- data/NEWS +10 -0
- data/README +21 -23
- data/Rakefile +39 -20
- data/bin/rgettext +1 -1
- data/bin/rmsgfmt +1 -1
- data/bin/rmsgmerge +1 -1
- data/data/locale/cs/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/es/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
- data/ext/gettext/extconf.rb +20 -0
- data/ext/gettext/{gettext/_locale.c → locale_system.c} +15 -19
- data/lib/gettext.rb +186 -38
- data/lib/gettext/cgi.rb +35 -69
- data/lib/gettext/container.rb +14 -5
- data/lib/gettext/erb.rb +30 -2
- data/lib/gettext/iconv.rb +19 -4
- data/lib/gettext/locale.rb +188 -39
- data/lib/gettext/locale_cgi.rb +102 -0
- data/lib/gettext/locale_object.rb +131 -0
- data/lib/gettext/locale_posix.rb +50 -0
- data/lib/gettext/locale_table_win32.rb +224 -182
- data/lib/gettext/locale_win32.rb +59 -35
- data/lib/gettext/mo.rb +2 -2
- data/lib/gettext/parser/activerecord.rb +19 -5
- data/lib/gettext/parser/erb.rb +6 -3
- data/lib/gettext/parser/glade.rb +5 -5
- data/lib/gettext/parser/ruby.rb +6 -6
- data/lib/gettext/poparser.rb +7 -6
- data/lib/gettext/rails.rb +122 -44
- data/lib/gettext/rgettext.rb +21 -8
- data/lib/gettext/rmsgfmt.rb +16 -8
- data/lib/gettext/rmsgmerge.rb +172 -50
- data/lib/gettext/string.rb +25 -3
- data/lib/gettext/textdomain.rb +89 -90
- data/lib/gettext/utils.rb +63 -3
- data/lib/gettext/version.rb +2 -2
- data/pkg/ruby-gettext-package-1.2.0/ext/gettext/extconf.rb +20 -0
- data/po/cs/rails.po +28 -28
- data/po/cs/rgettext.po +14 -14
- data/po/de/rails.po +29 -26
- data/po/de/rgettext.po +24 -17
- data/po/el/rails.po +26 -26
- data/po/el/rgettext.po +18 -15
- data/po/es/rails.po +26 -26
- data/po/es/rgettext.po +16 -16
- data/po/fr/rails.po +27 -27
- data/po/fr/rgettext.po +14 -14
- data/po/it/rgettext.po +14 -14
- data/po/ja/rails.po +24 -24
- data/po/ja/rgettext.po +14 -14
- data/po/ko/rails.po +24 -24
- data/po/ko/rgettext.po +17 -18
- data/po/nl/rails.po +27 -27
- data/po/nl/rgettext.po +18 -18
- data/po/pt_BR/rails.po +26 -26
- data/po/pt_BR/rgettext.po +14 -14
- data/po/rails.pot +26 -26
- data/po/rgettext.pot +14 -14
- data/po/sv/rgettext.po +14 -14
- data/post-setup.rb +8 -3
- data/pre-setup.rb +14 -1
- data/samples/cgi/http.rb +2 -1
- data/samples/makemo.rb +1 -1
- data/samples/rails/app/models/article.rb +15 -1
- data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/el/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/po/blog.pot +1 -1
- data/samples/rails/po/cs/blog.po +1 -2
- data/samples/rails/po/cs/gettext_plugin.po +1 -1
- data/samples/rails/po/de/blog.po +1 -2
- data/samples/rails/po/de/gettext_plugin.po +1 -1
- data/samples/rails/po/el/blog.po +1 -1
- data/samples/rails/po/el/gettext_plugin.po +1 -1
- data/samples/rails/po/en/blog.po +1 -1
- data/samples/rails/po/es/blog.po +1 -2
- data/samples/rails/po/es/gettext_plugin.po +1 -1
- data/samples/rails/po/fr/blog.po +1 -1
- data/samples/rails/po/fr/gettext_plugin.po +1 -1
- data/samples/rails/po/gettext_plugin.pot +1 -1
- data/samples/rails/po/ja/blog.po +2 -1
- data/samples/rails/po/ja/gettext_plugin.po +1 -1
- data/samples/rails/po/ko/blog.po +1 -2
- data/samples/rails/po/ko/gettext_plugin.po +1 -1
- data/samples/rails/po/nl/blog.po +1 -3
- data/samples/rails/po/nl/gettext_plugin.po +1 -1
- data/samples/rails/po/pt_BR/blog.po +1 -1
- data/samples/rails/po/pt_BR/gettext_plugin.po +1 -1
- data/setup.rb +799 -574
- data/src/poparser.ry +6 -5
- data/test/gettext_runner.rb +3 -1
- data/test/gettext_test.rb +40 -24
- data/test/gettext_test_cgi.rb +60 -6
- data/test/gettext_test_locale.rb +136 -0
- data/test/gettext_test_parser.rb +12 -12
- data/test/locale/la/LC_MESSAGES/plural_error.mo +0 -0
- data/test/po/la/plural_error.po +21 -0
- data/test/test.bat +2 -0
- data/test/test.sh +2 -4
- data/test/{test_rubyparser_n.rb → test_rubyparser_n_.rb} +0 -0
- metadata +17 -12
- data/ext/gettext/gettext/MANIFEST +0 -3
- data/ext/gettext/gettext/extconf.rb +0 -20
- data/lib/gettext/locale_default.rb +0 -35
data/lib/gettext.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
You may redistribute it and/or modify it under the same
|
11
11
|
license terms as Ruby.
|
12
12
|
|
13
|
-
$Id: gettext.rb,v 1.
|
13
|
+
$Id: gettext.rb,v 1.8 2006/02/20 12:35:06 mutoh Exp $
|
14
14
|
=end
|
15
15
|
|
16
16
|
require 'rbconfig'
|
@@ -21,67 +21,147 @@ require 'gettext/textdomain'
|
|
21
21
|
require 'gettext/string'
|
22
22
|
|
23
23
|
module GetText
|
24
|
+
# If the textdomain isn't bound when calling GetText.textdomain, this error is raised.
|
24
25
|
class NoboundTextDomainError < RuntimeError
|
25
26
|
end
|
26
27
|
|
27
28
|
@@__textdomain = Hash.new
|
28
29
|
@@__textdomain_key = Hash.new
|
29
30
|
|
30
|
-
@@
|
31
|
-
@@locale = nil
|
31
|
+
@@__output_charset = nil
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
# Bind a textdomain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to your program.
|
34
|
+
# Normally, the texdomain scope becomes a ruby-script-file.
|
35
|
+
# So you need to call this function each ruby-script-files.
|
36
|
+
# On the other hand, if you call this function under GetText::Container
|
37
|
+
#(gettext/container, gettext/erb, gettext/rails), the textdomain scope becomes a Class/Module.
|
38
|
+
#
|
39
|
+
# * domainname: the textdomain name.
|
40
|
+
# * path: the path to the mo-files. When the value is nil, it will search default paths such as
|
41
|
+
# /usr/share/locale, /usr/local/share/locale)
|
42
|
+
# * locale: the locale string such as "ja_JP.UTF-8". Generally, you should use GetText.set_locale instead.
|
43
|
+
# the value is searched order by:
|
44
|
+
#
|
45
|
+
# the value of this value > System default language.
|
46
|
+
#
|
47
|
+
# * charset: output charset. This affect the current textdomain only. Generally, you should use GetText.set_output_charset instead.
|
48
|
+
# the value is searched order by:
|
49
|
+
#
|
50
|
+
# the value of Locale.set_output_charset > ENV["OUTPUT_CHARSET"] > this value > System default charset.
|
51
|
+
# * Returns: the GetText::TextDomain.
|
52
|
+
#
|
53
|
+
def bindtextdomain(domainname, path = nil, locale_ = nil, charset = nil)
|
54
|
+
locale = locale_ ? Locale::Object.new(locale_) : Locale.get
|
55
|
+
if @@__output_charset
|
56
|
+
# Set global setting forcely.
|
57
|
+
charset = @@__output_charset
|
37
58
|
else
|
38
|
-
|
39
|
-
|
40
|
-
if @@output_charset
|
41
|
-
charset = @@output_charset
|
42
|
-
else
|
43
|
-
charset ||= ENV["OUTPUT_CHARSET"] ? ENV["OUTPUT_CHARSET"] : Locale.codeset
|
44
|
-
@@output_charset = charset
|
59
|
+
charset = ENV["OUTPUT_CHARSET"] if ENV["OUTPUT_CHARSET"]
|
60
|
+
@@__output_charset = charset
|
45
61
|
end
|
62
|
+
locale.charset = charset if charset
|
63
|
+
Locale.set_current(locale)
|
64
|
+
|
46
65
|
src = callersrc
|
47
|
-
$stderr.print "bind the domain '#{domainname}' to '#{src}'.
|
66
|
+
$stderr.print "bind the domain '#{domainname}' to '#{src}'. locale is #{locale.inspect}\n" if $DEBUG
|
48
67
|
textdomain = @@__textdomain[src]
|
49
68
|
unless textdomain
|
50
69
|
textdomain = @@__textdomain_key[domainname]
|
51
70
|
@@__textdomain[src] = textdomain
|
52
71
|
end
|
53
72
|
|
54
|
-
|
55
|
-
|
73
|
+
textdomain.set_locale(locale) if textdomain
|
74
|
+
|
75
|
+
if ! textdomain or ! textdomain.same_property?(domainname, path, locale)
|
76
|
+
textdomain = TextDomain.new(domainname, path, locale)
|
56
77
|
@@__textdomain_key[domainname] = textdomain
|
57
78
|
@@__textdomain[src] = textdomain
|
58
79
|
end
|
59
80
|
@@__textdomain[src]
|
60
81
|
end
|
61
82
|
|
83
|
+
# Binds a existed textdomain to your program.
|
84
|
+
# This is the same function with GetText.bindtextdomain but simpler than bindtextdomain.
|
85
|
+
# Notice that you need to call GetText.bindtextdomain first. If the domainname hasn't bound yet,
|
86
|
+
# raises GetText::NoboundTextDomainError.
|
87
|
+
# * domainname: a textdomain name.
|
88
|
+
# * Returns: the GetText::TextDomain.
|
62
89
|
def textdomain(domainname)
|
63
90
|
src = callersrc
|
64
91
|
textdomain = @@__textdomain_key[domainname]
|
65
92
|
raise NoboundTextDomainError, "#{domainname} is not bound." unless textdomain
|
93
|
+
textdomain.set_locale(Locale.current)
|
66
94
|
@@__textdomain[src] = textdomain
|
67
|
-
$stderr.print "Use the domain '#{domainname}' to '#{src}'.
|
95
|
+
$stderr.print "Use the domain '#{domainname}' to '#{src}'. locale is #{textdomain.current_locale.inspect}\n" if $DEBUG
|
68
96
|
@@__textdomain[src]
|
69
97
|
end
|
70
|
-
|
98
|
+
|
99
|
+
# call-seq:
|
100
|
+
# gettext(msgid)
|
101
|
+
# _(msgid)
|
102
|
+
#
|
103
|
+
# Translates msgid and return the message.
|
104
|
+
# * msgid: the message id.
|
105
|
+
# * Returns: localized text by msgid. If there are not binded mo-file, it will return msgid.
|
71
106
|
def gettext(msgid)
|
72
107
|
textdomain = @@__textdomain[callersrc]
|
73
108
|
textdomain ? textdomain.gettext(msgid) : msgid
|
74
109
|
end
|
75
110
|
|
76
|
-
|
111
|
+
# call-seq:
|
112
|
+
# ngettext(msgid, msgid_plural, n)
|
113
|
+
# ngettext(msgids, n) # msgids = [msgid, msgid_plural]
|
114
|
+
# n_(msgid, msgid_plural, n)
|
115
|
+
# n_(msgids, n) # msgids = [msgid, msgid_plural]
|
116
|
+
#
|
117
|
+
# The ngettext is similar to the gettext function as it finds the message catalogs in the same way.
|
118
|
+
# But it takes two extra arguments for plural form.
|
119
|
+
#
|
120
|
+
# * msgid: the singular form.
|
121
|
+
# * msgid_plural: the plural form.
|
122
|
+
# * n: a number used to determine the plural form.
|
123
|
+
# * Returns: the localized text which key is msgid_plural if n is plural(follow plural-rule) or msgid.
|
124
|
+
# "plural-rule" is defined in po-file.
|
125
|
+
def ngettext(arg1, arg2, arg3 = nil)
|
126
|
+
if arg1.kind_of?(Array)
|
127
|
+
msgid = arg1[0]
|
128
|
+
msgid_plural = arg1[1]
|
129
|
+
n = arg2
|
130
|
+
else
|
131
|
+
msgid = arg1
|
132
|
+
msgid_plural = arg2
|
133
|
+
n = arg3
|
134
|
+
end
|
77
135
|
textdomain = @@__textdomain[callersrc]
|
78
|
-
textdomain
|
136
|
+
textdomain.ngettext(msgid, msgid_plural, n)
|
79
137
|
end
|
80
|
-
|
138
|
+
|
139
|
+
# This function does nothing. But it is required in order to recognize the msgid by rgettext.
|
140
|
+
# * msgid: the message id.
|
141
|
+
# * Returns: msgid.
|
81
142
|
def N_(msgid)
|
82
143
|
msgid
|
83
144
|
end
|
84
145
|
|
146
|
+
# This is same function as N_ but for ngettext.
|
147
|
+
# * msgid: the message id.
|
148
|
+
# * Returns: msgid.
|
149
|
+
def Nn_(msgid, msgid_plural)
|
150
|
+
[msgid, msgid_plural]
|
151
|
+
end
|
152
|
+
|
153
|
+
# call-seq:
|
154
|
+
# sgettext(msgid, div = '|')
|
155
|
+
# s_(msgid, div = '|')
|
156
|
+
#
|
157
|
+
# Translates msgid, but if there are no localized text,
|
158
|
+
# it returns a last part of msgid separeted "div".
|
159
|
+
#
|
160
|
+
# * msgid: the message id.
|
161
|
+
# * div: separator or nil.
|
162
|
+
# * Returns: the localized text by msgid. If there are no localized text,
|
163
|
+
# it returns a last part of msgid separeted "div".
|
164
|
+
# See: http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151
|
85
165
|
def sgettext(msgid, div = '|')
|
86
166
|
textdomain = @@__textdomain[callersrc]
|
87
167
|
if textdomain
|
@@ -97,44 +177,112 @@ module GetText
|
|
97
177
|
msg
|
98
178
|
end
|
99
179
|
|
100
|
-
def callersrc
|
180
|
+
def callersrc # :nodoc:
|
101
181
|
caller(2)[0].sub(/:\d+(?::in \`\S+\')?\Z/, '')
|
102
182
|
end
|
103
183
|
|
184
|
+
# Sets locale(String) such as "de", "fr", "it", "ko", "ja_JP.eucJP", "zh_CN.EUC" ...
|
185
|
+
#
|
186
|
+
# Notice that you shouldn't use this for your own Libraries.
|
187
|
+
# * locale: a locale string
|
188
|
+
# * src: internal usage only. You shouldn't use this.
|
189
|
+
# * Returns: self
|
190
|
+
def set_locale(locale, src = callersrc)
|
191
|
+
if locale
|
192
|
+
ret = Locale::Object.new(locale)
|
193
|
+
ret.charset = @@__output_charset if @@__output_charset
|
194
|
+
else
|
195
|
+
ret = nil
|
196
|
+
end
|
197
|
+
Locale.set_current(ret)
|
198
|
+
|
199
|
+
textdomain = @@__textdomain[src]
|
200
|
+
textdomain.set_locale(ret, true) if textdomain
|
201
|
+
|
202
|
+
self
|
203
|
+
end
|
204
|
+
|
205
|
+
# Same as GetText.set_locale.
|
206
|
+
# * locale: a locale string
|
207
|
+
# * src: internal usage only. You shouldn't use this.
|
208
|
+
# * Returns: a locale string
|
104
209
|
def locale=(locale)
|
105
|
-
|
106
|
-
textdomain = @@__textdomain[callersrc]
|
107
|
-
textdomain.set_locale(locale) if textdomain
|
210
|
+
set_locale(locale, callersrc)
|
108
211
|
locale
|
109
212
|
end
|
110
213
|
|
214
|
+
# Sets charset(String) such as "euc-jp", "sjis", "CP932", "utf-8", ...
|
215
|
+
# This affect all of the TextDomains which are created after calling this method.
|
216
|
+
# You shouldn't use this in your own Libraries.
|
217
|
+
# * charset: an output_charset
|
218
|
+
# * Returns: charset
|
219
|
+
def set_output_charset(charset)
|
220
|
+
@@__output_charset = charset
|
221
|
+
self
|
222
|
+
end
|
223
|
+
|
224
|
+
# Same as GetText.set_output_charset
|
225
|
+
# * charset: an output_charset
|
226
|
+
# * Returns: charset
|
111
227
|
def output_charset=(charset)
|
112
|
-
@@
|
228
|
+
@@__output_charset = charset
|
113
229
|
end
|
114
230
|
|
231
|
+
# Gets the current output_charset which is set using GetText.set_output_charset.
|
232
|
+
# * Returns: output_charset.
|
115
233
|
def output_charset
|
116
|
-
@@
|
234
|
+
@@__output_charset
|
117
235
|
end
|
118
236
|
|
237
|
+
# Gets the current locale.
|
238
|
+
# * Returns: a current Locale::Object
|
119
239
|
def locale
|
120
|
-
|
240
|
+
Locale.current
|
121
241
|
end
|
122
242
|
|
243
|
+
# Sets a charset(String) such as "euc-jp", "sjis", "CP932", "utf-8", ...
|
244
|
+
# This affect he current textdomain only.
|
245
|
+
# Generaly you should use GetText.output_charset= instead.
|
246
|
+
# And you shouldn't use this in your own Libraries.
|
247
|
+
# * charset: an charset
|
248
|
+
# * src: internal usage only. You shouldn't use this.
|
249
|
+
# * Returns: self
|
250
|
+
def set_charset(cs, src = callersrc)
|
251
|
+
textdomain = @@__textdomain[src]
|
252
|
+
if textdomain
|
253
|
+
locale = textdomain.current_locale
|
254
|
+
locale ||= Locale.current
|
255
|
+
locale.charset = cs if locale
|
256
|
+
textdomain.set_locale(locale, true)
|
257
|
+
Locale.set_current(locale)
|
258
|
+
end
|
259
|
+
self
|
260
|
+
end
|
261
|
+
|
262
|
+
# Same as GetText.set_charset.
|
263
|
+
# * charset: an charset
|
264
|
+
# * Returns: charset
|
123
265
|
def charset=(cs)
|
124
|
-
|
125
|
-
|
266
|
+
set_charset(cs, callersrc)
|
267
|
+
cs
|
126
268
|
end
|
127
269
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
270
|
+
# Add default locale path.
|
271
|
+
# * path: a new locale path. (e.g.) "/usr/share/locale/%{locale}/LC_MESSAGES/%{name}.mo"
|
272
|
+
# ('locale' => "ja_JP", 'name' => "textdomain")
|
273
|
+
# * Returns: the new DEFAULT_LOCALE_PATHS
|
274
|
+
def add_default_locale_path(path)
|
275
|
+
TextDomain.add_default_locale_path(path)
|
276
|
+
end
|
277
|
+
|
278
|
+
alias :setlocale :locale= #:nodoc:
|
279
|
+
alias :_ :gettext #:nodoc:
|
280
|
+
alias :n_ :ngettext #:nodoc:
|
281
|
+
alias :s_ :sgettext #:nodoc:
|
134
282
|
|
135
283
|
module_function :bindtextdomain, :textdomain,
|
136
284
|
:N_, :gettext, :_, :ngettext, :n_,
|
137
285
|
:sgettext, :s_, :callersrc,
|
138
|
-
:setlocale, :set_locale, :locale=, :locale, :charset=,
|
286
|
+
:setlocale, :set_locale, :locale=, :locale, :charset=, :set_charset,
|
139
287
|
:set_output_charset, :output_charset=, :output_charset
|
140
288
|
end
|
data/lib/gettext/cgi.rb
CHANGED
@@ -6,93 +6,59 @@
|
|
6
6
|
You may redistribute it and/or modify it under the same
|
7
7
|
license terms as Ruby.
|
8
8
|
|
9
|
-
$Id: cgi.rb,v 1.
|
9
|
+
$Id: cgi.rb,v 1.6 2006/02/20 12:35:06 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
12
|
require 'cgi'
|
13
13
|
require 'gettext'
|
14
|
+
require 'gettext/locale_cgi'
|
14
15
|
|
15
16
|
module Locale
|
16
|
-
alias :orig_get :get
|
17
|
-
alias :orig_set :set
|
18
|
-
|
19
|
-
@@cgi = nil
|
20
|
-
@@locale_cgi = nil
|
21
|
-
|
22
17
|
module_function
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@@cgi
|
18
|
+
# Sets a CGI object.
|
19
|
+
# * cgi_: CGI object
|
20
|
+
# * Returns: self
|
21
|
+
def set_cgi(cgi_)
|
22
|
+
@@locale_system_module.set_cgi(cgi_)
|
23
|
+
self
|
30
24
|
end
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
ret = "#{language}#{dialect}"
|
26
|
+
# Sets a CGI object.
|
27
|
+
# * cgi_: CGI object
|
28
|
+
# * Returns: cgi_
|
29
|
+
def cgi=(cgi_)
|
30
|
+
set_cgi(cgi_)
|
31
|
+
cgi_
|
39
32
|
end
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if ret = @@cgi["lang"] and ret.size > 0
|
46
|
-
$stderr.print "query_string: lang = #{ret}\n" if $DEBUG
|
47
|
-
elsif ret = @@cgi.cookies["lang"][0]
|
48
|
-
$stderr.print "cookie: lang = #{ret}\n" if $DEBUG
|
49
|
-
elsif lang = @@cgi.accept_language
|
50
|
-
$stderr.print "accept lanaugage: lang = #{lang}\n" if $DEBUG
|
51
|
-
ret = normalize(lang)
|
52
|
-
else
|
53
|
-
ret = "en"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
$stderr.print "Locale.get = #{ret}\n" if $DEBUG
|
57
|
-
ret
|
34
|
+
# Gets the CGI object. If it is nil, returns new CGI object.
|
35
|
+
# * Returns: the CGI object
|
36
|
+
def cgi
|
37
|
+
@@locale_system_module.cgi
|
58
38
|
end
|
39
|
+
end
|
59
40
|
|
60
|
-
|
61
|
-
|
62
|
-
# match to the locale strings of POSIX setlocale.
|
63
|
-
@@locale_cgi = loc
|
64
|
-
end
|
41
|
+
module GetText
|
42
|
+
module_function
|
65
43
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
ary[0]
|
72
|
-
else
|
73
|
-
"UTF-8"
|
74
|
-
end
|
44
|
+
# Sets a CGI object.
|
45
|
+
# * cgi_: CGI object
|
46
|
+
# * Returns: self
|
47
|
+
def set_cgi(cgi_)
|
48
|
+
Locale.set_cgi(cgi_)
|
75
49
|
end
|
76
50
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
module GetText
|
85
|
-
def cgi=(cgi)
|
86
|
-
@cgi = cgi
|
87
|
-
Locale.cgi = cgi
|
51
|
+
# Same as GetText.set_cgi.
|
52
|
+
# * cgi_: CGI object
|
53
|
+
# * Returns: cgi_
|
54
|
+
def cgi=(cgi_)
|
55
|
+
set_cgi(cgi_)
|
56
|
+
cgi_
|
88
57
|
end
|
89
58
|
|
59
|
+
# Gets the CGI object. If it is nil, returns new CGI object.
|
60
|
+
# * Returns: the CGI object
|
90
61
|
def cgi
|
91
|
-
|
92
|
-
@cgi
|
62
|
+
Locale.cgi
|
93
63
|
end
|
94
|
-
|
95
|
-
alias :set_cgi :cgi=
|
96
|
-
|
97
|
-
module_function :cgi=, :set_cgi, :cgi
|
98
64
|
end
|
data/lib/gettext/container.rb
CHANGED
@@ -1,28 +1,37 @@
|
|
1
1
|
=begin
|
2
2
|
gettext/erb.rb - Class-based container module for GetText
|
3
3
|
|
4
|
-
Copyright (C) 2005 Masao Mutoh
|
4
|
+
Copyright (C) 2005,2006 Masao Mutoh
|
5
5
|
|
6
6
|
You may redistribute it and/or modify it under the same
|
7
7
|
license terms as Ruby.
|
8
8
|
|
9
|
-
$Id: container.rb,v 1.
|
9
|
+
$Id: container.rb,v 1.4 2006/02/23 14:53:59 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
12
|
require 'gettext'
|
13
13
|
|
14
14
|
module GetText
|
15
|
+
# This module is used instead of GetText module. This module provides same functions as GetText module.
|
16
|
+
#
|
17
|
+
# Normaly, GetText.bindtexdomain should be called once a ruby-script-file.
|
18
|
+
# But if the class includes GetText::Container, a TextDomain is bound to an instance of the class.
|
19
|
+
# So you don't need to call bindtextdomain in each files if the files define a class.
|
20
|
+
#
|
21
|
+
# This module is useful for application-side classes, but you shouldn't use this for libraries.
|
22
|
+
# Because the user of your library may override/add new features to the original library and the
|
23
|
+
# user needs to prepare another TextDomain(Otherwise, apply po/mo patch to the original library).
|
15
24
|
module Container
|
16
25
|
include GetText
|
17
26
|
|
18
|
-
alias :_bindtextdomain :bindtextdomain
|
27
|
+
alias :_bindtextdomain :bindtextdomain #:nodoc:
|
19
28
|
|
20
|
-
def bindtextdomain(domainname, path = nil, locale = nil, charset = nil)
|
29
|
+
def bindtextdomain(domainname, path = nil, locale = nil, charset = nil) #:nodoc:
|
21
30
|
@gettext_container_domainname = domainname
|
22
31
|
_bindtextdomain(domainname, path, locale, charset)
|
23
32
|
end
|
24
33
|
|
25
|
-
def callersrc
|
34
|
+
def callersrc #:nodoc:
|
26
35
|
@gettext_container_domainname
|
27
36
|
end
|
28
37
|
|