gettext 1.5.0-mswin32 → 1.6.0-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. data/ChangeLog +113 -0
  2. data/NEWS +17 -1
  3. data/README +56 -46
  4. data/Rakefile +7 -3
  5. data/data/locale/cs/LC_MESSAGES/rails.mo +0 -0
  6. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  7. data/data/locale/de/LC_MESSAGES/rails.mo +0 -0
  8. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  9. data/data/locale/el/LC_MESSAGES/rails.mo +0 -0
  10. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  11. data/data/locale/es/LC_MESSAGES/rails.mo +0 -0
  12. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  13. data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
  14. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  15. data/data/locale/it/LC_MESSAGES/rails.mo +0 -0
  16. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  17. data/data/locale/ja/LC_MESSAGES/rails.mo +0 -0
  18. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/ko/LC_MESSAGES/rails.mo +0 -0
  20. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/nl/LC_MESSAGES/rails.mo +0 -0
  22. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/pt_BR/LC_MESSAGES/rails.mo +0 -0
  24. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/ru/LC_MESSAGES/rails.mo +0 -0
  26. data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
  27. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  28. data/data/locale/zh/LC_MESSAGES/rails.mo +0 -0
  29. data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
  30. data/ext/gettext/locale_system.c +3 -3
  31. data/lib/gettext.rb +149 -98
  32. data/lib/gettext/container.rb +3 -23
  33. data/lib/gettext/erb.rb +2 -2
  34. data/lib/gettext/locale_posix.rb +37 -5
  35. data/lib/gettext/locale_win32.rb +2 -1
  36. data/lib/gettext/mo.rb +6 -4
  37. data/lib/gettext/parser/activerecord.rb +7 -3
  38. data/lib/gettext/poparser.rb +298 -298
  39. data/lib/gettext/rails.rb +131 -112
  40. data/lib/gettext/rgettext.rb +3 -1
  41. data/lib/gettext/rmsgfmt.rb +3 -1
  42. data/lib/gettext/rmsgmerge.rb +3 -1
  43. data/lib/gettext/textdomain.rb +14 -8
  44. data/lib/gettext/textdomainmanager.rb +103 -0
  45. data/lib/gettext/version.rb +1 -1
  46. data/po/cs/rails.po +16 -16
  47. data/po/cs/rgettext.po +7 -3
  48. data/po/de/rails.po +16 -16
  49. data/po/de/rgettext.po +7 -3
  50. data/po/el/rails.po +16 -16
  51. data/po/el/rgettext.po +7 -3
  52. data/po/es/rails.po +16 -16
  53. data/po/es/rgettext.po +7 -3
  54. data/po/fr/rails.po +16 -16
  55. data/po/fr/rgettext.po +7 -3
  56. data/po/it/rails.po +79 -0
  57. data/po/it/rgettext.po +42 -32
  58. data/po/ja/rails.po +20 -18
  59. data/po/ja/rgettext.po +7 -3
  60. data/po/ko/rails.po +16 -16
  61. data/po/ko/rgettext.po +7 -3
  62. data/po/nl/rails.po +16 -16
  63. data/po/nl/rgettext.po +7 -3
  64. data/po/pt_BR/rails.po +16 -16
  65. data/po/pt_BR/rgettext.po +7 -3
  66. data/po/rails.pot +16 -16
  67. data/po/rgettext.pot +7 -3
  68. data/po/ru/rails.po +18 -18
  69. data/po/ru/rgettext.po +13 -9
  70. data/po/sv/rgettext.po +7 -3
  71. data/po/zh/rails.po +78 -0
  72. data/po/zh/rgettext.po +104 -0
  73. data/pre-setup.rb +1 -4
  74. data/samples/cgi/helloerb.rhtml +1 -0
  75. data/samples/cgi/locale/zh/LC_MESSAGES/helloerb1.mo +0 -0
  76. data/samples/cgi/locale/zh/LC_MESSAGES/helloerb2.mo +0 -0
  77. data/samples/cgi/locale/zh/LC_MESSAGES/hellolib.mo +0 -0
  78. data/samples/cgi/locale/zh/LC_MESSAGES/main.mo +0 -0
  79. data/samples/cgi/po/zh/helloerb1.po +60 -0
  80. data/samples/cgi/po/zh/helloerb2.po +52 -0
  81. data/samples/cgi/po/zh/hellolib.po +24 -0
  82. data/samples/cgi/po/zh/main.po +80 -0
  83. data/samples/hello.rb +28 -5
  84. data/samples/hello2.rb +13 -6
  85. data/samples/hello_noop.rb +20 -8
  86. data/samples/hello_plural.rb +16 -6
  87. data/samples/hello_textdomain.rb +13 -4
  88. data/samples/hellogtk.rb +5 -4
  89. data/samples/hellogtk2.rb +5 -6
  90. data/samples/locale/cs/LC_MESSAGES/hello2.mo +0 -0
  91. data/samples/locale/cs/LC_MESSAGES/hello_plural.mo +0 -0
  92. data/samples/locale/de/LC_MESSAGES/hello2.mo +0 -0
  93. data/samples/locale/de/LC_MESSAGES/hello_plural.mo +0 -0
  94. data/samples/locale/el/LC_MESSAGES/hello2.mo +0 -0
  95. data/samples/locale/el/LC_MESSAGES/hello_plural.mo +0 -0
  96. data/samples/locale/es/LC_MESSAGES/hello2.mo +0 -0
  97. data/samples/locale/es/LC_MESSAGES/hello_plural.mo +0 -0
  98. data/samples/locale/fr/LC_MESSAGES/hello2.mo +0 -0
  99. data/samples/locale/fr/LC_MESSAGES/hello_plural.mo +0 -0
  100. data/samples/locale/it/LC_MESSAGES/hello2.mo +0 -0
  101. data/samples/locale/it/LC_MESSAGES/hello_plural.mo +0 -0
  102. data/samples/locale/ja/LC_MESSAGES/hello2.mo +0 -0
  103. data/samples/locale/ja/LC_MESSAGES/hello_plural.mo +0 -0
  104. data/samples/locale/ko/LC_MESSAGES/hello2.mo +0 -0
  105. data/samples/locale/ko/LC_MESSAGES/hello_plural.mo +0 -0
  106. data/samples/locale/nl/LC_MESSAGES/hello2.mo +0 -0
  107. data/samples/locale/nl/LC_MESSAGES/hello_plural.mo +0 -0
  108. data/samples/locale/pt_BR/LC_MESSAGES/hello2.mo +0 -0
  109. data/samples/locale/pt_BR/LC_MESSAGES/hello_plural.mo +0 -0
  110. data/samples/locale/ru/LC_MESSAGES/hello2.mo +0 -0
  111. data/samples/locale/ru/LC_MESSAGES/hello_plural.mo +0 -0
  112. data/samples/locale/sv/LC_MESSAGES/hello2.mo +0 -0
  113. data/samples/locale/sv/LC_MESSAGES/hello_plural.mo +0 -0
  114. data/samples/locale/zh/LC_MESSAGES/hello.mo +0 -0
  115. data/samples/locale/zh/LC_MESSAGES/hello2.mo +0 -0
  116. data/samples/locale/zh/LC_MESSAGES/hello_noop.mo +0 -0
  117. data/samples/locale/zh/LC_MESSAGES/hello_plural.mo +0 -0
  118. data/samples/locale/zh/LC_MESSAGES/helloglade2.mo +0 -0
  119. data/samples/locale/zh/LC_MESSAGES/hellogtk.mo +0 -0
  120. data/samples/locale/zh/LC_MESSAGES/hellotk.mo +0 -0
  121. data/samples/po/cs/hello2.po +4 -4
  122. data/samples/po/cs/hello_plural.po +5 -5
  123. data/samples/po/de/hello2.po +4 -4
  124. data/samples/po/de/hello_plural.po +9 -6
  125. data/samples/po/el/hello2.po +4 -4
  126. data/samples/po/el/hello_plural.po +3 -3
  127. data/samples/po/es/hello2.po +4 -4
  128. data/samples/po/es/hello_plural.po +6 -6
  129. data/samples/po/fr/hello2.po +4 -4
  130. data/samples/po/fr/hello_plural.po +3 -3
  131. data/samples/po/hello2.pot +2 -2
  132. data/samples/po/hello_plural.pot +1 -1
  133. data/samples/po/it/hello2.po +4 -4
  134. data/samples/po/it/hello_plural.po +4 -5
  135. data/samples/po/ja/hello2.po +4 -4
  136. data/samples/po/ja/hello_plural.po +4 -5
  137. data/samples/po/ko/hello2.po +4 -4
  138. data/samples/po/ko/hello_plural.po +10 -7
  139. data/samples/po/nl/hello2.po +4 -4
  140. data/samples/po/nl/hello_plural.po +6 -7
  141. data/samples/po/pt_BR/hello2.po +4 -4
  142. data/samples/po/pt_BR/hello_plural.po +6 -6
  143. data/samples/po/ru/hello2.po +4 -4
  144. data/samples/po/ru/hello_plural.po +10 -7
  145. data/samples/po/sv/hello2.po +4 -4
  146. data/samples/po/sv/hello_plural.po +4 -4
  147. data/samples/po/zh/hello.po +23 -0
  148. data/samples/po/zh/hello2.po +31 -0
  149. data/samples/po/zh/hello_noop.po +27 -0
  150. data/samples/po/zh/hello_plural.po +25 -0
  151. data/samples/po/zh/helloglade2.po +31 -0
  152. data/samples/po/zh/hellogtk.po +23 -0
  153. data/samples/po/zh/hellotk.po +23 -0
  154. data/samples/rails/README +2 -2
  155. data/samples/rails/lib/tasks/gettext.rake +0 -3
  156. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  157. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  158. data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
  159. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  160. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  161. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  162. data/samples/rails/locale/it/LC_MESSAGES/blog.mo +0 -0
  163. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  164. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  165. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  166. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  167. data/samples/rails/locale/ru/LC_MESSAGES/blog.mo +0 -0
  168. data/samples/rails/locale/zh/LC_MESSAGES/blog.mo +0 -0
  169. data/samples/rails/po/blog.pot +1 -1
  170. data/samples/rails/po/cs/blog.po +1 -1
  171. data/samples/rails/po/de/blog.po +1 -1
  172. data/samples/rails/po/el/blog.po +1 -1
  173. data/samples/rails/po/en/blog.po +3 -3
  174. data/samples/rails/po/es/blog.po +1 -1
  175. data/samples/rails/po/fr/blog.po +1 -1
  176. data/samples/rails/po/it/blog.po +109 -0
  177. data/samples/rails/po/ja/blog.po +1 -14
  178. data/samples/rails/po/ko/blog.po +2 -2
  179. data/samples/rails/po/nl/blog.po +1 -1
  180. data/samples/rails/po/pt_BR/blog.po +1 -1
  181. data/samples/rails/po/ru/blog.po +1 -2
  182. data/samples/rails/po/zh/blog.po +109 -0
  183. data/samples/rails/vendor/plugins/gettext/README +17 -0
  184. data/samples/rails/vendor/plugins/gettext/Rakefile +17 -0
  185. data/samples/rails/vendor/plugins/gettext/lib/gettext_plugin.rb +16 -35
  186. data/samples/rails/{locale → vendor/plugins/gettext/locale}/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  187. data/samples/rails/{locale → vendor/plugins/gettext/locale}/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  188. data/samples/rails/{locale → vendor/plugins/gettext/locale}/el/LC_MESSAGES/gettext_plugin.mo +0 -0
  189. data/samples/rails/{locale → vendor/plugins/gettext/locale}/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  190. data/samples/rails/{locale → vendor/plugins/gettext/locale}/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
  191. data/samples/rails/vendor/plugins/gettext/locale/it/LC_MESSAGES/gettext_plugin.mo +0 -0
  192. data/samples/rails/{locale → vendor/plugins/gettext/locale}/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
  193. data/samples/rails/{locale → vendor/plugins/gettext/locale}/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  194. data/samples/rails/{locale → vendor/plugins/gettext/locale}/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  195. data/samples/rails/{locale → vendor/plugins/gettext/locale}/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  196. data/samples/rails/{locale → vendor/plugins/gettext/locale}/ru/LC_MESSAGES/gettext_plugin.mo +0 -0
  197. data/samples/rails/vendor/plugins/gettext/locale/zh/LC_MESSAGES/gettext_plugin.mo +0 -0
  198. data/samples/rails/{po → vendor/plugins/gettext/po}/cs/gettext_plugin.po +4 -4
  199. data/samples/rails/{po → vendor/plugins/gettext/po}/de/gettext_plugin.po +4 -4
  200. data/samples/rails/{po → vendor/plugins/gettext/po}/el/gettext_plugin.po +4 -4
  201. data/samples/rails/{po → vendor/plugins/gettext/po}/es/gettext_plugin.po +4 -4
  202. data/samples/rails/{po → vendor/plugins/gettext/po}/fr/gettext_plugin.po +4 -4
  203. data/samples/rails/{po → vendor/plugins/gettext/po}/gettext_plugin.pot +4 -4
  204. data/samples/rails/vendor/plugins/gettext/po/it/gettext_plugin.po +27 -0
  205. data/samples/rails/{po → vendor/plugins/gettext/po}/ja/gettext_plugin.po +4 -4
  206. data/samples/rails/{po → vendor/plugins/gettext/po}/ko/gettext_plugin.po +4 -4
  207. data/samples/rails/{po → vendor/plugins/gettext/po}/nl/gettext_plugin.po +4 -4
  208. data/samples/rails/{po → vendor/plugins/gettext/po}/pt_BR/gettext_plugin.po +4 -4
  209. data/samples/rails/{po → vendor/plugins/gettext/po}/ru/gettext_plugin.po +4 -5
  210. data/samples/rails/vendor/plugins/gettext/po/zh/gettext_plugin.po +27 -0
  211. data/test/gettext_test.rb +18 -14
  212. data/test/gettext_test_multi_textdomain.rb +49 -0
  213. data/test/locale/fr/LC_MESSAGES/test6.mo +0 -0
  214. data/test/locale/ja/LC_MESSAGES/test6.mo +0 -0
  215. data/test/po/fr/test6.po +23 -0
  216. data/test/po/ja/test6.po +23 -0
  217. data/test/test.sh +3 -1
  218. data/test/testlib1.rb +0 -5
  219. data/test/testlib5.rb +70 -0
  220. data/test/testlib6.rb +19 -0
  221. metadata +128 -33
  222. data/COPYING.ja +0 -51
  223. data/ext/gettext/Makefile +0 -178
  224. data/ext/gettext/locale_system-i386-mswin32.def +0 -2
  225. data/ext/gettext/locale_system.exp +0 -0
  226. data/ext/gettext/locale_system.lib +0 -0
  227. data/ext/gettext/locale_system.obj +0 -0
  228. data/ext/gettext/locale_system.pdb +0 -0
  229. data/ext/gettext/locale_system.so +0 -0
  230. data/ext/gettext/mkmf.log +0 -16
  231. data/ext/gettext/vc70.pdb +0 -0
