gettext 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. data/ChangeLog +194 -0
  2. data/NEWS +49 -0
  3. data/README +28 -9
  4. data/Rakefile +54 -41
  5. data/bin/rgettext +2 -0
  6. data/bin/rmsgfmt +2 -0
  7. data/bin/rmsgmerge +24 -0
  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/es/LC_MESSAGES/rails.mo +0 -0
  13. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  14. data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
  15. data/data/locale/fr/LC_MESSAGES/rgettext.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/sv/LC_MESSAGES/rgettext.mo +0 -0
  26. data/lib/gettext.rb +17 -4
  27. data/lib/gettext/cgi.rb +34 -19
  28. data/lib/gettext/locale.rb +3 -13
  29. data/lib/gettext/locale_default.rb +2 -2
  30. data/lib/gettext/locale_win32.rb +27 -7
  31. data/lib/gettext/mo.rb +6 -1
  32. data/lib/gettext/parser/activerecord.rb +115 -0
  33. data/lib/gettext/parser/glade.rb +3 -1
  34. data/lib/gettext/parser/ruby.rb +56 -57
  35. data/lib/gettext/poparser.rb +297 -0
  36. data/lib/gettext/rails.rb +161 -3
  37. data/lib/gettext/rgettext.rb +19 -9
  38. data/lib/gettext/rmsgfmt.rb +7 -275
  39. data/lib/gettext/rmsgmerge.rb +381 -0
  40. data/lib/gettext/string.rb +26 -0
  41. data/lib/gettext/textdomain.rb +21 -18
  42. data/lib/gettext/utils.rb +55 -0
  43. data/lib/gettext/version.rb +1 -1
  44. data/po/cs/rails.po +83 -0
  45. data/po/cs/rgettext.po +104 -0
  46. data/po/de/rails.po +79 -0
  47. data/po/de/rgettext.po +72 -21
  48. data/po/es/rails.po +80 -0
  49. data/po/es/rgettext.po +75 -19
  50. data/po/fr/rails.po +81 -0
  51. data/po/fr/rgettext.po +75 -19
  52. data/po/it/rgettext.po +68 -17
  53. data/po/ja/rails.po +78 -0
  54. data/po/ja/rgettext.po +71 -20
  55. data/po/ko/rails.po +77 -0
  56. data/po/ko/rgettext.po +74 -22
  57. data/po/nl/rails.po +80 -0
  58. data/po/nl/rgettext.po +102 -0
  59. data/po/pt_BR/rails.po +79 -0
  60. data/po/pt_BR/rgettext.po +77 -24
  61. data/po/rails.pot +80 -0
  62. data/po/rgettext.pot +63 -13
  63. data/po/sv/rgettext.po +63 -15
  64. data/samples/cgi/cookie.cgi +5 -0
  65. data/samples/cgi/helloerb1.cgi +4 -0
  66. data/samples/cgi/helloerb2.cgi +5 -0
  67. data/samples/cgi/index.cgi +5 -0
  68. data/samples/cgi/locale/cs/LC_MESSAGES/helloerb1.mo +0 -0
  69. data/samples/cgi/locale/cs/LC_MESSAGES/helloerb2.mo +0 -0
  70. data/samples/cgi/locale/cs/LC_MESSAGES/hellolib.mo +0 -0
  71. data/samples/cgi/locale/cs/LC_MESSAGES/main.mo +0 -0
  72. data/samples/cgi/locale/fr/LC_MESSAGES/main.mo +0 -0
  73. data/samples/cgi/locale/ko/LC_MESSAGES/helloerb1.mo +0 -0
  74. data/samples/cgi/locale/ko/LC_MESSAGES/helloerb2.mo +0 -0
  75. data/samples/cgi/locale/ko/LC_MESSAGES/hellolib.mo +0 -0
  76. data/samples/cgi/locale/ko/LC_MESSAGES/main.mo +0 -0
  77. data/samples/cgi/locale/nl/LC_MESSAGES/helloerb1.mo +0 -0
  78. data/samples/cgi/locale/nl/LC_MESSAGES/helloerb2.mo +0 -0
  79. data/samples/cgi/locale/nl/LC_MESSAGES/hellolib.mo +0 -0
  80. data/samples/cgi/locale/nl/LC_MESSAGES/main.mo +0 -0
  81. data/samples/cgi/locale/pt_BR/LC_MESSAGES/helloerb1.mo +0 -0
  82. data/samples/cgi/locale/pt_BR/LC_MESSAGES/helloerb2.mo +0 -0
  83. data/samples/cgi/locale/pt_BR/LC_MESSAGES/hellolib.mo +0 -0
  84. data/samples/cgi/locale/pt_BR/LC_MESSAGES/main.mo +0 -0
  85. data/samples/cgi/po/cs/helloerb1.po +66 -0
  86. data/samples/cgi/po/cs/helloerb2.po +52 -0
  87. data/samples/cgi/po/cs/hellolib.po +25 -0
  88. data/samples/cgi/po/cs/main.po +78 -0
  89. data/samples/cgi/po/fr/main.po +8 -8
  90. data/samples/cgi/po/ko/helloerb1.po +2 -3
  91. data/samples/cgi/po/ko/helloerb2.po +1 -2
  92. data/samples/cgi/po/ko/hellolib.po +1 -2
  93. data/samples/cgi/po/ko/main.po +2 -3
  94. data/samples/cgi/po/nl/helloerb1.po +60 -0
  95. data/samples/cgi/po/nl/helloerb2.po +52 -0
  96. data/samples/cgi/po/nl/hellolib.po +24 -0
  97. data/samples/cgi/po/nl/main.po +76 -0
  98. data/samples/cgi/po/pt_BR/helloerb1.po +59 -0
  99. data/samples/cgi/po/pt_BR/helloerb2.po +51 -0
  100. data/samples/cgi/po/pt_BR/hellolib.po +22 -0
  101. data/samples/cgi/po/pt_BR/main.po +75 -0
  102. data/samples/locale/cs/LC_MESSAGES/hello.mo +0 -0
  103. data/samples/locale/cs/LC_MESSAGES/hello2.mo +0 -0
  104. data/samples/locale/cs/LC_MESSAGES/hello_noop.mo +0 -0
  105. data/samples/locale/cs/LC_MESSAGES/hello_plural.mo +0 -0
  106. data/samples/locale/cs/LC_MESSAGES/helloglade2.mo +0 -0
  107. data/samples/locale/cs/LC_MESSAGES/hellogtk.mo +0 -0
  108. data/samples/locale/cs/LC_MESSAGES/hellotk.mo +0 -0
  109. data/samples/locale/fr/LC_MESSAGES/helloglade2.mo +0 -0
  110. data/samples/locale/ko/LC_MESSAGES/hello.mo +0 -0
  111. data/samples/locale/ko/LC_MESSAGES/hello2.mo +0 -0
  112. data/samples/locale/ko/LC_MESSAGES/hello_noop.mo +0 -0
  113. data/samples/locale/ko/LC_MESSAGES/hello_plural.mo +0 -0
  114. data/samples/locale/ko/LC_MESSAGES/helloglade2.mo +0 -0
  115. data/samples/locale/ko/LC_MESSAGES/hellogtk.mo +0 -0
  116. data/samples/locale/ko/LC_MESSAGES/hellotk.mo +0 -0
  117. data/samples/locale/nl/LC_MESSAGES/hello.mo +0 -0
  118. data/samples/locale/nl/LC_MESSAGES/hello2.mo +0 -0
  119. data/samples/locale/nl/LC_MESSAGES/hello_noop.mo +0 -0
  120. data/samples/locale/nl/LC_MESSAGES/hello_plural.mo +0 -0
  121. data/samples/locale/nl/LC_MESSAGES/helloglade2.mo +0 -0
  122. data/samples/locale/nl/LC_MESSAGES/hellogtk.mo +0 -0
  123. data/samples/locale/nl/LC_MESSAGES/hellotk.mo +0 -0
  124. data/samples/locale/pt_BR/LC_MESSAGES/hello.mo +0 -0
  125. data/samples/locale/pt_BR/LC_MESSAGES/hello2.mo +0 -0
  126. data/samples/locale/pt_BR/LC_MESSAGES/hello_noop.mo +0 -0
  127. data/samples/locale/pt_BR/LC_MESSAGES/hello_plural.mo +0 -0
  128. data/samples/locale/pt_BR/LC_MESSAGES/helloglade2.mo +0 -0
  129. data/samples/locale/pt_BR/LC_MESSAGES/hellogtk.mo +0 -0
  130. data/samples/locale/pt_BR/LC_MESSAGES/hellotk.mo +0 -0
  131. data/samples/po/cs/hello.po +23 -0
  132. data/samples/po/cs/hello2.po +31 -0
  133. data/samples/po/cs/hello_noop.po +27 -0
  134. data/samples/po/cs/hello_plural.po +26 -0
  135. data/samples/po/cs/helloglade2.po +37 -0
  136. data/samples/po/cs/hellogtk.po +23 -0
  137. data/samples/po/cs/hellotk.po +23 -0
  138. data/samples/po/fr/helloglade2.po +2 -2
  139. data/samples/po/hello.pot +1 -0
  140. data/samples/po/hello2.pot +1 -0
  141. data/samples/po/hello_noop.pot +2 -1
  142. data/samples/po/hello_plural.pot +6 -2
  143. data/samples/po/helloglade2.pot +8 -3
  144. data/samples/po/hellotk.pot +4 -0
  145. data/samples/po/ko/hello.po +1 -2
  146. data/samples/po/ko/hello2.po +1 -2
  147. data/samples/po/ko/hello_noop.po +1 -2
  148. data/samples/po/ko/hello_plural.po +1 -2
  149. data/samples/po/ko/helloglade2.po +2 -2
  150. data/samples/po/ko/hellogtk.po +1 -2
  151. data/samples/po/ko/hellotk.po +1 -2
  152. data/samples/po/nl/hello.po +24 -0
  153. data/samples/po/nl/hello2.po +32 -0
  154. data/samples/po/nl/hello_noop.po +28 -0
  155. data/samples/po/nl/hello_plural.po +26 -0
  156. data/samples/po/nl/helloglade2.po +31 -0
  157. data/samples/po/nl/hellogtk.po +24 -0
  158. data/samples/po/nl/hellotk.po +24 -0
  159. data/samples/po/pt_BR/hello.po +6 -5
  160. data/samples/po/pt_BR/hello2.po +6 -5
  161. data/samples/po/pt_BR/hello_noop.po +6 -5
  162. data/samples/po/pt_BR/hello_plural.po +6 -6
  163. data/samples/po/pt_BR/helloglade2.po +6 -5
  164. data/samples/po/pt_BR/hellogtk.po +6 -5
  165. data/samples/po/pt_BR/hellotk.po +6 -5
  166. data/samples/rails/README +21 -15
  167. data/samples/rails/Rakefile +10 -1
  168. data/samples/rails/app/controllers/application.rb +10 -18
  169. data/samples/rails/app/controllers/blog_controller.rb +1 -5
  170. data/samples/rails/app/helpers/blog_helper.rb +1 -1
  171. data/samples/rails/app/models/article.rb +15 -0
  172. data/samples/rails/app/views/blog/_form.rhtml +2 -2
  173. data/samples/rails/config/boot.rb +17 -0
  174. data/samples/rails/config/database.yml +5 -3
  175. data/samples/rails/config/environment.rb +40 -75
  176. data/samples/rails/config/environments/development.rb +12 -7
  177. data/samples/rails/config/environments/production.rb +17 -6
  178. data/samples/rails/config/environments/test.rb +8 -6
  179. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  180. data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  181. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  182. data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  183. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  184. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  185. data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  186. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  187. data/samples/rails/locale/fr/LC_MESSAGES/{lang_helper.mo → gettext_plugin.mo} +0 -0
  188. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  189. data/samples/rails/locale/ja/LC_MESSAGES/{lang_helper.mo → gettext_plugin.mo} +0 -0
  190. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  191. data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  192. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  193. data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  194. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  195. data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  196. data/samples/rails/po/blog.pot +57 -37
  197. data/samples/rails/po/cs/blog.po +116 -0
  198. data/samples/rails/po/cs/gettext_plugin.po +29 -0
  199. data/samples/rails/po/de/blog.po +70 -51
  200. data/samples/rails/po/de/{lang_helper.po → gettext_plugin.po} +4 -5
  201. data/samples/rails/po/en/blog.po +111 -0
  202. data/samples/rails/po/es/blog.po +67 -47
  203. data/samples/rails/po/es/{lang_helper.po → gettext_plugin.po} +5 -5
  204. data/samples/rails/po/fr/blog.po +65 -45
  205. data/samples/rails/po/fr/{lang_helper.po → gettext_plugin.po} +4 -4
  206. data/samples/rails/po/{lang_helper.pot → gettext_plugin.pot} +4 -4
  207. data/samples/rails/po/ja/blog.po +64 -44
  208. data/samples/rails/po/ja/{lang_helper.po → gettext_plugin.po} +4 -4
  209. data/samples/rails/po/ko/blog.po +65 -46
  210. data/samples/rails/po/ko/{lang_helper.po → gettext_plugin.po} +5 -6
  211. data/samples/rails/po/nl/blog.po +115 -0
  212. data/samples/rails/po/nl/gettext_plugin.po +28 -0
  213. data/samples/rails/po/pt_BR/blog.po +109 -0
  214. data/samples/rails/po/pt_BR/gettext_plugin.po +27 -0
  215. data/samples/rails/public/images/rails.png +0 -0
  216. data/samples/rails/public/index.html +272 -71
  217. data/samples/rails/public/javascripts/controls.js +441 -166
  218. data/samples/rails/public/javascripts/dragdrop.js +261 -279
  219. data/samples/rails/public/javascripts/effects.js +657 -277
  220. data/samples/rails/public/javascripts/prototype.js +911 -223
  221. data/samples/rails/public/robots.txt +1 -0
  222. data/samples/rails/public/stylesheets/scaffold.css +1 -1
  223. data/samples/rails/script/about +3 -0
  224. data/samples/rails/script/breakpointer +3 -4
  225. data/samples/rails/script/console +3 -23
  226. data/samples/rails/script/destroy +3 -7
  227. data/samples/rails/script/generate +3 -7
  228. data/samples/rails/script/performance/benchmarker +3 -0
  229. data/samples/rails/script/performance/profiler +3 -0
  230. data/samples/rails/script/plugin +3 -0
  231. data/samples/rails/script/process/reaper +3 -0
  232. data/samples/rails/script/process/spawner +3 -0
  233. data/samples/rails/script/process/spinner +3 -0
  234. data/samples/rails/script/runner +3 -29
  235. data/samples/rails/script/server +3 -49
  236. data/samples/rails/vendor/plugins/gettext/init.rb +19 -0
  237. data/samples/rails/vendor/{lang_helper.rb → plugins/gettext/lib/gettext_plugin.rb} +15 -11
  238. data/src/poparser.ry +171 -0
  239. data/test/gettext_runner.rb +3 -1
  240. data/test/gettext_test.rb +56 -31
  241. data/test/gettext_test_cgi.rb +12 -0
  242. data/test/gettext_test_parser.rb +3 -0
  243. data/test/gettext_test_string.rb +14 -0
  244. data/test/locale/cr/LC_MESSAGES/plural.mo +0 -0
  245. data/test/locale/da/LC_MESSAGES/plural.mo +0 -0
  246. data/test/locale/da/LC_MESSAGES/plural_error.mo +0 -0
  247. data/test/locale/fr/LC_MESSAGES/plural.mo +0 -0
  248. data/test/locale/fr/LC_MESSAGES/plural_error.mo +0 -0
  249. data/test/locale/ir/LC_MESSAGES/plural.mo +0 -0
  250. data/test/locale/la/LC_MESSAGES/plural.mo +0 -0
  251. data/test/locale/li/LC_MESSAGES/plural.mo +0 -0
  252. data/test/locale/po/LC_MESSAGES/plural.mo +0 -0
  253. data/test/locale/sl/LC_MESSAGES/plural.mo +0 -0
  254. data/test/po/cr/plural.po +3 -3
  255. data/test/po/da/plural.po +2 -2
  256. data/test/po/da/plural_error.po +2 -1
  257. data/test/po/fr/plural.po +2 -2
  258. data/test/po/fr/plural_error.po +2 -1
  259. data/test/po/ir/plural.po +3 -3
  260. data/test/po/la/plural.po +3 -3
  261. data/test/po/li/plural.po +3 -3
  262. data/test/po/po/plural.po +3 -3
  263. data/test/po/sl/plural.po +4 -4
  264. data/test/test.sh +1 -0
  265. data/test/test_rubyparser.rb +20 -0
  266. metadata +678 -551
  267. data/README.ja +0 -115
  268. data/data/locale/de/LC_MESSAGES/rmsgfmt.mo +0 -0
  269. data/data/locale/es/LC_MESSAGES/rmsgfmt.mo +0 -0
  270. data/data/locale/fr/LC_MESSAGES/rmsgfmt.mo +0 -0
  271. data/data/locale/it/LC_MESSAGES/rmsgfmt.mo +0 -0
  272. data/data/locale/ja/LC_MESSAGES/rmsgfmt.mo +0 -0
  273. data/data/locale/ko/LC_MESSAGES/rmsgfmt.mo +0 -0
  274. data/data/locale/pt_BR/LC_MESSAGES/rmsgfmt.mo +0 -0
  275. data/data/locale/sv/LC_MESSAGES/rmsgfmt.mo +0 -0
  276. data/po/de/rmsgfmt.po +0 -45
  277. data/po/es/rmsgfmt.po +0 -43
  278. data/po/fr/rmsgfmt.po +0 -43
  279. data/po/it/rmsgfmt.po +0 -44
  280. data/po/ja/rmsgfmt.po +0 -43
  281. data/po/ko/rmsgfmt.po +0 -40
  282. data/po/pt_BR/rmsgfmt.po +0 -42
  283. data/po/rmsgfmt.pot +0 -40
  284. data/po/sv/rmsgfmt.po +0 -43
  285. data/samples/rails/locale/de/LC_MESSAGES/lang_helper.mo +0 -0
  286. data/samples/rails/locale/es/LC_MESSAGES/lang_helper.mo +0 -0
  287. data/samples/rails/locale/ko/LC_MESSAGES/lang_helper.mo +0 -0
  288. data/src/rmsgfmt.ry +0 -233
