gettext 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. data/ChangeLog +65 -0
  2. data/NEWS +20 -0
  3. data/README +9 -9
  4. data/Rakefile +30 -2
  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/doc/classes/ActionController/Base.html +169 -0
  31. data/doc/classes/ActionController/Base.src/M000014.html +37 -0
  32. data/doc/classes/ActionController/Base.src/M000015.html +30 -0
  33. data/doc/classes/ActiveRecord/Base.html +210 -0
  34. data/doc/classes/ActiveRecord/Base.src/M000114.html +30 -0
  35. data/doc/classes/ActiveRecord/Base.src/M000115.html +30 -0
  36. data/doc/classes/ActiveRecord/Base.src/M000116.html +30 -0
  37. data/doc/classes/ActiveRecord/Base.src/M000117.html +30 -0
  38. data/doc/classes/ActiveRecord/Base.src/M000118.html +37 -0
  39. data/doc/classes/ActiveRecord/Base.src/M000119.html +30 -0
  40. data/doc/classes/ActiveRecord/Base.src/M000120.html +30 -0
  41. data/doc/classes/ActiveRecord/ConnectionAdapters/Column.html +117 -0
  42. data/doc/classes/ActiveRecord/ConnectionAdapters/Column.src/M000113.html +30 -0
  43. data/doc/classes/ActiveRecord/Migration.html +96 -0
  44. data/doc/classes/GetText.html +863 -0
  45. data/doc/classes/GetText.src/M000017.html +30 -0
  46. data/doc/classes/GetText.src/M000018.html +31 -0
  47. data/doc/classes/GetText.src/M000019.html +46 -0
  48. data/doc/classes/GetText.src/M000020.html +42 -0
  49. data/doc/classes/GetText.src/M000021.html +32 -0
  50. data/doc/classes/GetText.src/M000022.html +30 -0
  51. data/doc/classes/GetText.src/M000023.html +30 -0
  52. data/doc/classes/GetText.src/M000024.html +31 -0
  53. data/doc/classes/GetText.src/M000025.html +30 -0
  54. data/doc/classes/GetText.src/M000026.html +49 -0
  55. data/doc/classes/GetText.src/M000027.html +38 -0
  56. data/doc/classes/GetText.src/M000028.html +35 -0
  57. data/doc/classes/GetText.src/M000029.html +44 -0
  58. data/doc/classes/GetText.src/M000030.html +30 -0
  59. data/doc/classes/GetText.src/M000031.html +30 -0
  60. data/doc/classes/GetText.src/M000032.html +36 -0
  61. data/doc/classes/GetText.src/M000033.html +53 -0
  62. data/doc/classes/GetText.src/M000034.html +46 -0
  63. data/doc/classes/GetText.src/M000035.html +31 -0
  64. data/doc/classes/GetText.src/M000036.html +31 -0
  65. data/doc/classes/GetText.src/M000037.html +30 -0
  66. data/doc/classes/GetText.src/M000038.html +30 -0
  67. data/doc/classes/GetText.src/M000039.html +30 -0
  68. data/doc/classes/GetText.src/M000040.html +30 -0
  69. data/doc/classes/GetText.src/M000041.html +48 -0
  70. data/doc/classes/GetText.src/M000042.html +18 -0
  71. data/doc/classes/GetText.src/M000043.html +34 -0
  72. data/doc/classes/GetText.src/M000044.html +30 -0
  73. data/doc/classes/GetText.src/M000045.html +20 -0
  74. data/doc/classes/GetText/ActiveRecordParser.html +148 -0
  75. data/doc/classes/GetText/ActiveRecordParser.src/M000048.html +35 -0
  76. data/doc/classes/GetText/ActiveRecordParser.src/M000049.html +30 -0
  77. data/doc/classes/GetText/ErbContainer.html +161 -0
  78. data/doc/classes/GetText/ErbContainer.src/M000046.html +31 -0
  79. data/doc/classes/GetText/ErbContainer.src/M000047.html +30 -0
  80. data/doc/classes/GetText/ErbParser.html +113 -0
  81. data/doc/classes/GetText/ErbParser.src/M000051.html +32 -0
  82. data/doc/classes/GetText/GetText.html +89 -0
  83. data/doc/classes/GetText/GetText/Container.html +95 -0
  84. data/doc/classes/GetText/GladeParser.html +109 -0
  85. data/doc/classes/GetText/NoboundTextDomainError.html +98 -0
  86. data/doc/classes/GetText/PoParser.html +121 -0
  87. data/doc/classes/GetText/PoParser.src/M000068.html +30 -0
  88. data/doc/classes/GetText/Rails.html +172 -0
  89. data/doc/classes/GetText/Rails.src/M000050.html +43 -0
  90. data/doc/classes/GetText/RubyParser.html +99 -0
  91. data/doc/classes/GetText/TextDomain.html +345 -0
  92. data/doc/classes/GetText/TextDomain.src/M000052.html +30 -0
  93. data/doc/classes/GetText/TextDomain.src/M000053.html +30 -0
  94. data/doc/classes/GetText/TextDomain.src/M000054.html +30 -0
  95. data/doc/classes/GetText/TextDomain.src/M000055.html +58 -0
  96. data/doc/classes/GetText/TextDomain.src/M000056.html +32 -0
  97. data/doc/classes/GetText/TextDomain.src/M000057.html +35 -0
  98. data/doc/classes/GetText/TextDomain.src/M000058.html +49 -0
  99. data/doc/classes/GetText/TextDomain.src/M000059.html +30 -0
  100. data/doc/classes/GetText/TextDomain.src/M000060.html +18 -0
  101. data/doc/classes/GetText/TextDomain.src/M000061.html +18 -0
  102. data/doc/classes/GetText/TextDomain.src/M000062.html +18 -0
  103. data/doc/classes/GetText/TextDomain.src/M000063.html +46 -0
  104. data/doc/classes/GetText/TextDomain.src/M000064.html +20 -0
  105. data/doc/classes/GetText/TextDomain.src/M000065.html +23 -0
  106. data/doc/classes/GetText/TextDomain.src/M000066.html +37 -0
  107. data/doc/classes/GetText/TextDomain.src/M000067.html +18 -0
  108. data/doc/classes/GetText/TextDomainManager.html +253 -0
  109. data/doc/classes/GetText/TextDomainManager.src/M000052.html +18 -0
  110. data/doc/classes/GetText/TextDomainManager.src/M000053.html +18 -0
  111. data/doc/classes/GetText/TextDomainManager.src/M000054.html +20 -0
  112. data/doc/classes/GetText/TextDomainManager.src/M000055.html +18 -0
  113. data/doc/classes/GetText/TextDomainManager.src/M000056.html +20 -0
  114. data/doc/classes/GetText/TextDomainManager.src/M000057.html +31 -0
  115. data/doc/classes/GetText/TextDomainManager.src/M000058.html +21 -0
  116. data/doc/classes/GetText/TextDomainManager.src/M000059.html +24 -0
  117. data/doc/classes/GetText/TextDomainManager.src/M000060.html +30 -0
  118. data/doc/classes/GetText/TextDomainManager.src/M000061.html +30 -0
  119. data/doc/classes/GetText/TextDomainManager.src/M000062.html +32 -0
  120. data/doc/classes/GetText/TextDomainManager.src/M000063.html +30 -0
  121. data/doc/classes/GetText/TextDomainManager.src/M000064.html +32 -0
  122. data/doc/classes/GetText/TextDomainManager.src/M000065.html +43 -0
  123. data/doc/classes/GetText/TextDomainManager.src/M000066.html +33 -0
  124. data/doc/classes/GetText/TextDomainManager.src/M000067.html +36 -0
  125. data/doc/classes/Iconv.html +140 -0
  126. data/doc/classes/Iconv.src/M000016.html +41 -0
  127. data/doc/classes/Iconv/Failure.html +86 -0
  128. data/doc/classes/Iconv/IllegalSequence.html +96 -0
  129. data/doc/classes/Iconv/InvalidCharacter.html +96 -0
  130. data/doc/classes/Iconv/InvalidEncoding.html +96 -0
  131. data/doc/classes/Locale.html +648 -0
  132. data/doc/classes/Locale.src/M000069.html +32 -0
  133. data/doc/classes/Locale.src/M000070.html +31 -0
  134. data/doc/classes/Locale.src/M000071.html +30 -0
  135. data/doc/classes/Locale.src/M000072.html +34 -0
  136. data/doc/classes/Locale.src/M000073.html +31 -0
  137. data/doc/classes/Locale.src/M000074.html +30 -0
  138. data/doc/classes/Locale.src/M000075.html +30 -0
  139. data/doc/classes/Locale.src/M000076.html +31 -0
  140. data/doc/classes/Locale.src/M000077.html +40 -0
  141. data/doc/classes/Locale.src/M000078.html +31 -0
  142. data/doc/classes/Locale.src/M000079.html +46 -0
  143. data/doc/classes/Locale.src/M000080.html +32 -0
  144. data/doc/classes/Locale.src/M000081.html +31 -0
  145. data/doc/classes/Locale.src/M000082.html +30 -0
  146. data/doc/classes/Locale.src/M000083.html +30 -0
  147. data/doc/classes/Locale.src/M000084.html +30 -0
  148. data/doc/classes/Locale.src/M000085.html +32 -0
  149. data/doc/classes/Locale.src/M000086.html +31 -0
  150. data/doc/classes/Locale.src/M000087.html +31 -0
  151. data/doc/classes/Locale.src/M000088.html +30 -0
  152. data/doc/classes/Locale/Object.html +420 -0
  153. data/doc/classes/Locale/Object.src/M000104.html +53 -0
  154. data/doc/classes/Locale/Object.src/M000105.html +34 -0
  155. data/doc/classes/Locale/Object.src/M000106.html +32 -0
  156. data/doc/classes/Locale/Object.src/M000107.html +32 -0
  157. data/doc/classes/Locale/Object.src/M000108.html +33 -0
  158. data/doc/classes/Locale/Object.src/M000109.html +33 -0
  159. data/doc/classes/Locale/Object.src/M000110.html +30 -0
  160. data/doc/classes/Locale/SystemCGI.html +247 -0
  161. data/doc/classes/Locale/SystemCGI.src/M000094.html +48 -0
  162. data/doc/classes/Locale/SystemCGI.src/M000095.html +30 -0
  163. data/doc/classes/Locale/SystemCGI.src/M000096.html +31 -0
  164. data/doc/classes/Locale/SystemCGI.src/M000097.html +31 -0
  165. data/doc/classes/Locale/SystemCGI.src/M000098.html +31 -0
  166. data/doc/classes/Locale/SystemCGI.src/M000099.html +32 -0
  167. data/doc/classes/Locale/SystemCGI.src/M000100.html +31 -0
  168. data/doc/classes/Locale/SystemCGI.src/M000101.html +30 -0
  169. data/doc/classes/Locale/SystemPosix.html +133 -0
  170. data/doc/classes/Locale/SystemPosix.src/M000102.html +39 -0
  171. data/doc/classes/Locale/SystemPosix.src/M000103.html +34 -0
  172. data/doc/classes/Locale/SystemWin32.html +206 -0
  173. data/doc/classes/Locale/SystemWin32.src/M000089.html +31 -0
  174. data/doc/classes/Locale/SystemWin32.src/M000090.html +48 -0
  175. data/doc/classes/Locale/SystemWin32.src/M000091.html +32 -0
  176. data/doc/classes/Locale/SystemWin32.src/M000092.html +31 -0
  177. data/doc/classes/Locale/SystemWin32.src/M000093.html +30 -0
  178. data/doc/classes/MOFile.html +279 -0
  179. data/doc/classes/MOFile.src/M000001.html +31 -0
  180. data/doc/classes/MOFile.src/M000002.html +34 -0
  181. data/doc/classes/MOFile.src/M000003.html +37 -0
  182. data/doc/classes/MOFile.src/M000004.html +42 -0
  183. data/doc/classes/MOFile.src/M000005.html +93 -0
  184. data/doc/classes/MOFile.src/M000006.html +38 -0
  185. data/doc/classes/MOFile.src/M000007.html +34 -0
  186. data/doc/classes/MOFile.src/M000008.html +42 -0
  187. data/doc/classes/MOFile.src/M000009.html +93 -0
  188. data/doc/classes/MOFile.src/M000010.html +31 -0
  189. data/doc/classes/MOFile.src/M000011.html +30 -0
  190. data/doc/classes/MOFile.src/M000012.html +30 -0
  191. data/doc/classes/MOFile/InvalidFormat.html +92 -0
  192. data/doc/classes/String.html +150 -0
  193. data/doc/classes/String.src/M000013.html +44 -0
  194. data/doc/created.rid +1 -0
  195. data/doc/files/lib/gettext/cgi_rb.html +98 -0
  196. data/doc/files/lib/gettext/container_rb.html +96 -0
  197. data/doc/files/lib/gettext/erb_rb.html +97 -0
  198. data/doc/files/lib/gettext/iconv_rb.html +97 -0
  199. data/doc/files/lib/gettext/locale_cgi_rb.html +92 -0
  200. data/doc/files/lib/gettext/locale_object_rb.html +92 -0
  201. data/doc/files/lib/gettext/locale_posix_rb.html +92 -0
  202. data/doc/files/lib/gettext/locale_rb.html +99 -0
  203. data/doc/files/lib/gettext/locale_table_win32_rb.html +92 -0
  204. data/doc/files/lib/gettext/locale_win32_rb.html +96 -0
  205. data/doc/files/lib/gettext/mo_rb.html +96 -0
  206. data/doc/files/lib/gettext/parser/activerecord_rb.html +103 -0
  207. data/doc/files/lib/gettext/parser/erb_rb.html +97 -0
  208. data/doc/files/lib/gettext/parser/glade_rb.html +97 -0
  209. data/doc/files/lib/gettext/parser/ruby_rb.html +98 -0
  210. data/doc/files/lib/gettext/poparser_rb.html +96 -0
  211. data/doc/files/lib/gettext/rails_rb.html +99 -0
  212. data/doc/files/lib/gettext/rgettext_rb.html +98 -0
  213. data/doc/files/lib/gettext/rmsgfmt_rb.html +100 -0
  214. data/doc/files/lib/gettext/rmsgmerge_rb.html +100 -0
  215. data/doc/files/lib/gettext/string_rb.html +92 -0
  216. data/doc/files/lib/gettext/textdomain_rb.html +97 -0
  217. data/doc/files/lib/gettext/textdomainmanager_rb.html +97 -0
  218. data/doc/files/lib/gettext/utils_rb.html +98 -0
  219. data/doc/files/lib/gettext/version_rb.html +92 -0
  220. data/doc/files/lib/gettext_rb.html +101 -0
  221. data/doc/fr_class_index.html +45 -0
  222. data/doc/fr_file_index.html +41 -0
  223. data/doc/fr_method_index.html +135 -0
  224. data/doc/frame-style.css +33 -0
  225. data/doc/index.html +26 -0
  226. data/doc/rdoc-style.css +180 -0
  227. data/jamis.rb +590 -0
  228. data/lib/gettext.rb +38 -12
  229. data/lib/gettext/container.rb +6 -2
  230. data/lib/gettext/iconv.rb +2 -2
  231. data/lib/gettext/locale_cgi.rb +3 -2
  232. data/lib/gettext/locale_object.rb +8 -8
  233. data/lib/gettext/locale_posix.rb +2 -2
  234. data/lib/gettext/locale_table_win32.rb +3 -3
  235. data/lib/gettext/locale_win32.rb +2 -2
  236. data/lib/gettext/mo.rb +5 -2
  237. data/lib/gettext/parser/activerecord.rb +27 -17
  238. data/lib/gettext/parser/glade.rb +7 -11
  239. data/lib/gettext/parser/ruby.rb +2 -3
  240. data/lib/gettext/rails.rb +220 -85
  241. data/lib/gettext/rgettext.rb +2 -2
  242. data/lib/gettext/rmsgfmt.rb +3 -3
  243. data/lib/gettext/rmsgmerge.rb +2 -2
  244. data/lib/gettext/string.rb +2 -1
  245. data/lib/gettext/textdomain.rb +5 -2
  246. data/lib/gettext/textdomainmanager.rb +3 -3
  247. data/lib/gettext/version.rb +1 -1
  248. data/po/cs/rails.po +63 -22
  249. data/po/cs/rgettext.po +71 -37
  250. data/po/de/rails.po +54 -16
  251. data/po/de/rgettext.po +56 -22
  252. data/po/el/rails.po +54 -16
  253. data/po/el/rgettext.po +56 -22
  254. data/po/es/rails.po +57 -20
  255. data/po/es/rgettext.po +70 -30
  256. data/po/fr/rails.po +57 -19
  257. data/po/fr/rgettext.po +61 -25
  258. data/po/it/rails.po +54 -16
  259. data/po/it/rgettext.po +56 -22
  260. data/po/ja/rails.po +55 -18
  261. data/po/ja/rgettext.po +58 -24
  262. data/po/ko/rails.po +68 -33
  263. data/po/ko/rgettext.po +77 -37
  264. data/po/nl/rails.po +61 -22
  265. data/po/nl/rgettext.po +72 -36
  266. data/po/pt_BR/rails.po +54 -16
  267. data/po/pt_BR/rgettext.po +56 -22
  268. data/po/rails.pot +54 -16
  269. data/po/rgettext.pot +55 -21
  270. data/po/ru/rails.po +68 -26
  271. data/po/ru/rgettext.po +70 -30
  272. data/po/sv/rgettext.po +55 -21
  273. data/po/zh/rails.po +51 -16
  274. data/po/zh/rgettext.po +59 -23
  275. data/samples/rails/app/controllers/application.rb +7 -1
  276. data/samples/rails/app/models/article.rb +0 -6
  277. data/src/poparser.ry +1 -1
  278. data/test/gettext_test.rb +1 -1
  279. data/test/gettext_test_parser.rb +0 -1
  280. data/test/test_rubyparser.rb +0 -11
  281. metadata +233 -8
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.14 2006/06/07 15:56:04 mutoh Exp $
13
+ $Id: gettext.rb,v 1.15 2006/06/11 15:36:20 mutoh Exp $
14
14
  =end