data/lib/gettext/rails.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: rails.rb,v 1.33 2006/05/06 14:59:08 mutoh Exp $
9
+ $Id: rails.rb,v 1.36 2006/06/04 14:43:37 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'gettext/cgi'
@@ -22,12 +22,15 @@ module GetText #:nodoc:
22
22
  # See <Ruby-GetText-Package HOWTO for Ruby on Rails (http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html>.
23
23
  module Rails
24
24
  include GetText
25
- extend GetText
26
25
 
27
26
  Rails = ::Rails #:nodoc:
28
27
 
29
28
  alias :_bindtextdomain :bindtextdomain #:nodoc:
30
29
 
30
+ def self.included(mod) #:nodoc:
31
+ mod.extend self
32
+ end
33
+
31
34
  module_function
32
35
  # Bind a textdomain(#{path}/#{locale}/LC_MESSAGES/#{domainname}.mo) to your program.
33
36
  # Notes the textdomain scope becomes all of the controllers/views/models in your app.
@@ -39,58 +42,44 @@ module GetText #:nodoc:
39
42
  # On the other hand, you need to call this in helpers/plugins.
40
43
  #
41
44
  # * domainname: the textdomain name.
42
- # * locale: the locale value such as "ja-JP". When the value is nil,
43
- # * charset: the charset. Generally UTF-8 is recommanded.
44
- # * with_model: false if you want to ignore model support.
45
+ # * options: options as a Hash.
46
+ # * :locale - the locale value such as "ja-JP". When the value is nil,
47
+ # locale is searched the order by this value > "lang" value of QUERY_STRING >
48
+ # params["lang"] > "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value
49
+ # > Default locale(en).
50
+ # * :path - the path to the mo-files. Default is "RAIL_ROOT/locale".
51
+ # * :charset - the charset. Generally UTF-8 is recommanded.
52
+ # And the charset is set order by "the argument of bindtextdomain"
53
+ # > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
54
+ # * :with_model - false if you want to ignore ActiveRecord support.
55
+ # * :with_helper - false if you want to ignore ApplicationHelper support.
45
56
  #