data/bin/rgettext CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  You may redistribute it and/or modify it under the same
8
8
  license terms as Ruby.
9
+
10
+ $Id: rgettext,v 1.4 2005/11/27 15:35:54 mutoh Exp $
9
11
  =end
10
12
 
11
13
  begin
data/bin/rmsgfmt CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  You may redistribute it and/or modify it under the same
8
8
  license terms as Ruby.
9
+
10
+ $Id: rmsgfmt,v 1.3 2005/11/27 15:35:54 mutoh Exp $
9
11
  =end
10
12
 
11
13
  begin
data/bin/rmsgmerge ADDED
@@ -0,0 +1,24 @@
1
+ #! /usr/bin/ruby
2
+ =begin
3
+ rmsgmerge - ruby version of msgmerge
4
+
5
+ Copyright (C) 2005 Masao Mutoh
6
+
7
+ You may redistribute it and/or modify it under the same
8
+ license terms as Ruby.
9
+
10
+ $Id: rmsgmerge,v 1.2 2005/11/27 15:35:54 mutoh Exp $
11
+ =end
12
+
13
+ begin
14
+ require 'gettext/rmsgmerge'
15
+ rescue LoadError
16
+ begin
17
+ require 'rubygems'
18
+ require_gem 'gettext/rmsgmerge'
19
+ rescue LoadError
20
+ raise 'Ruby-GetText-Package are not installed.'
21
+ end
22
+ end
23
+
24
+ GetText.rmsgmerge
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
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.2 2005/08/20 17:05:34 mutoh Exp $
13
+ $Id: gettext.rb,v 1.5 2005/11/30 17:59:14 mutoh Exp $
14
14
  =end