15
15
 
16
16
  require 'rbconfig'
@@ -31,27 +31,25 @@ module GetText
31
31
 
32
32
  @@__textdomainmanagers = Hash.new
33
33
 
34
+ # call-seq:
35
+ # bindtextdomain(domainname, options = {})
36
+ #
34
37
  # Bind a textdomain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to your program.
35
38
  # Normally, the texdomain scope becomes a ruby-script-file.
36
39
  # So you need to call this function each ruby-script-files.
37
40
  # On the other hand, if you call this function under GetText::Container
38
- #(gettext/container, gettext/erb, gettext/rails), the textdomain scope becomes a Class/Module.
39
- #
41
+ # (gettext/container, gettext/erb, gettext/rails), the textdomain scope becomes a Class/Module.
40
42
  # * domainname: the textdomain name.
41
43
  # * options: options as an Hash.
42
44
  # * :path - the path to the mo-files. When the value is nil, it will search default paths such as
43
45
  # /usr/share/locale, /usr/local/share/locale)
44
46
  # * :locale - the locale string such as "ja_JP.UTF-8". Generally, you should use GetText.set_locale instead.
45
47
  # The value is searched order by:
46
- #
47
48
  # the value of this value > System default language.
48
- #
49
49
  # * :charset - output charset. This affect the current textdomain only. Generally, you should use GetText.set_output_charset instead.