46
- # locale is searched the order by this value > "lang" value of QUERY_STRING >
47
- # "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
48
- # And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
57
+ # Note: Don't use locale, charset, with_model argument(not in options).
58
+ # They are remained for backward compatibility.
49
59
  #
50
- def bindtextdomain(domainname, _cgi = nil, locale = nil, charset = nil, with_model = true)
60
+ def bindtextdomain(domainname, options = {}, locale = nil, charset = nil, with_model = true)
61
+ opt = {:with_helper => true, :with_model => true}
62
+ if options.kind_of? CGI
63
+ # For backward compatibility
64
+ opt.merge!(:cgi => options, :locale => locale, :charset => charset, :with_model => with_model)
65
+ else
66
+ opt.merge!(options)
67
+ end
68
+ opt[:path] ||= File.join(RAILS_ROOT, "locale")
51
69
  Locale.set_current(nil) # IMPORTANT! current locale should be nil once(default is used).
52
- set_cgi(_cgi) if _cgi
53
- @gettext_container_domainname = domainname
54
- path = File.join(RAILS_ROOT, "locale")
55
- _bindtextdomain(domainname, path, locale, charset)
56
-
57
- bindtextdomain_to(ActiveRecord::Base, domainname) if with_model
70
+ set_cgi(opt[:cgi]) if opt[:cgi]
71
+ ret = _bindtextdomain(domainname, opt)
72
+ bindtextdomain_to(ActiveRecord::Base, domainname) if opt[:with_model]
73
+ bindtextdomain_to(ApplicationHelper, domainname) if opt[:with_helper]
74
+ ret
58
75
  end