15
15
 
16
16
  require 'rbconfig'
@@ -18,6 +18,7 @@ require 'gettext/version'
18
18
  require 'gettext/mo'
19
19
  require 'gettext/locale'
20
20
  require 'gettext/textdomain'
21
+ require 'gettext/string'
21
22
 
22
23
  module GetText
23
24
  class NoboundTextDomainError < RuntimeError
@@ -27,9 +28,15 @@ module GetText
27
28
  @@__textdomain_key = Hash.new
28
29
 
29
30
  @@output_charset = nil
31
+ @@locale = nil
30
32
 
31
33
  def bindtextdomain(domainname, path = nil, locale = nil, charset = nil)
32
- locale ||= Locale.get
34
+ if @@locale
35
+ locale = @@locale
36
+ Locale.set(Locale::CTYPE, locale)
37
+ else
38
+ locale ||= Locale.get
39
+ end
33
40
  if @@output_charset
34
41
  charset = @@output_charset
35
42
  else
@@ -43,6 +50,7 @@ module GetText
43
50
  textdomain = @@__textdomain_key[domainname]
44
51
  @@__textdomain[src] = textdomain
45
52
  end
53
+
46
54
  if ! textdomain or ! textdomain.same_property?(domainname, path, locale, charset)
47
55
  textdomain = TextDomain.new(domainname, path, locale, charset)
