gettext 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/ChangeLog +128 -0
  2. data/NEWS +10 -0
  3. data/README +21 -23
  4. data/Rakefile +39 -20
  5. data/bin/rgettext +1 -1
  6. data/bin/rmsgfmt +1 -1
  7. data/bin/rmsgmerge +1 -1
  8. data/data/locale/cs/LC_MESSAGES/rails.mo +0 -0
  9. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  10. data/data/locale/de/LC_MESSAGES/rails.mo +0 -0
  11. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  12. data/data/locale/el/LC_MESSAGES/rails.mo +0 -0
  13. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  14. data/data/locale/es/LC_MESSAGES/rails.mo +0 -0
  15. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  16. data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
  17. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  18. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/ja/LC_MESSAGES/rails.mo +0 -0
  20. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/ko/LC_MESSAGES/rails.mo +0 -0
  22. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/nl/LC_MESSAGES/rails.mo +0 -0
  24. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/pt_BR/LC_MESSAGES/rails.mo +0 -0
  26. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  27. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  28. data/ext/gettext/extconf.rb +20 -0
  29. data/ext/gettext/{gettext/_locale.c → locale_system.c} +15 -19
  30. data/lib/gettext.rb +186 -38
  31. data/lib/gettext/cgi.rb +35 -69
  32. data/lib/gettext/container.rb +14 -5
  33. data/lib/gettext/erb.rb +30 -2
  34. data/lib/gettext/iconv.rb +19 -4
  35. data/lib/gettext/locale.rb +188 -39
  36. data/lib/gettext/locale_cgi.rb +102 -0
  37. data/lib/gettext/locale_object.rb +131 -0
  38. data/lib/gettext/locale_posix.rb +50 -0
  39. data/lib/gettext/locale_table_win32.rb +224 -182
  40. data/lib/gettext/locale_win32.rb +59 -35
  41. data/lib/gettext/mo.rb +2 -2
  42. data/lib/gettext/parser/activerecord.rb +19 -5
  43. data/lib/gettext/parser/erb.rb +6 -3
  44. data/lib/gettext/parser/glade.rb +5 -5
  45. data/lib/gettext/parser/ruby.rb +6 -6
  46. data/lib/gettext/poparser.rb +7 -6
  47. data/lib/gettext/rails.rb +122 -44
  48. data/lib/gettext/rgettext.rb +21 -8
  49. data/lib/gettext/rmsgfmt.rb +16 -8
  50. data/lib/gettext/rmsgmerge.rb +172 -50
  51. data/lib/gettext/string.rb +25 -3
  52. data/lib/gettext/textdomain.rb +89 -90
  53. data/lib/gettext/utils.rb +63 -3
  54. data/lib/gettext/version.rb +2 -2
  55. data/pkg/ruby-gettext-package-1.2.0/ext/gettext/extconf.rb +20 -0
  56. data/po/cs/rails.po +28 -28
  57. data/po/cs/rgettext.po +14 -14
  58. data/po/de/rails.po +29 -26
  59. data/po/de/rgettext.po +24 -17
  60. data/po/el/rails.po +26 -26
  61. data/po/el/rgettext.po +18 -15
  62. data/po/es/rails.po +26 -26
  63. data/po/es/rgettext.po +16 -16
  64. data/po/fr/rails.po +27 -27
  65. data/po/fr/rgettext.po +14 -14
  66. data/po/it/rgettext.po +14 -14
  67. data/po/ja/rails.po +24 -24
  68. data/po/ja/rgettext.po +14 -14
  69. data/po/ko/rails.po +24 -24
  70. data/po/ko/rgettext.po +17 -18
  71. data/po/nl/rails.po +27 -27
  72. data/po/nl/rgettext.po +18 -18
  73. data/po/pt_BR/rails.po +26 -26
  74. data/po/pt_BR/rgettext.po +14 -14
  75. data/po/rails.pot +26 -26
  76. data/po/rgettext.pot +14 -14
  77. data/po/sv/rgettext.po +14 -14
  78. data/post-setup.rb +8 -3
  79. data/pre-setup.rb +14 -1
  80. data/samples/cgi/http.rb +2 -1
  81. data/samples/makemo.rb +1 -1
  82. data/samples/rails/app/models/article.rb +15 -1
  83. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  84. data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  85. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  86. data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  87. data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
  88. data/samples/rails/locale/el/LC_MESSAGES/gettext_plugin.mo +0 -0
  89. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  90. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  91. data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  92. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  93. data/samples/rails/locale/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
  94. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  95. data/samples/rails/locale/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
  96. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  97. data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  98. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  99. data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  100. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  101. data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  102. data/samples/rails/po/blog.pot +1 -1
  103. data/samples/rails/po/cs/blog.po +1 -2
  104. data/samples/rails/po/cs/gettext_plugin.po +1 -1
  105. data/samples/rails/po/de/blog.po +1 -2
  106. data/samples/rails/po/de/gettext_plugin.po +1 -1
  107. data/samples/rails/po/el/blog.po +1 -1
  108. data/samples/rails/po/el/gettext_plugin.po +1 -1
  109. data/samples/rails/po/en/blog.po +1 -1
  110. data/samples/rails/po/es/blog.po +1 -2
  111. data/samples/rails/po/es/gettext_plugin.po +1 -1
  112. data/samples/rails/po/fr/blog.po +1 -1
  113. data/samples/rails/po/fr/gettext_plugin.po +1 -1
  114. data/samples/rails/po/gettext_plugin.pot +1 -1
  115. data/samples/rails/po/ja/blog.po +2 -1
  116. data/samples/rails/po/ja/gettext_plugin.po +1 -1
  117. data/samples/rails/po/ko/blog.po +1 -2
  118. data/samples/rails/po/ko/gettext_plugin.po +1 -1
  119. data/samples/rails/po/nl/blog.po +1 -3
  120. data/samples/rails/po/nl/gettext_plugin.po +1 -1
  121. data/samples/rails/po/pt_BR/blog.po +1 -1
  122. data/samples/rails/po/pt_BR/gettext_plugin.po +1 -1
  123. data/setup.rb +799 -574
  124. data/src/poparser.ry +6 -5
  125. data/test/gettext_runner.rb +3 -1
  126. data/test/gettext_test.rb +40 -24
  127. data/test/gettext_test_cgi.rb +60 -6
  128. data/test/gettext_test_locale.rb +136 -0
  129. data/test/gettext_test_parser.rb +12 -12
  130. data/test/locale/la/LC_MESSAGES/plural_error.mo +0 -0
  131. data/test/po/la/plural_error.po +21 -0
  132. data/test/test.bat +2 -0
  133. data/test/test.sh +2 -4
  134. data/test/{test_rubyparser_n.rb → test_rubyparser_n_.rb} +0 -0
  135. metadata +17 -12
  136. data/ext/gettext/gettext/MANIFEST +0 -3
  137. data/ext/gettext/gettext/extconf.rb +0 -20
  138. 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.5 2005/11/30 17:59:14 mutoh Exp $
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
- @@output_charset = nil
31
- @@locale = nil
31
+ @@__output_charset = nil
32
32
 