59
76
 
60
77
  def bindtextdomain_to(klass, domainname) #:nodoc:
61
78
  klass.class_eval {
79
+ include GetText
62
80
  textdomain(domainname)
63
- def self.human_attribute_name(attribute_key_name) #:nodoc:
64
- s_("#{self}|#{attribute_key_name.humanize}")
65
- end
66
- def self.human_attribute_table_name_for_error(table_name) #:nodoc:
67
- _(table_name.gsub(/_/, " "))
68
- end
69
81
  }
70
82
  end
71
-
72
- def callersrc #:nodoc:
73
- @gettext_container_domainname = nil unless defined? @gettext_container_domainname
74
- @gettext_container_domainname
75
- end
76
-
77
- # true to use localized templates such as list.rhtml, list_ja.rhtml, list_ja_JP.rhtml.
78
- # * setting: true if localized, otherwise false. Default is true.
79
- # * Returns: setting
80
- def use_localized_templates(setting)
81
- @@gettext_use_localized_templates = setting
82
- end
83
-
84
- # true if it use localized templates. See GetText::Rails.use_localized_templates
85
- # for more details.
86
- # * Returns: true or false.
87
- def use_localized_templates?
88
- if defined? @@gettext_use_localized_templates
89
- @@gettext_use_localized_templates
90
- else
91
- true
92
- end
93
- end
94
83
  end