48
56
  @@__textdomain_key[domainname] = textdomain
@@ -67,7 +75,7 @@ module GetText
67
75
 
68
76
  def ngettext(msgid, msgid_plural, n)
69
77
  textdomain = @@__textdomain[callersrc]
70
- textdomain ? textdomain.ngettext(msgid, msgid_plural, n) : msgid
78
+ textdomain ? textdomain.ngettext(msgid, msgid_plural, n) : (n == 1 ? msgid : msgid_plural)
71
79
  end
72
80
 
73
81
  def N_(msgid)
@@ -94,6 +102,7 @@ module GetText
94
102
  end
95
103
 
96
104
  def locale=(locale)
105
+ @@locale = locale
97
106
  textdomain = @@__textdomain[callersrc]
98
107
  textdomain.set_locale(locale) if textdomain
99
108
  locale
@@ -107,6 +116,10 @@ module GetText
107
116
  @@output_charset
108
117
  end
109
118
 
119
+ def locale
120
+ @@locale
121
+ end
122
+
110
123
  def charset=(cs)
111
124
  textdomain = @@__textdomain[callersrc]
112
125
  textdomain.set_charset(cs) if textdomain
@@ -122,6 +135,6 @@ module GetText
122
135
  module_function :bindtextdomain, :textdomain,