50
50
  # The value is searched order by:
51
- #
52
51
  # the value of Locale.set_output_charset > ENV["OUTPUT_CHARSET"] > this value > System default charset.
53
52
  # * Returns: the GetText::TextDomain.
54
- #
55
53
  # Note: Don't use locale_, charset argument(not in options).
56
54
  # They are remained for backward compatibility.
57
55
  #
@@ -102,7 +100,7 @@ module GetText
102
100
  # * klass: a class/module to find. Default is the class of self.
103
101
  # * ignore_targets: Ignore tragets.
104
102
  # * Returns: a bound GetText::TextDomain or nil.
105
- def each_textdomain(klass = bound_target, ignore_targets = [])
103
+ def each_textdomain(klass = bound_target, ignore_targets = []) #:nodoc:
106
104
  (klass.ancestors + [GetText]).each do |target|
107
105
  unless ignore_targets.include? target
108
106
  ignore_targets << target
@@ -145,7 +143,7 @@ module GetText
145
143
  }
146
144
  ret ? ret : msgid
147
145
  end
148
-
146
+
149
147
  # call-seq:
150
148
  # ngettext(msgid, msgid_plural, n)
151
149
  # ngettext(msgids, n) # msgids = [msgid, msgid_plural]
@@ -313,7 +311,7 @@ module GetText
313
311
  end