95
84
  end
96
85
 
@@ -99,7 +88,6 @@ module ActionController #:nodoc:
99
88
  class Base
100
89
  helper GetText::Rails
101
90
  include GetText::Rails
102
- extend GetText::Rails
103
91
 
104
92
  @@gettext_domainname = nil
105
93
  @@gettext_content_type = nil
@@ -111,9 +99,9 @@ module ActionController #:nodoc:
111
99
  if defined? request.cgi
112
100
  cgi_ = request.cgi
113
101
  cgi_.params["lang"] = [@params["lang"]] if @params["lang"]
114
- bindtextdomain(@@gettext_domainname, cgi_) #You need to pass CGI object first.
102
+ bindtextdomain(@@gettext_domainname, {:cgi => cgi_}) #You need to pass CGI object first.
115
103
  else
116
- bindtextdomain(@@gettext_domainname, nil, @params["lang"])
104
+ bindtextdomain(@@gettext_domainname, {:locale => @params["lang"]})
117
105
  end
118
106
  end
119
107
 
@@ -131,19 +119,23 @@ module ActionController #:nodoc:
131
119
  ActiveRecord::Errors.class_eval{
132
120
  # You need to call bindtextdomain here because ActiveRecord::Errors doesn't know
133
121
  # what locale is used in.
134
- GetText.bindtextdomain("rails")
122
+ bindtextdomain("rails")
135
123
  }
136
124
  end
137
125
 
138
126
  # Bind a 'textdomain' to all of the controllers/views/models. Call this instead of GetText.bindtextdomain.
139
127
  # * textdomain: the textdomain
140
- # * charset: the output charset. Default is "UTF-8"
141
- # * content_type: the content type. Default is "text/html"
128
+ # * options: options as a Hash.
129
+ # * :charset - the output charset. Default is "UTF-8"
130
+ # * :content_type - the content type. Default is "text/html"
142
131
  #
143
132
  # locale is searched the order by @params["lang"] > "lang" value of QUERY_STRING >
144
133
  # "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
145
134
  # And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
146
135
  #
136
+ # Note: Don't use content_type argument(not in options).
137
+ # They are remained for backward compatibility.
138
+ #
147
139
  # If you want to separate the textdomain each controllers, you need to call this function in the each controllers.
148
140
  #
149
141
  # app/controller/blog_controller.rb:
@@ -154,10 +146,15 @@ module ActionController #:nodoc:
154
146
  # :
155
147
  # :
156
148
  # end
157
- def self.init_gettext(domainname, charset = "UTF-8", content_type = "text/html")
158
- GetText.output_charset = charset
149
+ def self.init_gettext(domainname, options = {}, content_type = "text/html")
150
+ opt = {:charset => "UTF-8", :content_type => content_type}
151
+ if options.kind_of? String
152
+ # For backward compatibility
153
+ opt.merge!(:charset => options, :content_type => content_type)
154
+ end
155
+ GetText.output_charset = opt[:charset]
159
156
  @@gettext_domainname = domainname
160
- @@gettext_content_type = content_type
157
+ @@gettext_content_type = opt[:content_type]
161
158
  end
162
159
  end
163
160
 
@@ -183,8 +180,13 @@ module ActiveRecord #:nodoc:
183
180
  end
184
181
 
185
182
  class Base
186
- include GetText::Rails # Important
187
- extend GetText::Rails # Important
183
+ def self.human_attribute_name(attribute_key_name) #:nodoc:
184
+ s_("#{self}|#{attribute_key_name.humanize}")
185
+ end
186
+
187
+ def self.human_attribute_table_name_for_error(table_name) #:nodoc:
188
+ _(table_name.gsub(/_/, " "))
189
+ end
188
190
 