123
136
  :N_, :gettext, :_, :ngettext, :n_,
124
137
  :sgettext, :s_, :callersrc,
125
- :setlocale, :set_locale, :locale=, :charset=,
138
+ :setlocale, :set_locale, :locale=, :locale, :charset=,
126
139
  :set_output_charset, :output_charset=, :output_charset
127
140
  end
data/lib/gettext/cgi.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: cgi.rb,v 1.2 2005/08/27 18:52:20 mutoh Exp $
9
+ $Id: cgi.rb,v 1.4 2005/12/07 17:09:39 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'cgi'
@@ -14,8 +14,10 @@ require 'gettext'
14
14
 
15
15
  module Locale
16
16
  alias :orig_get :get
17
+ alias :orig_set :set
17
18
 
18
19
  @@cgi = nil
20
+ @@locale_cgi = nil
19
21
 
20
22
  module_function
21
23
  def cgi=(cgi)
@@ -27,28 +29,40 @@ module Locale
27
29
  @@cgi
28
30
  end
29
31
 
30
- def get
31
- @@cgi = CGI.new unless @@cgi
32
- if ret = @@cgi["lang"] and ret.size > 0
33
- $stderr.print "query_string: lang = #{ret}\n" if $DEBUG
34
- elsif ret = @@cgi.cookies["lang"][0]
35
- print "cookie: lang = #{ret}\n" if $DEBUG
36
- elsif lang = @@cgi.accept_language
37
- $stderr.print "accept lanaugage: lang = #{lang}\n" if $DEBUG
38
-
39
- lang = lang.split(',').first.split('-') rescue []
40
- language = lang[0]
41
- dialect = lang[1]
42
- language = language ? language.downcase : 'en' # default is en
43
- dialect = dialect ? "_#{dialect.upcase}" : ""
44
- ret = "#{language}#{dialect}"
45
- else
46
- ret = "en"
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}"
39
+ end
40
+
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
47
55
  end