33
- def bindtextdomain(domainname, path = nil, locale = nil, charset = nil)
34
- if @@locale
35
- locale = @@locale
36
- Locale.set(Locale::CTYPE, locale)
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
- locale ||= Locale.get
39
- end
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}'. charset is #{charset}\n" if $DEBUG
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
- if ! textdomain or ! textdomain.same_property?(domainname, path, locale, charset)
55
- textdomain = TextDomain.new(domainname, path, locale, charset)
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}'. charset is #{textdomain.charset}\n" if $DEBUG
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
- def ngettext(msgid, msgid_plural, n)
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 ? textdomain.ngettext(msgid, msgid_plural, n) : (n == 1 ? msgid : msgid_plural)
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
- @@locale = locale
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
- @@output_charset = charset
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
- @@output_charset
234
+ @@__output_charset
117
235
  end
118
236
 
237
+ # Gets the current locale.
238
+ # * Returns: a current Locale::Object
119
239
  def locale
120
- @@locale
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
- textdomain = @@__textdomain[callersrc]
125
- textdomain.set_charset(cs) if textdomain
266
+ set_charset(cs, callersrc)
267
+ cs
126
268
  end
127
269
 
128
- alias :setlocale :locale=
129
- alias :set_locale :locale=
130
- alias :set_output_charset :output_charset=
131
- alias :_ :gettext
132
- alias :n_ :ngettext
133
- alias :s_ :sgettext
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.4 2005/12/07 17:09:39 mutoh Exp $
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
- def cgi=(cgi)
24
- @@cgi = cgi
25
- end
26
-
27
- def cgi
28
- @@cgi = CGI.new unless @@cgi
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
- def normalize(lang)
33
- lang = lang.split(',').first.gsub(/_/, "-").split('-') rescue []
34
- language = lang[0]
35
- dialect = lang[1]
36
- language = language ? language.downcase : 'en' # default is en
37
- dialect = dialect ? "_#{dialect.upcase}" : ""
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
- def get(lctype = Locale::CTYPE) #lctype doesn't used here.
42
- ret = @@locale_cgi
43
- unless ret
44
- @@cgi = CGI.new unless @@cgi
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
- def set(lctype, loc)
61
- # Override this method. Because the value from WWW browser doesn't
62
- # match to the locale strings of POSIX setlocale.
63
- @@locale_cgi = loc
64
- end
41
+ module GetText
42
+ module_function
65
43
 
66
- def codeset
67
- @@cgi = CGI.new unless @@cgi
68
- codesets = @@cgi.accept_charset
69
- if codesets
70
- ary = codesets.split(',')
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
- alias :charset :codeset
78
- alias :setlocale :set
79
- alias :set_cgi :cgi=
80
-
81
- module_function :charset, :set_cgi, :set, :setlocale
82
- end
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
- @cgi = Locale.cgi unless @cgi
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
@@ -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.3 2005/08/22 17:24:33 mutoh Exp $
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