189
191
  @@error_message_title = nil
190
192
  @@error_message_explanation = nil
@@ -205,6 +207,19 @@ module ActiveRecord #:nodoc:
205
207
  @@error_message_title = [single_msg, plural_msg]
206
208
  end
207
209
 
210
+ # Very ugly but...
211
+ @@custom_error_messages_d = {}
212
+ def self.validates_length_of(*attrs) #:nodoc:
213
+ if attrs.last.is_a?(Hash)
214
+ msg = attrs.last[:message]
215
+ @@custom_error_messages_d[msg] = /#{Regexp.escape(msg).sub(/%d/, '(\d+)')}/ if msg
216
+ end
217
+ validates_size_of(*attrs)
218
+ end
219
+ def custom_error_messages_d #:nodoc:
220
+ @@custom_error_messages_d
221
+ end
222
+
208
223
  def self.columns
209
224
  unless @columns
210
225
  @columns = connection.columns(table_name, "#{name} Columns")
@@ -254,7 +269,6 @@ module ActiveRecord #:nodoc:
254
269
 
255
270
  class Errors #:nodoc:
256
271
  include GetText
257
- extend GetText
258
272
 
259
273
  RE_FIELD_NAME = /%\{fn\}/ #:nodoc:
260
274
 
@@ -274,34 +288,39 @@ module ActiveRecord #:nodoc:
274
288
  :not_a_number => N_("%{fn} is not a number")
275
289
  )
276
290
  @@default_error_messages_d = {
277
- :too_long => /#{Regexp.escape(default_error_messages[:too_long]).sub(/%d/, '(\d+)')}/,
278
- :too_short => /#{Regexp.escape(default_error_messages[:too_short]).sub(/%d/, '(\d+)')}/,
279
- :wrong_length => /#{Regexp.escape(default_error_messages[:wrong_length]).sub(/%d/, '(\d+)')}/,
291
+ default_error_messages[:too_long] => /#{Regexp.escape(default_error_messages[:too_long]).sub(/%d/, '(\d+)')}/,
292
+ default_error_messages[:too_short] =>/#{Regexp.escape(default_error_messages[:too_short]).sub(/%d/, '(\d+)')}/,
293
+ default_error_messages[:wrong_length] =>/#{Regexp.escape(default_error_messages[:wrong_length]).sub(/%d/, '(\d+)')}/,
280
294
  }
295
+ cattr_accessor :default_error_messages_d
281
296
 
282
297
  def full_messages #:nodoc:
283
298
  full_messages = []
284
299
  @errors.each_key do |attr|
285
- @errors[attr].each do |msg|
286
- next if msg.nil?
287
- #Ugly but... :-<
288
- @@default_error_messages_d.each do |key, regexp|
289
- if regexp =~ msg
290
- msg = _(default_error_messages[key]) % $1.to_i
291
- break
292
- end
293
- end
294
- custom_msg = @base.gettext(msg)
295
- custom_msg = _(msg) if custom_msg == msg
296
-
297
- if attr == "base"
298
- full_messages << custom_msg
299
- elsif RE_FIELD_NAME =~ msg
300
- full_messages << custom_msg % {:fn => @base.class.human_attribute_name(attr)}
301
- else
302
- full_messages << @base.class.human_attribute_name(attr) + " " + custom_msg
303
- end
304
- end
300
+ @errors[attr].each do |msg|
301
+ next if msg.nil?
302
+ custom_msg = nil
303
+ #Ugly but... :-<
304
+ @@default_error_messages_d.merge(@base.custom_error_messages_d).each do |key, regexp|
305
+ if regexp =~ msg
306
+ custom_msg = @base.gettext(key)
307
+ custom_msg = _(msg) if custom_msg == msg
308
+ custom_msg = _(custom_msg) % $1.to_i
309
+ break
310
+ end
311
+ end
312
+ unless custom_msg
313
+ custom_msg = @base.gettext(msg)
314
+ custom_msg = _(msg) if custom_msg == msg
315
+ end
316
+ if attr == "base"
317
+ full_messages << custom_msg
318
+ elsif RE_FIELD_NAME =~ custom_msg
319
+ full_messages << custom_msg % {:fn => @base.class.human_attribute_name(attr)}
320
+ else
321
+ full_messages << @base.class.human_attribute_name(attr) + " " + custom_msg
322
+ end
323
+ end
305
324
  end
306
325
  full_messages
307
326
  end
@@ -315,12 +334,10 @@ module ActionView #:nodoc:
315
334
  # This provides to find localized template files such as foo_ja.rhtml, foo_ja_JP.rhtml
316
335
  # instead of foo.rhtml. If the file isn't found, foo.rhtml is used.
317
336
  def render_file(template_path, use_full_path = true, local_assigns = {})