48
56
  $stderr.print "Locale.get = #{ret}\n" if $DEBUG
49
57
  ret
50
58
  end
51
59
 
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
65
+
52
66
  def codeset
53
67
  @@cgi = CGI.new unless @@cgi
54
68
  codesets = @@cgi.accept_charset
@@ -61,9 +75,10 @@ module Locale
61
75
  end
62
76
 
63
77
  alias :charset :codeset
78
+ alias :setlocale :set
64
79
  alias :set_cgi :cgi=
65
80
 
66
- module_function :charset, :set_cgi
81
+ module_function :charset, :set_cgi, :set, :setlocale
67
82
  end
68
83
 
69
84
  module GetText
@@ -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: locale.rb,v 1.3 2005/08/22 16:56:33 mutoh Exp $
9
+ $Id: locale.rb,v 1.4 2005/09/04 17:47:54 mutoh Exp $
10
10
  =end
11
11
 
12
12
  begin
@@ -41,18 +41,8 @@ else
41
41
  end
42
42
 
43
43
  module Locale
44
- def get
45
- ret = __get
46
- return ret if ret
47
-
48
- ret = nil
49
- ["LC_ALL", "LC_MESSAGES", "LANG"].each do |env|
50
- ret = ENV[env]
51
- break if ret
52
- end
53
-
54
- ret = "C" unless ret
55
- ret
44
+ def get(lctype = Locale::CTYPE)
45
+ __get(lctype)
56
46
  end
