gettext 1.1.1-mswin32 → 1.2.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/ChangeLog +128 -0
  2. data/NEWS +10 -0
  3. data/README +21 -23
  4. data/Rakefile +40 -21
  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/{gettext/Makefile → Makefile} +3 -3
  29. data/ext/gettext/extconf.rb +20 -0
  30. data/ext/gettext/locale_system-i386-mswin32.def +2 -0
  31. data/ext/gettext/{gettext/_locale.c → locale_system.c} +15 -19
  32. data/ext/gettext/locale_system.exp +0 -0
  33. data/ext/gettext/locale_system.lib +0 -0
  34. data/ext/gettext/locale_system.obj +0 -0
  35. data/ext/gettext/{gettext/_locale.pdb → locale_system.pdb} +0 -0
  36. data/ext/gettext/locale_system.so +0 -0
  37. data/ext/gettext/mkmf.log +10 -0
  38. data/ext/gettext/{gettext/vc70.pdb → vc70.pdb} +0 -0
  39. data/lib/gettext.rb +186 -38
  40. data/lib/gettext/cgi.rb +35 -69
  41. data/lib/gettext/container.rb +14 -5
  42. data/lib/gettext/erb.rb +30 -2
  43. data/lib/gettext/iconv.rb +19 -4
  44. data/lib/gettext/locale.rb +188 -39
  45. data/lib/gettext/locale_cgi.rb +102 -0
  46. data/lib/gettext/locale_object.rb +131 -0
  47. data/lib/gettext/locale_posix.rb +50 -0
  48. data/lib/gettext/locale_table_win32.rb +224 -182
  49. data/lib/gettext/locale_win32.rb +59 -35
  50. data/lib/gettext/mo.rb +2 -2
  51. data/lib/gettext/parser/activerecord.rb +19 -5
  52. data/lib/gettext/parser/erb.rb +6 -3
  53. data/lib/gettext/parser/glade.rb +5 -5
  54. data/lib/gettext/parser/ruby.rb +6 -6
  55. data/lib/gettext/poparser.rb +298 -297
  56. data/lib/gettext/rails.rb +122 -44
  57. data/lib/gettext/rgettext.rb +21 -8
  58. data/lib/gettext/rmsgfmt.rb +16 -8
  59. data/lib/gettext/rmsgmerge.rb +172 -50
  60. data/lib/gettext/string.rb +25 -3
  61. data/lib/gettext/textdomain.rb +89 -90
  62. data/lib/gettext/utils.rb +63 -3
  63. data/lib/gettext/version.rb +2 -2
  64. data/lib/locale_system.so +0 -0
  65. data/po/cs/rails.po +28 -28
  66. data/po/cs/rgettext.po +14 -14
  67. data/po/de/rails.po +29 -26
  68. data/po/de/rgettext.po +24 -17
  69. data/po/el/rails.po +26 -26
  70. data/po/el/rgettext.po +18 -15
  71. data/po/es/rails.po +26 -26
  72. data/po/es/rgettext.po +16 -16
  73. data/po/fr/rails.po +27 -27
  74. data/po/fr/rgettext.po +14 -14
  75. data/po/it/rgettext.po +14 -14
  76. data/po/ja/rails.po +24 -24
  77. data/po/ja/rgettext.po +14 -14
  78. data/po/ko/rails.po +24 -24
  79. data/po/ko/rgettext.po +17 -18
  80. data/po/nl/rails.po +27 -27
  81. data/po/nl/rgettext.po +18 -18
  82. data/po/pt_BR/rails.po +26 -26
  83. data/po/pt_BR/rgettext.po +14 -14
  84. data/po/rails.pot +26 -26
  85. data/po/rgettext.pot +14 -14
  86. data/po/sv/rgettext.po +14 -14
  87. data/post-setup.rb +8 -3
  88. data/pre-setup.rb +14 -1
  89. data/samples/cgi/http.rb +2 -1
  90. data/samples/makemo.rb +1 -1
  91. data/samples/rails/app/models/article.rb +15 -1
  92. data/samples/rails/config/database.yml +1 -1
  93. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  94. data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  95. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  96. data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  97. data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
  98. data/samples/rails/locale/el/LC_MESSAGES/gettext_plugin.mo +0 -0
  99. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  100. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  101. data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  102. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  103. data/samples/rails/locale/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
  104. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  105. data/samples/rails/locale/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
  106. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  107. data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  108. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  109. data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  110. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  111. data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  112. data/samples/rails/po/blog.pot +1 -1
  113. data/samples/rails/po/cs/blog.po +1 -2
  114. data/samples/rails/po/cs/gettext_plugin.po +1 -1
  115. data/samples/rails/po/de/blog.po +1 -2
  116. data/samples/rails/po/de/gettext_plugin.po +1 -1
  117. data/samples/rails/po/el/blog.po +1 -1
  118. data/samples/rails/po/el/gettext_plugin.po +1 -1
  119. data/samples/rails/po/en/blog.po +1 -1
  120. data/samples/rails/po/es/blog.po +1 -2
  121. data/samples/rails/po/es/gettext_plugin.po +1 -1
  122. data/samples/rails/po/fr/blog.po +1 -1
  123. data/samples/rails/po/fr/gettext_plugin.po +1 -1
  124. data/samples/rails/po/gettext_plugin.pot +1 -1
  125. data/samples/rails/po/ja/blog.po +2 -1
  126. data/samples/rails/po/ja/gettext_plugin.po +1 -1
  127. data/samples/rails/po/ko/blog.po +1 -2
  128. data/samples/rails/po/ko/gettext_plugin.po +1 -1
  129. data/samples/rails/po/nl/blog.po +1 -3
  130. data/samples/rails/po/nl/gettext_plugin.po +1 -1
  131. data/samples/rails/po/pt_BR/blog.po +1 -1
  132. data/samples/rails/po/pt_BR/gettext_plugin.po +1 -1
  133. data/setup.rb +799 -574
  134. data/src/poparser.ry +6 -5
  135. data/test/gettext_runner.rb +3 -1
  136. data/test/gettext_test.rb +40 -24
  137. data/test/gettext_test_cgi.rb +60 -6
  138. data/test/gettext_test_locale.rb +136 -0
  139. data/test/gettext_test_parser.rb +12 -12
  140. data/test/locale/la/LC_MESSAGES/plural_error.mo +0 -0
  141. data/test/po/la/plural_error.po +21 -0
  142. data/test/test.bat +2 -0
  143. data/test/test.sh +2 -4
  144. data/test/test_rubyparser_n_.rb +64 -0
  145. metadata +24 -21
  146. data/ext/gettext/gettext/MANIFEST +0 -3
  147. data/ext/gettext/gettext/_locale-i386-mswin32.def +0 -2
  148. data/ext/gettext/gettext/_locale.exp +0 -0
  149. data/ext/gettext/gettext/_locale.lib +0 -0
  150. data/ext/gettext/gettext/_locale.obj +0 -0
  151. data/ext/gettext/gettext/_locale.so +0 -0
  152. data/ext/gettext/gettext/extconf.rb +0 -20
  153. data/ext/gettext/gettext/mkmf.log +0 -16
  154. data/lib/_locale.so +0 -0
  155. data/lib/gettext/locale_default.rb +0 -35
  156. data/po/it/messages.mo +0 -0
  157. data/samples/cgi/po/it/messages.mo +0 -0