314
312
 
315
313
  # Deprecated. Now this function do nothing. Use GetText.output_charset= instead.
316
- def set_charset(cs)
314
+ def set_charset(cs) #:nodoc:
317
315
  $stderr.puts "Deprecated. Now this function do nothing. Use GetText.output_charset= instead." if $DEBUG
318
316
  self
319
317
  end
@@ -325,12 +323,40 @@ module GetText
325
323
 
326
324
  # Add default locale path.
327
325
  # * path: a new locale path. (e.g.) "/usr/share/locale/%{locale}/LC_MESSAGES/%{name}.mo"
328
- # ('locale' => "ja_JP", 'name' => "textdomain")
326
+ # ('locale' => "ja_JP", 'name' => "textdomain")
329
327
  # * Returns: the new DEFAULT_LOCALE_PATHS
330
328
  def add_default_locale_path(path)
331
329
  TextDomain.add_default_locale_path(path)
332
330
  end
333
331
 
332
+ # Show the current textdomain information. This function is for debugging.
333
+ # * options: options as a Hash.
334
+ # * :with_messages - show informations with messages of the current mo file. Default is false.
335
+ # * :out - An output target. Default is STDOUT.
336
+ # * :with_paths - show the load paths for mo-files.
337
+ # * Returns: localized text by msgid. If there are not binded mo-file, it will return msgid.
338
+ def current_textdomain_info(options = {})
339
+ opts = {:with_messages => false, :with_paths => false, :out => STDOUT}.merge(options)
340
+ ret = nil
341
+ each_textdomain {|textdomain|
342
+ opts[:out].puts "TextDomain name: \"#{textdomain.name}\""
343
+ opts[:out].puts "TextDomain current locale: \"#{textdomain.current_locale}\""
344
+ opts[:out].puts "TextDomain current mo filename: \"#{textdomain.current_mo.filename}\""
345
+ if opts[:with_paths]
346
+ opts[:out].puts "TextDomain locale file paths:"
347
+ textdomain.locale_paths.each do |v|
348
+ opts[:out].puts " #{v}"
349
+ end
350
+ end
351
+ if opts[:with_messages]
352
+ opts[:out].puts "The messages in the mo file:"
353
+ textdomain.current_mo.each{|k, v|
354
+ opts[:out].puts " \"#{k}\": \"#{v}\""
355
+ }
356
+ end
357
+ }
358
+ end
359
+
334
360
  alias :setlocale :locale= #:nodoc:
335
361
  alias :_ :gettext #:nodoc:
336
362
  alias :n_ :ngettext #:nodoc:
@@ -339,5 +365,5 @@ module GetText
339
365
  module_function :bindtextdomain, :textdomain, :each_textdomain,
340
366
  :N_, :gettext, :_, :ngettext, :n_, :sgettext, :s_, :bound_target,
341
367
  :setlocale, :set_locale, :locale=, :set_locale_all, :locale, :charset=, :set_charset,
342
- :set_output_charset, :output_charset=, :output_charset
368
+ :set_output_charset, :output_charset=, :output_charset, :current_textdomain_info
343
369
  end
@@ -6,12 +6,16 @@
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.5 2006/06/04 14:43:37 mutoh Exp $
9
+ $Id: container.rb,v 1.6 2006/06/11 15:36:20 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'gettext'
13
13
 
14
- module GetText # :nodoc:
14
+ <<<<<<< container.rb
15
+ module GetText
16
+ =======
17
+ module GetText
18
+ >>>>>>> 1.6
15
19
  # Deprecated. You don't need this. Use GetText instead.
16
20
  module Container
17
21
  include GetText
data/lib/gettext/iconv.rb CHANGED
@@ -9,7 +9,7 @@
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.2 2006/02/22 16:42:41 mutoh Exp $
12
+ $Id: iconv.rb,v 1.3 2006/06/11 15:36:20 mutoh Exp $
13
13
  =end
14
14
 
15
15
  begin
@@ -17,7 +17,7 @@ begin
17
17
  rescue LoadError
18
18
  begin
19
19
  require 'glib2'
20
- # = Pseudo Iconv module
20
+ # Pseudo Iconv module
21
21
  #
22
22
  # Provides Iconv.iconv which uses Ruby/GLib(1) functions. This library also required from 'gettext'.
23
23
  # If you require 'gettext/iconv', Iconv.iconv try to call Ruby/GLib function
@@ -6,11 +6,11 @@
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: locale_cgi.rb,v 1.3 2006/03/07 17:26:57 mutoh Exp $
9
+ $Id: locale_cgi.rb,v 1.4 2006/06/11 15:36:20 mutoh Exp $
10
10
  =end
11
11
 
12
12
 
13
- module Locale # :nodoc:
13
+ module Locale
14
14
  # Locale::System module for Default OS (Unix)
15
15
  # This is low-level class. Application shouldn't use this directly.
16
16
  module SystemCGI
@@ -21,6 +21,7 @@ module Locale # :nodoc:
21
21
  # Gets the default locale using setlocale and nl_langinfo.
22
22
  # * Returns the system locale (Locale::Object).
23
23
  def system
24
+ return @@default_locale unless @@cgi
24
25
  cgi_ = cgi
25
26
  if ret = cgi_["lang"] and ret.size > 0
26
27
  elsif ret = cgi_.cookies["lang"][0]
@@ -6,11 +6,11 @@
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: locale_object.rb,v 1.7 2006/03/03 07:03:50 mutoh Exp $
9
+ $Id: locale_object.rb,v 1.8 2006/06/11 15:36:20 mutoh Exp $
10
10
  =end
11
11
 
12
12
 
13
- module Locale # :nodoc:
13
+ module Locale
14
14
  class Object
15
15
  attr_accessor :language, :country, :charset, :script, :variant, :modifier, :orig_str
16
16
 