57
47
 
58
48
  alias :setlocale :set
@@ -6,14 +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: locale_default.rb,v 1.2 2005/08/20 17:05:34 mutoh Exp $
9
+ $Id: locale_default.rb,v 1.3 2005/09/04 17:47:54 mutoh Exp $
10
10
  =end
11
11
 
12
12
  module Locale
13
13
  @@locale_initialized = false
14
14
  alias :__set :set
15
15
  def __get(lctype = Locale::CTYPE)
16
- # Initialize CTYPE first lazily.
16
+ # Initialize lctype lazily.
17
17
  # This isn't called when 'gettext/cgi' is required.
18
18
  unless @@locale_initialized
19
19
  Locale.set(lctype, "")
@@ -6,19 +6,39 @@
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.2 2005/08/20 17:05:34 mutoh Exp $
9
+ $Id: locale_win32.rb,v 1.4 2005/12/29 07:02:52 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'gettext/locale_table_win32'
13
13
 
14
14
  module Locale
15
- def __get
16
- pri_id, sub_id = __locale_id
17
- lang = LocaleTable.assoc(pri_id)
18
- if lang.size == 3
19
- lang = lang[2].assoc(sub_id)
15
+ @@locale_win32 = {}
16
+ def __get(lctype = Locale::CTYPE)
17
+ ret = nil
18
+ if @@locale_win32[lctype]
19
+ ret = @@locale_win32[lctype]
20
+ else
21
+ ["LC_ALL", "LC_MESSAGES", "LANG"].each do |env|
22
+ ret = ENV[env]
23
+ break if ret
24
+ end
25
+ unless ret
26
+ pri_id, sub_id = __locale_id
27
+ lang = LocaleTable.assoc(pri_id)
28
+ if lang.size == 3
29
+ lang = lang[2].assoc(sub_id)
30
+ end
31
+ ret = lang ? lang[1] : "C"
32
+ end
33
+ @@locale_win32[lctype] = ret
34
+ end
35
+ ret
36
+ end
37
+
38
+ def set(lctype, loc)
39
+ if lctype == ALL
40
+ @@locale_win32[lctype] = loc
20
41
  end
21
- lang ? lang[1] : nil
22
42
  end
23
43
 
24
44
  unless defined? CTYPE
data/lib/gettext/mo.rb CHANGED
@@ -12,7 +12,7 @@
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.1.1.1 2005/08/13 02:38:09 mutoh Exp $
15
+ $Id: mo.rb,v 1.2 2005/10/22 10:49:59 mutoh Exp $
16
16
  =end
17
17
 
18
18
  require 'gettext/iconv'