@@ -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
 
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.1.1.1 2005/08/13 02:38:09 mutoh Exp $
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.1.1.1 2005/08/13 02:38:09 mutoh Exp $
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
@@ -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.4 2005/09/04 17:47:54 mutoh Exp $
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 'gettext/_locale'
15
+ require 'locale_system'
14
16
  rescue LoadError
15
- # For rubygems
16
- begin
17
- require '_locale'
18
- rescue LoadError
19
- # This is used for installation process(from rake only)
20
- module Locale
21
- CTYPE = 0
22
- NUMERIC = 1
23
- TIME = 2
24
- COLLATE = 3
25
- MONETARY = 4
26
- MESSAGES = 5
27
- ALL = 6
28
-
29
- module_function
30
- def codeset; "UTF-8"; end
31
- def set(lc, val); "C"; end
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|mswin32|bccwin32/ =~ RUBY_PLATFORM
37
+ if /cygwin|mingw|win32/ =~ RUBY_PLATFORM
38
38
  require 'gettext/locale_win32'
39
39
  else
40
- require 'gettext/locale_default'
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
- def get(lctype = Locale::CTYPE)
45
- __get(lctype)
46
- end
47
-
48
- alias :setlocale :set
49
- alias :charset :codeset
50
-
51
- module_function :get, :setlocale, :charset
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 __FILE__ == $0
55
- p Locale.set(Locale::CTYPE, "")
56
- p Locale.set(Locale::CTYPE, nil)
57
- p Locale.set(Locale::CTYPE, "ja_JP.eucJP")
58
- p Locale.set(Locale::MESSAGES, nil)
59
- p Locale.get
60
- p Locale.codeset
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
+