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/erb.rb
CHANGED
@@ -1,26 +1,54 @@
|
|
1
1
|
=begin
|
2
2
|
gettext/erb.rb - GetText for ERB
|
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: erb.rb,v 1.
|
9
|
+
$Id: erb.rb,v 1.2 2006/02/23 14:53:59 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
12
|
require 'erb'
|
13
13
|
require 'gettext/container'
|
14
14
|
|
15
15
|
module GetText
|
16
|
+
|
17
|
+
# This module provides basic functions to evaluate plural ERB files(.rhtml) in a TextDomain.
|
18
|
+
# You need to implement a class which includes GetText::ErbContainer.
|
19
|
+
#
|
20
|
+
# See simple examples below:
|
21
|
+
#
|
22
|
+
# require 'gettext/erb'
|
23
|
+
# class SimpleContainer
|
24
|
+
# include GetText::ErbContainer
|
25
|
+
#
|
26
|
+
# def initialize(domainname, domainpath = nil, locale = nil, charset = nil)
|
27
|
+
# bindtextdomain(domainname, domainpath, locale)
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# container = SimpleContainer.new("helloerb1", "locale")
|
32
|
+
# puts container.eval_file("/your/erb/file.rhtml")
|
33
|
+
#
|
34
|
+
# This module is an example for template engines such as ERB.
|
35
|
+
# You can implement another implementation easily to read gettext/erb.rb.
|
16
36
|
module ErbContainer
|
17
37
|
include Container
|
18
38
|
|
39
|
+
# Evaluates ERB source(String) in the instance and returns the result HTML.
|
40
|
+
#
|
41
|
+
# * rhtml: an ERB source
|
42
|
+
# * Returns: the Evaluated ERB result
|
19
43
|
def eval_src(rhtml)
|
20
44
|
erb = ERB.new(rhtml).src
|
21
45
|
eval(erb, binding)
|
22
46
|
end
|
23
47
|
|
48
|
+
# Evaluates ERB file in the instance and returns the result HTML.
|
49
|
+
#
|
50
|
+
# * rhtml: an ERB file
|
51
|
+
# * Returns: the Evaluated ERB result
|
24
52
|
def eval_file(rhtmlpath)
|
25
53
|
eval_src(IO.read(rhtmlpath))
|
26
54
|
end
|
data/lib/gettext/iconv.rb
CHANGED
@@ -9,20 +9,30 @@
|
|
9
9
|
You may redistribute it and/or modify it under the same
|
10
10
|
license terms as Ruby.
|
11
11
|
|
12
|
-
$Id: iconv.rb,v 1.
|
12
|
+
$Id: iconv.rb,v 1.2 2006/02/22 16:42:41 mutoh Exp $
|
13
13
|
=end
|
14
|
+
|
14
15
|
begin
|
15
16
|
require 'iconv.so'
|
16
17
|
rescue LoadError
|
17
18
|
begin
|
18
19
|
require 'glib2'
|
20
|
+
# = Pseudo Iconv module
|
21
|
+
#
|
22
|
+
# Provides Iconv.iconv which uses Ruby/GLib(1) functions. This library also required from 'gettext'.
|
23
|
+
# If you require 'gettext/iconv', Iconv.iconv try to call Ruby/GLib function
|
24
|
+
# when it doesn't find original Iconv module(iconv.so).
|
25
|
+
#
|
26
|
+
# (1) Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
|
27
|
+
# You can get binaries for Win32(One-Click Ruby Installer).
|
28
|
+
# <URL: http://ruby-gnome2.sourceforge.jp/>
|
19
29
|
module Iconv
|
20
30
|
module Failure; end
|
21
31
|
class InvalidEncoding < ArgumentError; include Failure; end
|
22
32
|
class IllegalSequence < ArgumentError; include Failure; end
|
23
33
|
class InvalidCharacter < ArgumentError; include Failure; end
|
24
34
|
|
25
|
-
def check_glib_version?(major, minor, micro)
|
35
|
+
def check_glib_version?(major, minor, micro) # :nodoc:
|
26
36
|
(GLib::BINDING_VERSION[0] > major ||
|
27
37
|
(GLib::BINDING_VERSION[0] == major &&
|
28
38
|
GLib::BINDING_VERSION[1] > minor) ||
|
@@ -33,6 +43,11 @@ rescue LoadError
|
|
33
43
|
module_function :check_glib_version?
|
34
44
|
|
35
45
|
if check_glib_version?(0, 11, 0)
|
46
|
+
# This is a function equivalent of Iconv.iconv.
|
47
|
+
# * to: encoding name for destination
|
48
|
+
# * from: encoding name for source
|
49
|
+
# * str: strings to be converted
|
50
|
+
# * Returns: Returns an Array of converted strings.
|
36
51
|
def iconv(to, from, str)
|
37
52
|
begin
|
38
53
|
GLib.convert(str, to, from).split(//)
|
@@ -48,7 +63,7 @@ rescue LoadError
|
|
48
63
|
end
|
49
64
|
end
|
50
65
|
else
|
51
|
-
def iconv(to, from, str)
|
66
|
+
def iconv(to, from, str) # :nodoc:
|
52
67
|
begin
|
53
68
|
GLib.convert(str, to, from).split(//)
|
54
69
|
rescue
|
@@ -61,7 +76,7 @@ rescue LoadError
|
|
61
76
|
rescue LoadError
|
62
77
|
module Iconv
|
63
78
|
module_function
|
64
|
-
def iconv(to, from, str)
|
79
|
+
def iconv(to, from, str) # :nodoc:
|
65
80
|
warn "Iconv was not found." if $DEBUG
|
66
81
|
str.split(//)
|
67
82
|
end
|
data/lib/gettext/locale.rb
CHANGED
@@ -6,56 +6,205 @@
|
|
6
6
|
You may redistribute it and/or modify it under the same
|
7
7
|
license terms as Ruby.
|
8
8
|
|
9
|
-
$Id: locale.rb,v 1.
|
9
|
+
$Id: locale.rb,v 1.9 2006/02/20 12:35:06 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
|
+
require 'gettext/locale_object'
|
13
|
+
|
12
14
|
begin
|
13
|
-
require '
|
15
|
+
require 'locale_system'
|
14
16
|
rescue LoadError
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def __locale_id; [0x00, 0x00]; end
|
33
|
-
end
|
17
|
+
# This is used for installation process(from rake only)
|
18
|
+
# And deprecated these constants.
|
19
|
+
module Locale
|
20
|
+
# Deprecated.
|
21
|
+
CTYPE = 0
|
22
|
+
# Deprecated.
|
23
|
+
NUMERIC = 1
|
24
|
+
# Deprecated.
|
25
|
+
TIME = 2
|
26
|
+
# Deprecated.
|
27
|
+
COLLATE = 3
|
28
|
+
# Deprecated.
|
29
|
+
MONETARY = 4
|
30
|
+
# Deprecated.
|
31
|
+
MESSAGES = 5
|
32
|
+
# Deprecated.
|
33
|
+
ALL = 6
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
if /cygwin|mingw|
|
37
|
+
if /cygwin|mingw|win32/ =~ RUBY_PLATFORM
|
38
38
|
require 'gettext/locale_win32'
|
39
39
|
else
|
40
|
-
require 'gettext/
|
40
|
+
require 'gettext/locale_posix'
|
41
41
|
end
|
42
42
|
|
43
|
+
# Locale module manages the locale informations of the application.
|
43
44
|
module Locale
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
45
|
+
unless defined? CTYPE
|
46
|
+
CTYPE = 0 #:nodoc:
|
47
|
+
NUMERIC = 1 #:nodoc:
|
48
|
+
TIME = 2 #:nodoc:
|
49
|
+
COLLATE = 3 #:nodoc:
|
50
|
+
MONETARY = 4 #:nodoc:
|
51
|
+
MESSAGES = 5 #:nodoc:
|
52
|
+
ALL = 6 #:nodoc:
|
53
|
+
end
|
54
|
+
|
55
|
+
@@default = nil
|
56
|
+
@@current = nil
|
57
|
+
|
58
|
+
module_function
|
59
|
+
# Sets the default locale (Locale::Object).
|
60
|
+
#
|
61
|
+
# * locale: the default locale
|
62
|
+
# * Returns: self.
|
63
|
+
def set_default(locale)
|
64
|
+
@@default = locale
|
65
|
+
if @@default
|
66
|
+
@@default.charset ||= @@locale_system_module.get_charset(locale)
|
67
|
+
end
|
68
|
+
self
|
69
|
+
end
|
70
|
+
# Same as Locale.set_default.
|
71
|
+
#
|
72
|
+
# * locale: the default locale (Locale::Object).
|
73
|
+
# * Returns: locale.
|
74
|
+
def default=(locale)
|
75
|
+
set_default(locale)
|
76
|
+
@@default
|
77
|
+
end
|
78
|
+
|
79
|
+
# Gets the system locale.
|
80
|
+
# * Returns: the system locale (Locale::Object).
|
81
|
+
def system
|
82
|
+
@@locale_system_module.system
|
83
|
+
end
|
84
|
+
|
85
|
+
# Gets the default locale.
|
86
|
+
#
|
87
|
+
# If the default locale not set, this returns system locale.
|
88
|
+
# * Returns: the default locale (Locale::Object).
|
89
|
+
def default
|
90
|
+
@@default = system unless @@default
|
91
|
+
@@default
|
92
|
+
end
|
93
|
+
|
94
|
+
# Gets the current locale (Locale::Object).
|
95
|
+
#
|
96
|
+
# If the current locale is not set, this returns default locale.
|
97
|
+
# * Returns: the current locale (Locale::Object).
|
98
|
+
def current
|
99
|
+
@@current = default unless @@current
|
100
|
+
@@current
|
101
|
+
end
|
102
|
+
|
103
|
+
# Sets a locale as the current locale.
|
104
|
+
#
|
105
|
+
# This returns the current Locale::Object.
|
106
|
+
# * lang: Locale::Object or locale name(String), or language name.
|
107
|
+
# * country: the country code(String)
|
108
|
+
# * charset: the charset(override the charset even if the locale name has charset).
|
109
|
+
# * Returns: self
|
110
|
+
#
|
111
|
+
# Locale.set_current("ja_JP.eucJP")
|
112
|
+
# Locale.set_current("ja", "JP")
|
113
|
+
# Locale.set_current("ja", "JP", "eucJP")
|
114
|
+
# Locale.set_current("ja", nil, "eucJP")
|
115
|
+
# Locale.set_current(Locale::Object.new("ja", "JP", "eucJP"))
|
116
|
+
def set_current(lang, country = nil, charset = nil)
|
117
|
+
if lang == nil
|
118
|
+
@@current = nil
|
119
|
+
else
|
120
|
+
if lang.kind_of? Locale::Object
|
121
|
+
@@current = lang
|
122
|
+
else
|
123
|
+
@@current = Locale::Object.new(lang, country, charset)
|
124
|
+
end
|
125
|
+
@@current.charset ||= @@locale_system_module.get_charset(@@current)
|
126
|
+
end
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
130
|
+
# Sets a current locale. This is a single argument version of Locale.set_current.
|
131
|
+
#
|
132
|
+
# * lang: the Locale::Object
|
133
|
+
# * Returns: the current locale (Locale::Object).
|
134
|
+
#
|
135
|
+
# Locale.current = "ja_JP.eucJP"
|
136
|
+
# Locale.current = Locale::Object.new("ja", "JP", "eucJP")
|
137
|
+
def current=(lang)
|
138
|
+
set_current(lang)
|
139
|
+
@@current
|
140
|
+
end
|
141
|
+
|
142
|
+
# call-seq:
|
143
|
+
# set(lang)
|
144
|
+
# set(lang, country = nil, charset = nil)
|
145
|
+
#
|
146
|
+
# Sets a default locale. This function is an alias of Locale.set_default.
|
147
|
+
#
|
148
|
+
# *Notice*: Locale.set(lctype, locale) is deprecated.
|
149
|
+
def set(lang, country = nil, charset = nil)
|
150
|
+
if lang.kind_of? Numeric
|
151
|
+
warn "Locale.set(lctype, locale) is deprecated. Use Locale.set(locale) instead."
|
152
|
+
# Locale.set(Locale::CTYPE, "ja_JP.eucJP") "country" means locale.
|
153
|
+
lang = country
|
154
|
+
country = nil
|
155
|
+
charset = nil
|
156
|
+
end
|
53
157
|
|
54
|
-
if
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
158
|
+
if lang
|
159
|
+
set_default(Locale::Object.new(lang, country, charset))
|
160
|
+
else
|
161
|
+
set_default(nil)
|
162
|
+
end
|
163
|
+
@@default
|
164
|
+
end
|
165
|
+
|
166
|
+
# call-seq:
|
167
|
+
# current
|
168
|
+
# get
|
169
|
+
# get(lctype = nil) (Deprecated)
|
170
|
+
#
|
171
|
+
# * Returns: the current locale (Locale::Object).
|
172
|
+
#
|
173
|
+
# *Notice*: lctype is deprecated. Use this with no parameter instead.
|
174
|
+
def get(lctype = nil)
|
175
|
+
warn "Locale.get(lctype) is deprecated. Use Locale.get (noparam) instead." if lctype
|
176
|
+
@@current = default unless @@current
|
177
|
+
@@current
|
178
|
+
end
|
179
|
+
|
180
|
+
# *Deprecated*. Use Locale.set or Locale.set_current instead.
|
181
|
+
def setlocale(lctype, loc)
|
182
|
+
warn "Deprecated. Use Locale#set instead."
|
183
|
+
set(lctype, loc)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Same as charset. Gets the charset of the current locale.
|
187
|
+
# * Returns: the charset of the current locale (String)
|
188
|
+
def codeset
|
189
|
+
current.charset
|
190
|
+
end
|
191
|
+
|
192
|
+
# Gets the charset of the current locale.
|
193
|
+
# * Returns: the charset of the current locale (String)
|
194
|
+
def charset
|
195
|
+
codeset
|
196
|
+
end
|
197
|
+
# Same as codeset. Returns the charset of the current locale.
|
198
|
+
# * Returns: the charset of the current locale (String)
|
199
|
+
def current_charset
|
200
|
+
codeset
|
201
|
+
end
|
202
|
+
|
203
|
+
# Clear default/current locale.
|
204
|
+
# * Returns: self
|
205
|
+
def clear
|
206
|
+
set(nil)
|
207
|
+
set_current(nil)
|
208
|
+
self
|
209
|
+
end
|
61
210
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
=begin
|
2
|
+
locale_cgi.rb
|
3
|
+
|
4
|
+
Copyright (C) 2002-2006 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby.
|
8
|
+
|
9
|
+
$Id: locale_cgi.rb,v 1.1 2006/02/20 12:35:06 mutoh Exp $
|
10
|
+
=end
|
11
|
+
|
12
|
+
|
13
|
+
module Locale # :nodoc:
|
14
|
+
# Locale::System module for Default OS (Unix)
|
15
|
+
# This is low-level class. Application shouldn't use this directly.
|
16
|
+
module SystemCGI
|
17
|
+
@@default_locale = Locale::Object.new("en", nil, "UTF-8")
|
18
|
+
@@cgi = nil
|
19
|
+
|
20
|
+
module_function
|
21
|
+
# Gets the default locale using setlocale and nl_langinfo.
|
22
|
+
# * Returns the system locale (Locale::Object).
|
23
|
+
def system
|
24
|
+
cgi_ = cgi
|
25
|
+
if ret = cgi_["lang"] and ret.size > 0
|
26
|
+
$stderr.print "query_string: lang = #{ret}\n" if $DEBUG
|
27
|
+
elsif ret = cgi_.cookies["lang"][0]
|
28
|
+
$stderr.print "cookie: lang = #{ret}\n" if $DEBUG
|
29
|
+
elsif lang = cgi_.accept_language and lang.size > 0
|
30
|
+
$stderr.print "accept lanaugage: lang = #{lang}\n" if $DEBUG
|
31
|
+
ret = lang.split(/,|;/).first
|
32
|
+
else
|
33
|
+
ret = @@default_locale.to_str
|
34
|
+
end
|
35
|
+
|
36
|
+
codesets = cgi_.accept_charset
|
37
|
+
if codesets and codesets.size > 0
|
38
|
+
ary = codesets.split(',')
|
39
|
+
codeset = ary[0]
|
40
|
+
codeset = @@default_locale.charset if codeset == "*"
|
41
|
+
else
|
42
|
+
codeset = @@default_locale.charset
|
43
|
+
end
|
44
|
+
Locale::Object.new(ret, nil, codeset)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Gets the charset of the locale.
|
48
|
+
# * locale: Locale::Object
|
49
|
+
# * Returns: the charset of the locale
|
50
|
+
def get_charset(locale)
|
51
|
+
locale.charset ? locale.charset : @@default_locale.charset
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sets a CGI object.
|
55
|
+
# * cgi_: CGI object
|
56
|
+
# * Returns: self
|
57
|
+
def set_cgi(cgi_)
|
58
|
+
@@cgi = cgi_
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
# Sets a CGI object.
|
63
|
+
# * cgi_: CGI object
|
64
|
+
# * Returns: cgi_
|
65
|
+
def cgi=(cgi_)
|
66
|
+
set_cgi(cgi_)
|
67
|
+
cgi_
|
68
|
+
end
|
69
|
+
|
70
|
+
# Gets the CGI object. If it is nil, returns new CGI object.
|
71
|
+
# * Returns: the CGI object
|
72
|
+
def cgi
|
73
|
+
@@cgi = CGI.new unless @@cgi
|
74
|
+
@@cgi
|
75
|
+
end
|
76
|
+
|
77
|
+
# Sets a default locale. en.UTF-8 is the default value if not set.
|
78
|
+
# * locale: Locale::Object object. You can't set nil.
|
79
|
+
# * Returns: self
|
80
|
+
def set_default_locale(locale)
|
81
|
+
raise "Wrong parameter: #{locale}" if locale.nil?
|
82
|
+
@@default_locale = locale
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
# Sets a default locale. en.UTF-8 is the default value if not set.
|
87
|
+
# * locale: Locale::Object
|
88
|
+
# * Returns: locale
|
89
|
+
def default_locale=(locale)
|
90
|
+
set_default_locale(locale)
|
91
|
+
locale
|
92
|
+
end
|
93
|
+
|
94
|
+
# Gets the default Locale::Object.
|
95
|
+
# * Returns: the default locale
|
96
|
+
def default_locale
|
97
|
+
@@default_locale
|
98
|
+
end
|
99
|
+
end
|
100
|
+
@@locale_system_module = SystemCGI
|
101
|
+
end
|
102
|
+
|