@@ -233,6 +233,11 @@ class MOFile < Hash
233
233
  File.open(filename, 'wb'){|f| save_to_stream(f)}
234
234
  end
235
235
 
236
+ def set_comment(msgid_or_sym, comment)
237
+ #Do nothing
238
+ end
239
+
240
+
236
241
  attr_accessor :little_endian
237
242
  attr_reader :charset, :nplurals, :plural
238
243
  end
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/ruby
2
+ =begin
3
+ parser/activerecord.rb - parser for ActiveRecord
4
+
5
+ Copyright (C) 2005 Masao Mutoh
6
+
7
+ You may redistribute it and/or modify it under the same
8
+ license terms as Ruby.
9
+
10
+ $Id: activerecord.rb,v 1.2 2005/12/25 11:43:20 mutoh Exp $
11
+ =end
12
+
13
+ require 'gettext'
14
+ require 'gettext/parser/ruby'
15
+
16
+ module GetText
17
+ module ActiveRecordParser
18
+ extend GetText
19
+ include GetText
20
+ GetText.bindtextdomain("rgettext")
21
+
22
+ @config = {
23
+ :db_yml => "config/database.yml",
24
+ :db_mode => "development",
25
+ :activerecord_classes => ["ActiveRecord::Base"],
26
+ :use_classname => true,
27
+ }
28
+
29
+ @ar_re = nil
30
+
31
+ module_function
32
+ def require_rails(file)
33
+ begin
34
+ require file
35
+ rescue MissingSourceFile
36
+ $stderr.puts _("'%{file}' is not found.") % {:file => file}
37
+ end
38
+ end
39
+
40
+ def init(config)
41
+ if config
42
+ config.each{|k, v|
43
+ @config[k] = v
44
+ }
45
+ end
46
+ @ar_re = /class.*(#{@config[:activerecord_classes].join("|")})/
47
+ end
48
+
49
+ def parse(file, targets = [])
50
+ ActiveRecord::Base.establish_connection(@db)
51
+
52
+ old_constants = constants
53
+ begin
54
+ eval(open(file).read)
55
+ rescue
56
+ $stderr.puts _("Ignored '%{file}'. Solve dependencies first.") % {:file => file}
57
+ $stderr.puts $!
58
+ end
59
+ loaded_constants = constants - old_constants
60
+ loaded_constants.each do |classname|
61
+ klass = eval(classname)
62
+ if klass < ActiveRecord::Base
63
+ tablename = klass.human_attribute_name(klass.class_name)
64
+ targets << [tablename, "#{file}:-"]
65
+ begin
66
+ klass.columns.each do |column|
67
+ if @config[:use_classname]
68
+ targets << [tablename + "|" + klass.human_attribute_name(column.name), "#{file}:-"]
69
+ else
70
+ targets << [klass.human_attribute_name(column.name), "#{file}:-"]
71
+ end
72
+ end
73
+ rescue
74
+ $stderr.puts _("No database is available.")
75
+ $stderr.puts $!
76
+ end
77
+ end
78
+ end
79
+ if RubyParser.target?(file)
80
+ RubyParser.parse(file, targets)
81
+ end
82
+ end
83
+
84
+ def target?(file)
85
+ init(nil) unless @ar_re
86
+ data = IO.readlines(file)
87
+ data.each do |v|
88
+ if @ar_re =~ v
89
+ unless @db
90
+ require 'rubygems'
91
+ require 'active_record'
92
+ yml = YAML.load_file(@config[:db_yml])
93
+ @db = yml[:db_mode]
94
+ @db = yml["production"] unless @db
95
+ require_rails 'config/boot.rb'
96
+ require_rails 'config/environment.rb'
97
+ require_rails 'app/controllers/application.rb'
98
+ end
99
+ return true
100
+ end
101
+ end
102
+ false
103
+ end
104
+ end
105
+ end
106
+
107
+ if __FILE__ == $0
108
+ # ex) ruby model1.rb model2.rb
109
+ ARGV.each do |file|
110
+ if GetText::ActiveRecordParser.target?(file)
111
+ p file
112
+ p GetText::ActiveRecordParser.parse(file)
113
+ end
114
+ end
115
+ end