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
@@ -0,0 +1,20 @@
1
+ =begin
2
+ extconf.rb
3
+
4
+ Copyright (C) 2002-2006 Masao Mutoh <mutoh@highway.ne.jp>
5
+
6
+ You may redistribute it and/or modify it under the same
7
+ license terms as Ruby.
8
+
9
+ $Id: extconf.rb,v 1.1 2006/02/07 00:24:45 mutoh Exp $
10
+ =end
11
+
12
+ require 'mkmf'
13
+
14
+ if RUBY_PLATFORM =~ /cygwin|mingw|mswin32|bccwin32/
15
+ have_header 'windows.h'
16
+ else
17
+ have_func 'setlocale'
18
+ have_func 'nl_langinfo'
19
+ end
20
+ create_makefile 'locale_system'
@@ -0,0 +1,2 @@
1
+ EXPORTS
2
+ Init_locale_system
@@ -1,11 +1,11 @@
1
1
  /* -*- c-file-style: "ruby"; tab-width: 4 -*-
2
2
  *
3
- * Copyright (C) 2002-2005 Masao Mutoh
3
+ * Copyright (C) 2002-2006 Masao Mutoh
4
4
  *
5
5
  * You may redistribute it and/or modify it under the same
6
6
  * license terms as Ruby.
7
7
  *
8
- * $Id: _locale.c,v 1.2 2005/08/20 17:05:34 mutoh Exp $
8
+ * $Id: locale_system.c,v 1.3 2006/02/20 12:35:06 mutoh Exp $
9
9
  */
10
10
 
11
11
  #include "ruby.h"
@@ -29,11 +29,7 @@ static VALUE
29
29
  gt_locale_id_win32(self)
30
30
  VALUE self;
31
31
  {
32
- int lcid, pri_id, sub_id;
33
- lcid = GetUserDefaultLangID();
34
- pri_id = lcid & 0x3ff;
35
- sub_id = lcid >> 10;
36
- return rb_assoc_new(INT2FIX(pri_id), INT2FIX(sub_id));
32
+ return INT2NUM(GetUserDefaultLangID());
37
33
  }
38
34
  #endif
39
35
  static VALUE
@@ -64,23 +60,23 @@ gt_codeset(self)
64
60
  #endif
65
61
  }
66
62
 
67
- void Init__locale()
63
+ void Init_locale_system()
68
64
  {
69
65
  VALUE mLocale = rb_define_module("Locale");
70
-
66
+ VALUE mSystem = rb_define_module_under(mLocale, "System");
71
67
  #if defined HAVE_WINDOWS_H
72
- rb_define_module_function(mLocale, "__locale_id", gt_locale_id_win32, 0);
68
+ rb_define_module_function(mSystem, "locale_id", gt_locale_id_win32, 0);
73
69
  #endif
74
- rb_define_module_function(mLocale, "set", gt_setlocale, 2);
75
- rb_define_module_function(mLocale, "codeset", gt_codeset, 0);
70
+ rb_define_module_function(mSystem, "set", gt_setlocale, 2);
71
+ rb_define_module_function(mSystem, "codeset", gt_codeset, 0);
76
72
  # if defined HAVE_SETLOCALE
77
- rb_define_const(mLocale, "ALL", INT2NUM(LC_ALL));
78
- rb_define_const(mLocale, "COLLATE", INT2NUM(LC_COLLATE));
79
- rb_define_const(mLocale, "CTYPE", INT2NUM(LC_CTYPE));
80
- rb_define_const(mLocale, "MESSAGES", INT2NUM(LC_MESSAGES));
81
- rb_define_const(mLocale, "MONETARY", INT2NUM(LC_MONETARY));
82
- rb_define_const(mLocale, "NUMERIC", INT2NUM(LC_NUMERIC));
83
- rb_define_const(mLocale, "TIME", INT2NUM(LC_TIME));
73
+ rb_define_const(mSystem, "ALL", INT2NUM(LC_ALL));
74
+ rb_define_const(mSystem, "COLLATE", INT2NUM(LC_COLLATE));
75
+ rb_define_const(mSystem, "CTYPE", INT2NUM(LC_CTYPE));
76
+ rb_define_const(mSystem, "MESSAGES", INT2NUM(LC_MESSAGES));
77
+ rb_define_const(mSystem, "MONETARY", INT2NUM(LC_MONETARY));
78
+ rb_define_const(mSystem, "NUMERIC", INT2NUM(LC_NUMERIC));
79
+ rb_define_const(mSystem, "TIME", INT2NUM(LC_TIME));
84
80
  #endif
85
81
 
86
82
  }
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,10 @@
1
+ have_header: checking for windows.h... -------------------- no
2
+
3
+ "cl -IE:/gettext/ext/gettext -Ie:/ruby/lib/ruby/1.8/i386-mswin32 -I. -I./.. -I./../missing -MD -Zi -O2b2xg- -G6 conftest.c -P"
4
+ checked program was:
5
+ /* begin */
6
+ #include <windows.h>
7
+ /* end */
8
+
9
+ --------------------
10
+
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