318
- if GetText::Rails.use_localized_templates?
319
- locale = GetText.locale
320
- [locale.to_general, locale.to_s, locale.language, Locale.default.language].each do |v|
321
- localized_path = "#{template_path}_#{v}"
322
- return render_file_without_locale(localized_path, use_full_path, local_assigns) if file_exists? localized_path
323
- end
337
+ locale = GetText.locale
338
+ [locale.to_general, locale.to_s, locale.language, Locale.default.language].each do |v|
339
+ localized_path = "#{template_path}_#{v}"
340
+ return render_file_without_locale(localized_path, use_full_path, local_assigns) if file_exists? localized_path
324
341
  end
325
342
  render_file_without_locale(template_path, use_full_path, local_assigns)
326
343
  end
@@ -375,36 +392,38 @@ module ActionView #:nodoc:
375
392
  end
376
393
  end
377
394
 
378
- module ActionMailer #:nodoc:
379
- class Base #:nodoc:
380
- helper GetText::Rails
381
- include GetText::Rails
382
- extend GetText::Rails
383
-
384
- alias :_create! :create! #:nodoc:
385
-
386
- def base64(text, charset="iso-2022-jp", convert=true)
387
- if convert
388
- if charset == "iso-2022-jp"
389
- text = NKF.nkf('-j -m0', text)
390
- end
391
- end
392
- text = TMail::Base64.folding_encode(text)
393
- "=?#{charset}?B?#{text}?="
394
- end
395
-
396
- def create!(*arg) #:nodoc:
397
- _create!(*arg)
398
- if Locale.get.language == "ja"
399
- require 'nkf'
400
- @mail.subject = base64(@mail.subject)
401
- part = @mail.parts.empty? ? @mail : @mail.parts.first
402
- if part.content_type == 'text/plain'
403
- part.charset = 'iso-2022-jp'
404
- part.body = NKF.nkf('-j', part.body)
395
+ if defined? ActionMailer
396
+ module ActionMailer #:nodoc:
397
+ class Base #:nodoc:
398
+ helper GetText::Rails
399
+ include GetText::Rails
400
+ extend GetText::Rails
401
+
402
+ alias :_create! :create! #:nodoc:
403
+
404
+ def base64(text, charset="iso-2022-jp", convert=true)
405
+ if convert
406
+ if charset == "iso-2022-jp"
407
+ text = NKF.nkf('-j -m0', text)
405
408
  end
409
+ end
410
+ text = TMail::Base64.folding_encode(text)
411
+ "=?#{charset}?B?#{text}?="
406
412
  end
413
+
414
+ def create!(*arg) #:nodoc:
415
+ _create!(*arg)
416
+ if Locale.get.language == "ja"
417
+ require 'nkf'
418
+ @mail.subject = base64(@mail.subject)
419
+ part = @mail.parts.empty? ? @mail : @mail.parts.first
420
+ if part.content_type == 'text/plain'
421
+ part.charset = 'iso-2022-jp'
422
+ part.body = NKF.nkf('-j', part.body)
423
+ end
424
+ end
407
425
  @mail
426
+ end
408
427
  end
409
428
  end
410
429
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require 'optparse'
16
16
  require 'gettext'
17
+ require 'rbconfig'
17
18
 
18
19
  module GetText
19
20
 
@@ -24,7 +25,7 @@ module GetText
24
25
 
25
26
  # constant values
26
27
  VERSION = GetText::VERSION
27
- DATE = %w($Date: 2006/02/22 16:42:41 $)[1]
28
+ DATE = %w($Date: 2006/06/04 15:07:34 $)[1]
28
29
  MAX_LINE_LEN = 70
29
30
 
30
31
  @ex_parsers = []
@@ -142,6 +143,7 @@ msgstr ""
142
143
 
143
144
  opts.on_tail("--version", _("display version information and exit")) do
144
145
  puts "#{$0} #{VERSION} (#{DATE})"
146
+ puts "#{File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
145
147
  exit
146
148
  end
147
149
 
@@ -11,6 +11,7 @@ require 'optparse'
11
11
  require 'fileutils'
12
12
  require 'gettext'
13
13
  require 'gettext/poparser'
14
+ require 'rbconfig'
14
15
 
15
16
  module GetText
16
17
  GetText.bindtextdomain("rgettext")
@@ -19,7 +20,7 @@ module GetText
19
20
  extend GetText
20
21
 
21
22
  VERSION = GetText::VERSION
22
- DATE = %w($Date: 2006/02/22 16:42:41 $)[1] # :nodoc:
23
+ DATE = %w($Date: 2006/06/04 15:07:34 $)[1] # :nodoc:
23
24
 
24
25
  module_function
25
26
  def run(targetfile = nil, output_path = nil) # :nodoc:
@@ -55,6 +56,7 @@ module GetText
55
56
 