@@ -19,16 +19,16 @@ module Locale # :nodoc:
19
19
  # * locale_name: locale name as String
20
20
  #
21
21
  # * Basic POSIX format: <language>_<COUNTRY>.<charset>@<modifier>
22
- # * Both of POSIX and C are converted to "en".
22
+ # * Both of POSIX and C are converted to "en".
23
23
  # * Basic RFC3066 format: <language>-<COUNTRY>
24
24
  # * Win32 format: <language>-<COUNTRY>-<Script>_<sort order>
25
25
  # * CLDR format: <language>_<Script>_<COUNTRY>_<variant>@<modifier>
26
26
  # * Some broken format: <language>_<country>_<script> # Don't use this.
27
27
  # * The max locale format is below:
28
- # * <language>-<COUNTRY>-<Script>_<sort order>.<charset>@<modifier>
29
- # * format: <language>_<Script>_<COUNTRY>_<variant>@<modifier>
30
- # * both of '-' and '_' are separators.
31
- # * each elements are omittable.
28
+ # * <language>-<COUNTRY>-<Script>_<sort order>.<charset>@<modifier>
29
+ # * format: <language>_<Script>_<COUNTRY>_<variant>@<modifier>
30
+ # * both of '-' and '_' are separators.
31
+ # * each elements are omittable.
32
32
  #
33
33
  # (e.g.) uz-UZ-Latn, ja_JP.eucJP, wa_BE.iso885915@euro
34
34
  # * Returns: [language, country, charset, script, modifier]
@@ -39,7 +39,7 @@ module Locale # :nodoc:
39
39
  # * variant: variant value in CLDR or sort order in Win32.
40
40
  # * modifier: (no standard)
41
41
  #
42
- #
42
+ # (e.g.)
43
43
  # "ja_JP.eucJP" => ["ja", "JP", "eucJP", nil, nil]
44
44
  # "ja-jp.utf-8" => ["ja", "JP", "utf-8", nil, nil]
45
45
  # "ja-jp" => ["ja", "JP", nil, nil, nil]
@@ -6,11 +6,11 @@
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: locale_posix.rb,v 1.3 2006/06/07 15:56:04 mutoh Exp $
9
+ $Id: locale_posix.rb,v 1.4 2006/06/11 15:36:20 mutoh Exp $
10
10
  =end
11
11
 
12
12
 
13
- module Locale # :nodoc:
13
+ module Locale
14
14
  # Locale::SystemPosix module for Posix OS (Unix)
15
15
  # This is low-level class. Application shouldn't use this directly.
16
16
  module SystemPosix
@@ -6,11 +6,11 @@
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: locale_table_win32.rb,v 1.4 2006/02/20 16:07:36 mutoh Exp $
9
+ $Id: locale_table_win32.rb,v 1.5 2006/06/11 15:36:20 mutoh Exp $
10
10
  =end
11
11
 
12
- module Locale #:nodoc:
13
- module SystemWin32 #:nodoc:
12
+ module Locale
13
+ module SystemWin32
14
14
  #LangID, locale name, code page
15
15
  LocaleTable = [
16
16
  [0x0000, "en", "CP1252"],
@@ -6,12 +6,12 @@
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: locale_win32.rb,v 1.13 2006/06/04 14:43:37 mutoh Exp $
9
+ $Id: locale_win32.rb,v 1.14 2006/06/11 15:36:20 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'gettext/locale_table_win32'
13
13
 
14
- module Locale #:nodoc:
14
+ module Locale
15
15
  # Locale::SystemWin32 module for win32.
16
16
  module SystemWin32
17
17
  extend Locale::System
data/lib/gettext/mo.rb CHANGED
@@ -12,14 +12,16 @@
12
12
  of Ruby. License of Ruby is included with Ruby distribution in
13
13
  the file "README".
14
14
 
15
- $Id: mo.rb,v 1.6 2006/05/19 15:42:14 mutoh Exp $
15
+ $Id: mo.rb,v 1.7 2006/06/11 15:36:20 mutoh Exp $
16
16
  =end
17
17
 
18
18
  require 'gettext/iconv'
19
19
 
20
- class MOFile < Hash #:nodoc:
20
+ class MOFile < Hash
21
21
  class InvalidFormat < RuntimeError; end;
22
22
 
23
+ attr_reader :filename
24
+
23
25
  Header = Struct.new(:magic,
24
26
  :revision,
25
27
  :nstrings,
@@ -249,6 +251,7 @@ class MOFile < Hash #:nodoc:
249
251
  end
250
252
 
251
253
  def load_from_file(filename)
254
+ @filename = filename
252
255
  File.open(filename, 'rb'){|f| load_from_stream(f)}
253
256
  end
254
257
 
@@ -7,7 +7,7 @@
7
7
  You may redistribute it and/or modify it under the same
8
8
  license terms as Ruby.
9
9
 
10
- $Id: activerecord.rb,v 1.9 2006/05/13 17:20:52 mutoh Exp $
10
+ $Id: activerecord.rb,v 1.11 2006/07/13 18:22:09 mutoh Exp $
11
11
  =end
12
12
 
13
13
  require 'gettext'
@@ -25,6 +25,7 @@ module GetText
25
25
  :db_yml => "config/database.yml",
26
26
  :db_mode => "development",
27
27
  :activerecord_classes => ["ActiveRecord::Base"],
28
+ :untranslate_columns => ["id"],
28
29
  :use_classname => true,
29
30
  }
30
31
 
@@ -42,10 +43,11 @@ module GetText
42
43
  # Sets some preferences to parse ActiveRecord files.
43
44
  #
44
45
  # * config: a Hash of the config. It can takes some values below:
45
- # * :use_classname: If true, the msgids of ActiveRecord become "ClassName|FieldName" (e.g. "Article|Title"). Otherwise the ClassName is not used (e.g. "Title"). Default is true.
46
- # * :db_yml: the path of database.yml. Default is "config/database.yml".
47
- # * :db_mode: the mode of the database. Default is "development"
48
- # * :activerecord_classes: an Array of the superclass of the models. The classes should be String value. Default is ["ActiveRecord::Base"]
46
+ # * :use_classname - If true, the msgids of ActiveRecord become "ClassName|FieldName" (e.g. "Article|Title"). Otherwise the ClassName is not used (e.g. "Title"). Default is true.
47
+ # * :db_yml - the path of database.yml. Default is "config/database.yml".
48
+ # * :db_mode - the mode of the database. Default is "development"
49
+ # * :activerecord_classes - an Array of the superclass of the models. The classes should be String value. Default is ["ActiveRecord::Base"]
50
+ # * :untranslate_columns - an Array of the column names which is ignored as the msgid.
49
51
  #
50
52
  # "ClassName|FieldName" uses GetText.sgettext. So you don't need to translate the left-side of "|".
51
53
  # See <Documents for Translators for more details(http://www.yotabanana.com/hiki/ruby-gettext-translate.html)>.
@@ -58,6 +60,10 @@ module GetText
58
60
  @ar_re = /class.*(#{@config[:activerecord_classes].join("|")})/
59
61
  end
60
62
 
63
+ def untranslate_column?(klass, columnname)
64
+ klass.untranslate?(columnname) || @config[:untranslate_columns].include?(columnname)
65
+ end
66
+
61
67
  def parse(file, targets = []) # :nodoc:
62
68
  old_constants = constants
63
69
  begin
@@ -70,20 +76,24 @@ module GetText
70
76
  loaded_constants.each do |classname|
71
77
  klass = eval(classname)
72
78
  if klass < ActiveRecord::Base
73
- add_target(targets, file, ::Inflector.singularize(klass.table_name.gsub(/_/, " ")))
74
- tablename = klass.class_name
75
- begin
76
- klass.columns.each do |column|
77
- if @config[:use_classname]
78
- msgid = tablename + "|" + klass.human_attribute_name(column.name)
79
- else
80
- msgid = klass.human_attribute_name(column.name)
79
+ unless klass.untranslate_all?
80
+ add_target(targets, file, ::Inflector.singularize(klass.table_name.gsub(/_/, " ")))
81
+ tablename = klass.class_name
82
+ begin
83
+ klass.columns.each do |column|
84
+ unless untranslate_column?(klass, column.name)
85
+ if @config[:use_classname]
86
+ msgid = tablename + "|" + klass.human_attribute_name(column.name)
87
+ else
88
+ msgid = klass.human_attribute_name(column.name)
89
+ end
90
+ add_target(targets, file, msgid)
91
+ end
81
92
  end
82
- add_target(targets, file, msgid)
93
+ rescue
94
+ $stderr.puts _("No database is available.")
95
+ $stderr.puts $!
83
96
  end
84
- rescue
85
- $stderr.puts _("No database is available.")
86
- $stderr.puts $!
87
97
  end
88
98
  end
89
99
  end
@@ -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: glade.rb,v 1.4 2006/02/22 16:42:41 mutoh Exp $
9
+ $Id: glade.rb,v 1.5 2006/06/11 15:36:20 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'cgi'
@@ -67,17 +67,13 @@ module GetText
67
67
 
68
68
  def target?(file) # :nodoc:
69
69
  data = IO.readlines(file)
70
- if XML_RE =~ data[0]
71
- if GLADE_RE =~ data[1]
72
- return true
73
- else
74
- if File.extname(file) == '.glade'
75
- raise _("%s is not glade-2.0 format.") % [file]
76
- end
77
- return false
78
- end
70
+ if XML_RE =~ data[0] and GLADE_RE =~ data[1]
71
+ true
79
72
  else
80
- return false
73
+ if File.extname(file) == '.glade'
74
+ raise _("`%{file}' is not glade-2.0 format.") % {:file => file}
75
+ end
76
+ false
81
77
  end
82
78
  end
83
79
 
@@ -9,7 +9,7 @@
9
9
  You may redistribute it and/or modify it under the same
10
10
  license terms as Ruby.
11
11
 
12
- $Id: ruby.rb,v 1.6 2006/02/22 16:42:41 mutoh Exp $
12
+ $Id: ruby.rb,v 1.7 2006/06/11 15:36:20 mutoh Exp $
13
13
  =end
14
14
 
15
15
  require 'irb/ruby-lex.rb'
@@ -171,7 +171,7 @@ module GetText
171
171
  end
172
172
  else
173
173
  if msgid
174
- key_existed = targets.assoc(msgid)
174
+ key_existed = targets.assoc(msgid.gsub(/\n/, '\n'))
175
175
  if key_existed
176
176
  targets[targets.index(key_existed)] = key_existed <<
177
177
  file_name + ":" + line_no
@@ -184,7 +184,6 @@ module GetText
184
184
  end
185
185
  targets
186
186
  end
187
-
188
187
  targets
189
188
  end
190
189
 
data/lib/gettext/rails.rb CHANGED
@@ -6,15 +6,14 @@
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.36 2006/06/04 14:43:37 mutoh Exp $
9
+ $Id: rails.rb,v 1.43 2006/07/16 15:19:17 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'gettext/cgi'
13
13
  require 'active_record'
14
14
  require 'active_support'
15
15
 
16
- module GetText #:nodoc:
17
- # = GetText for Ruby on Rails
16
+ module GetText
18
17
  # GetText::Rails supports Ruby on Rails.
19
18
  # You add only 2 lines in your controller, all of the controller/view/models are
20
19
  # targeted the textdomain.
@@ -32,6 +31,9 @@ module GetText #:nodoc:
32
31
  end
33
32
 
34
33
  module_function
34
+ # call-seq:
35
+ # bindtextdomain(domainname, options = {})
36
+ #
35
37
  # Bind a textdomain(#{path}/#{locale}/LC_MESSAGES/#{domainname}.mo) to your program.
36
38
  # Notes the textdomain scope becomes all of the controllers/views/models in your app.
37
39
  # This is different from normal GetText.bindtextomain.
@@ -43,16 +45,16 @@ module GetText #:nodoc:
43
45
  #
44
46
  # * domainname: the textdomain name.
45
47
  # * 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.
48
+ # * :locale - the locale value such as "ja-JP". When the value is nil,
49
+ # locale is searched the order by this value > "lang" value of QUERY_STRING >
50
+ # params["lang"] > "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value
51
+ # > Default locale(en).
52
+ # * :path - the path to the mo-files. Default is "RAIL_ROOT/locale".
53
+ # * :charset - the charset. Generally UTF-8 is recommanded.
54
+ # And the charset is set order by "the argument of bindtextdomain"
55
+ # > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
56
+ # * :with_model - false if you want to ignore ActiveRecord support.
57
+ # * :with_helper - false if you want to ignore ApplicationHelper support.
56
58
  #
57
59
  # Note: Don't use locale, charset, with_model argument(not in options).
58
60
  # They are remained for backward compatibility.
@@ -126,8 +128,8 @@ module ActionController #:nodoc:
126
128
  # Bind a 'textdomain' to all of the controllers/views/models. Call this instead of GetText.bindtextdomain.
127
129
  # * textdomain: the textdomain
128
130
  # * options: options as a Hash.
129
- # * :charset - the output charset. Default is "UTF-8"
130
- # * :content_type - the content type. Default is "text/html"
131
+ # * :charset - the output charset. Default is "UTF-8"
132
+ # * :content_type - the content type. Default is "text/html"
131
133
  #
132
134
  # locale is searched the order by @params["lang"] > "lang" value of QUERY_STRING >
133
135
  # "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
@@ -156,6 +158,12 @@ module ActionController #:nodoc:
156
158
  @@gettext_domainname = domainname
157
159
  @@gettext_content_type = opt[:content_type]
158
160
  end
161
+
162
+ # Gets the textdomain name of this controller.
163
+ def self.textdomainname
164
+ @@gettext_domainname
165
+ end
166
+
159
167
  end
160
168
 
161
169
  class TestRequest < AbstractRequest #:nodoc:
@@ -168,6 +176,11 @@ module ActionController #:nodoc:
168
176
  end
169
177
 
170
178
  module ActiveRecord #:nodoc:
179
+ class Migration
180
+ extend GetText
181
+ include GetText
182
+ end
183
+
171
184
  module ConnectionAdapters #:nodoc:
172
185
  # An abstract definition of a column in a table.
173
186
  class Column
@@ -178,46 +191,79 @@ module ActiveRecord #:nodoc:
178
191
  end
179
192
  end
180
193
  end
194
+
195
+ module Validations # :nodoc:
196
+ def self.append_features(base) # :nodoc:
197
+ super
198
+ base.extend ClassMethods
199
+ base.class_eval{
200
+ def gettext(str) #:nodoc:
201
+ _(str)
202
+ end
203
+ def self.human_attribute_name(attribute_key_name) #:nodoc:
204
+ s_("#{self}|#{attribute_key_name.humanize}")
205
+ end
206
+
207
+ def self.human_attribute_table_name_for_error(table_name) #:nodoc:
208
+ _(table_name.gsub(/_/, " "))
209
+ end
210
+ }
211
+ end
212
+
213
+ module ClassMethods #:nodoc:
214
+ @@custom_error_messages_d = {}
215
+
216
+ # Very ugly but...
217
+ def validates_length_of(*attrs) #:nodoc:
218
+ if attrs.last.is_a?(Hash)
219
+ msg = attrs.last[:message]
220
+ if msg
221
+ @@custom_error_messages_d[msg] = /#{Regexp.escape(msg).sub(/%d/, '(\d+)')}/
222
+ end
223
+ end
224
+ validates_size_of(*attrs)
225
+ end
226
+
227
+ def custom_error_messages_d #:nodoc:
228
+ @@custom_error_messages_d
229
+ end
230
+ end
231
+ def custom_error_messages_d #:nodoc:
232
+ self.class.custom_error_messages_d
233
+ end
234
+ end
181
235
 
182
236
  class Base
183
- def self.human_attribute_name(attribute_key_name) #:nodoc:
184
- s_("#{self}|#{attribute_key_name.humanize}")
237
+ include GetText::Rails
238
+ include Validations
239
+
240
+ @@gettext_untranslate = false
241
+ @@gettext_untranslate_columns = []
242
+
243
+ # Untranslate all of the tablename/fieldnames in this model class.
244
+ def self.untranslate_all
245
+ @@gettext_untranslate = true
185
246
  end
186
247
 
187
- def self.human_attribute_table_name_for_error(table_name) #:nodoc:
188
- _(table_name.gsub(/_/, " "))
248
+ # Returns true if "untranslate_all" is called. Otherwise false.
249
+ def self.untranslate_all?
250
+ @@gettext_untranslate
189
251
  end
190
252
 
191
- @@error_message_title = nil
192
- @@error_message_explanation = nil
193
-
194
- # call-seq:
195
- # set_error_message_title(msg)
196
- #
197
- # Sets a your own title of error message dialog.
198
- # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
199
- # * Returns: [single_msg, plural_msg]
200
- def self.set_error_message_title(msg, plural_msg = nil)
201
- if msg.kind_of? Array
202
- single_msg = msg[0]
203
- plural_msg = msg[1]
204
- else
205
- single_msg = msg
206
- end
207
- @@error_message_title = [single_msg, plural_msg]
253
+ # Sets the untranslate columns.
254
+ # (e.g.) untranslate :foo, :bar, :baz
255
+ def self.untranslate(*w)
256
+ @@gettext_untranslate_columns += w.collect{|v| v.to_s}
208
257
  end
209
258
 
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)
259
+ # Returns true if the column is set "untranslate".
260
+ # (e.g.) untranslate? :foo
261
+ def self.untranslate?(columnname)
262
+ @@gettext_untranslate_columns.include?(columnname)
218
263
  end
219
- def custom_error_messages_d #:nodoc:
220
- @@custom_error_messages_d
264
+
265
+ def self.untranslate_data #:nodoc:
266
+ [@@gettext_untranslate, @@gettext_untranslate_columns]
221
267
  end
222
268
 
223
269
  def self.columns
@@ -230,46 +276,40 @@ module ActiveRecord #:nodoc:
230
276
  end
231
277
  @columns
232
278
  end
279
+
280
+ # call-seq:
281
+ # set_error_message_title(msg)
282
+ #
283
+ # ((*Deprecated*))
284
+ # Use ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title
285
+ # instead.
286
+ #
287
+ # Sets a your own title of error message dialog.
288
+ # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
289
+ # * Returns: [single_msg, plural_msg]
290
+ def self.set_error_message_title(msg, plural_msg = nil)
291
+ ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title(msg, plural_msg)
292
+ end
233
293
 
234
294
  # call-seq:
235
295
  # set_error_message_explanation(msg)
236
296
  #
297
+ # ((*Deprecated*))
298
+ # Use ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_explanation
299
+ # instead.
300
+ #
237
301
  # Sets a your own explanation of the error message dialog.
238
302
  # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
239
303
  # * Returns: [single_msg, plural_msg]
240
304
  def self.set_error_message_explanation(msg, plural_msg = nil)
241
- if msg.kind_of? Array
242
- single_msg = msg[0]
243
- plural_msg = msg[1]
244
- else
245
- single_msg = msg
246
- end
247
- @@error_message_explanation = [single_msg, plural_msg]
248
- end
249
-
250
- def error_message_title #:nodoc:
251
- if @@error_message_title
252
- [_(@@error_message_title[0]), _(@@error_message_title[1])]
253
- else
254
- nil
255
- end
256
- end
257
- def error_message_explanation #:nodoc:
258
- if @@error_message_explanation
259
- [_(@@error_message_explanation[0]), _(@@error_message_explanation[1])]
260
- else
261
- nil
262
- end
263
- end
264
-
265
- def gettext(str) #:nodoc:
266
- _(str)
305
+ ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_explanation(msg, plural_msg)
267
306
  end
268
307
  end
269
308
 
309
+ # activerecord-1.14.3/lib/active_record/validations.rb
270
310
  class Errors #:nodoc:
271
311
  include GetText
272
-
312
+
273
313
  RE_FIELD_NAME = /%\{fn\}/ #:nodoc:
274
314
 
275
315
  # You need to define this here, because this values will be updated by application.
@@ -294,8 +334,8 @@ module ActiveRecord #:nodoc:
294
334
  }