56
57
  opts.on_tail("--version", _("display version information and exit")) do
57
58
  puts "#{$0} #{VERSION} (#{DATE})"
59
+ puts "#{File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
58
60
  exit
59
61
  end
60
62
  opts.parse!(ARGV)
@@ -11,6 +11,7 @@
11
11
  require 'optparse'
12
12
  require 'gettext'
13
13
  require 'gettext/poparser'
14
+ require 'rbconfig'
14
15
 
15
16
  module GetText
16
17
 
@@ -393,7 +394,7 @@ module GetText
393
394
 
394
395
  # constant values
395
396
  VERSION = GetText::VERSION
396
- DATE = %w($Date: 2006/02/23 14:53:59 $)[1]
397
+ DATE = %w($Date: 2006/06/04 15:07:34 $)[1]
397
398
 
398
399
  module_function
399
400
 
@@ -419,6 +420,7 @@ module GetText
419
420
 
420
421
  opts.on_tail("--version", _("display version information and exit")) do
421
422
  puts "#{$0} #{VERSION} (#{DATE})"
423
+ puts "#{File.join(::Config::CONFIG["bindir"], ::Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
422
424
  exit
423
425
  end
424
426
 
@@ -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: textdomain.rb,v 1.16 2006/04/29 17:17:15 mutoh Exp $
13
+ $Id: textdomain.rb,v 1.17 2006/06/04 14:43:37 mutoh Exp $
14
14
  =end
15
15
 
16
16
  require 'gettext/string'
@@ -27,7 +27,9 @@ module GetText
27
27
  GEM_PATH_RE = /(.*)\/lib$/ # :nodoc:
28
28
 
29
29
  attr_reader :current_locale
30
+ attr_reader :locale_paths
30
31
  attr_reader :current_mo
32
+ attr_reader :name
31
33
 
32
34
  @@check_mo = false
33
35
  # Check mo-file is modified or not, and if mo-file is modified,
@@ -46,10 +48,12 @@ module GetText
46
48
  @@check_mo = val
47
49
  end
48
50
  # The default locale paths.
51
+ CONFIG_PREFIX = Config::CONFIG['prefix'].gsub(/\/local/, "")
49
52
  DEFAULT_LOCALE_PATHS = [
50
53
  "#{Config::CONFIG['datadir']}/locale/%{locale}/LC_MESSAGES/%{name}.mo",
51
- "#{Config::CONFIG['prefix']}/share/locale/%{locale}/LC_MESSAGES/%{name}.mo",
52
- "#{Config::CONFIG['prefix']}/local/share/locale/%{locale}/LC_MESSAGES/%{name}.mo"
54
+ "#{Config::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{locale}/LC_MESSAGES/%{name}.mo",
55
+ "#{CONFIG_PREFIX}/share/locale/%{locale}/LC_MESSAGES/%{name}.mo",
56
+ "#{CONFIG_PREFIX}/local/share/locale/%{locale}/LC_MESSAGES/%{name}.mo"
53
57
  ].uniq
54
58
 
55
59
  # Add default locale path. Usually you should use GetText.add_default_locale_path instead.
@@ -109,13 +113,13 @@ module GetText
109
113
 
110
114
  # Gets the translated string.
111
115
  # * msgid: the original message.
112
- # * Returns: the translated string.
116
+ # * Returns: the translated string or nil if not found.
113
117
  def gettext(msgid)
114
118
  return "" if msgid == "" or msgid.nil?
115
119
  if @current_mo and @current_mo[msgid] and (@current_mo[msgid].size > 0)
116
120
  @current_mo[msgid]
117
121
  else
118
- msgid
122
+ nil
119
123
  end
120
124
  end
121
125
 
@@ -123,11 +127,13 @@ module GetText
123
127
  # * msgid: the original message(single).
124
128
  # * msgid: the original message(plural).
125
129
  # * n: the number
126
- # * Returns: the translated string.
130
+ # * Returns: the translated string or nil if not found.
127
131
  def ngettext(msgid, msgid_plural, n)
128
132
  key = msgid + "\000" + msgid_plural
129
133
  msg = gettext(key)
130
- if msg == key
134
+ if ! msg
135
+ nil
136
+ elsif msg == key
131
137
  msg = n == 1 ? msgid : msgid_plural
132
138
  elsif msg.include?("\000")
133
139
  ary = msg.split("\000")
@@ -172,7 +178,7 @@ module GetText
172
178
  end
173
179
  end
174
180
  end
175
- locales = [@current_locale.orig_str, @current_locale.to_posix, @current_locale.language]
181
+ locales = [@current_locale.orig_str, @current_locale.to_posix, @current_locale.language].uniq
176
182
  @locale_paths.each do |dir|
177
183
  locales.each{|locale|
178
184
  fname = dir % {:locale => locale, :name => @name}