295
335
  cattr_accessor :default_error_messages_d
296
336
 
297
- def full_messages #:nodoc:
298
- full_messages = []
337
+ def localize_error_messages # :nodoc:
338
+ errors = {}
299
339
  @errors.each_key do |attr|
300
340
  @errors[attr].each do |msg|
301
341
  next if msg.nil?
@@ -305,8 +345,8 @@ module ActiveRecord #:nodoc:
305
345
  if regexp =~ msg
306
346
  custom_msg = @base.gettext(key)
307
347
  custom_msg = _(msg) if custom_msg == msg
308
- custom_msg = _(custom_msg) % $1.to_i
309
- break
348
+ custom_msg = _(custom_msg) % $1.to_i
349
+ break
310
350
  end
311
351
  end
312
352
  unless custom_msg
@@ -314,14 +354,36 @@ module ActiveRecord #:nodoc:
314
354
  custom_msg = _(msg) if custom_msg == msg
315
355
  end
316
356
  if attr == "base"
317
- full_messages << custom_msg
357
+ full_message = custom_msg
318
358
  elsif RE_FIELD_NAME =~ custom_msg
319
- full_messages << custom_msg % {:fn => @base.class.human_attribute_name(attr)}
359
+ full_message = custom_msg % {:fn => @base.class.human_attribute_name(attr)}
320
360
  else
321
- full_messages << @base.class.human_attribute_name(attr) + " " + custom_msg
361
+ full_message = @base.class.human_attribute_name(attr) + " " + custom_msg
322
362
  end
363
+ errors[attr] = full_message
323
364
  end
324
365
  end
366
+ errors
367
+ end
368
+
369
+ def on(attribute) #:nodoc:
370
+ errors = localize_error_messages
371
+ if errors[attribute.to_s].nil?
372
+ nil
373
+ elsif errors[attribute.to_s].length == 1
374
+ errors[attribute.to_s].first
375
+ else
376
+ errors[attribute.to_s]
377
+ end
378
+ end
379
+
380
+ def full_messages #:nodoc:
381
+ full_messages = []
382
+ errors = localize_error_messages
383
+ errors.each do |attr, msg|
384
+ next if msg.nil?
385
+ full_messages << msg
386
+ end
325
387
  full_messages
326
388
  end
327
389
  end
@@ -349,7 +411,8 @@ module ActionView #:nodoc:
349
411
  module L10n
350
412
  # Separate namespace for textdomain
351
413
  include GetText
352
- extend GetText
414
+
415
+ bindtextdomain("rails")
353
416
 
354
417
  @error_message_title = Nn_("%{num} error prohibited this %{record} from being saved",
355
418
  "%{num} errors prohibited this %{record} from being saved")
@@ -357,9 +420,56 @@ module ActionView #:nodoc:
357
420
  "There were problems with the following fields:")
358
421
 
359
422
  module_function
423
+ # call-seq:
424
+ # set_error_message_title(msgs)
425
+ #
426
+ # Sets a your own title of error message dialog.
427
+ # * msgs: [single_msg, plural_msg]. Usually you need to call this with Nn_().
428
+ # * Returns: [single_msg, plural_msg]
429
+ def set_error_message_title(msg, plural_msg = nil)
430
+ if msg.kind_of? Array
431
+ single_msg = msg[0]
432
+ plural_msg = msg[1]
433
+ else
434
+ single_msg = msg
435
+ end
436
+ @error_message_title = [single_msg, plural_msg]
437
+ end
438
+
439
+ # call-seq:
440
+ # set_error_message_explanation(msg)
441
+ #
442
+ # Sets a your own explanation of the error message dialog.
443
+ # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
444
+ # * Returns: [single_msg, plural_msg]
445
+ def set_error_message_explanation(msg, plural_msg = nil)
446
+ if msg.kind_of? Array
447
+ single_msg = msg[0]
448
+ plural_msg = msg[1]
449
+ else
450
+ single_msg = msg
451
+ end
452
+ @error_message_explanation = [single_msg, plural_msg]
453
+ end
454
+
455
+ def error_message_title #:nodoc:
456
+ if @error_message_title
457
+ [_(@error_message_title[0]), _(@error_message_title[1])]
458
+ else
459
+ nil
460
+ end
461
+ end
462
+ def error_message_explanation #:nodoc:
463
+ if @error_message_explanation
464
+ [_(@error_message_explanation[0]), _(@error_message_explanation[1])]
465
+ else
466
+ nil
467
+ end
468
+ end
469
+
360
470
  def render_error_message(object, klass, record, count, options)
361
- message_title = object.error_message_title || @error_message_title
362
- message_explanation = object.error_message_explanation || @error_message_explanation
471
+ message_title = @error_message_title
472
+ message_explanation = @error_message_explanation
363
473
 
364
474
  klass.content_tag("div",
365
475
  klass.content_tag(
@@ -373,8 +483,6 @@ module ActionView #:nodoc:
373
483
  end
374
484
 
375
485
  def error_messages_for(object, object_name, klass, options = {})
376
- textdomain("rails")
377
-
378
486
  options = options.symbolize_keys
379
487
 
380
488
  if object && ! object.errors.empty?
@@ -389,6 +497,33 @@ module ActionView #:nodoc:
389
497
  L10n.error_messages_for(object, object_name, self, options)
390
498
  end
391
499
  end
500
+
501
+ module DateHelper #:nodoc: all
502
+ include GetText
503
+ alias distance_of_time_in_words_without_locale distance_of_time_in_words #:nodoc:
504
+
505
+ bindtextdomain("rails")
506
+
507
+ # This is FAKE constant. The messages are found by rgettext as the msgid.
508
+ MESSAGESS = [N_('less than 5 seconds'), N_('less than 10 seconds'), N_('less than 20 seconds'),
509
+ N_('half a minute'), N_('less than a minute')]
510
+ MINUTES = [/^(\d+) minutes?$/, Nn_('1 minute', '%{num} minutes')]
511
+ HOURS = [/^about (\d+) hours?$/, Nn_('about 1 hour', 'about %{num} hours')]
512
+ DAYS = [/^(\d+) days?$/, Nn_('1 day', '%{num} days')]
513
+
514
+ def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
515
+ msg = distance_of_time_in_words_without_locale(from_time, to_time, include_seconds)
516
+ match = false
517
+ [MINUTES, HOURS, DAYS].each do |regexp, nn|
518
+ if regexp =~ msg
519
+ match = true
520
+ msg = n_(nn, $1.to_i) % {:num => $1}
521
+ break
522
+ end
523
+ end
524
+ match ? msg : _(msg)
525
+ end
526
+ end
392
527
  end
393
528
  end
394
529