gettext 1.0.0-mswin32 → 1.1.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (301) hide show
  1. data/ChangeLog +193 -0
  2. data/NEWS +51 -1
  3. data/README +29 -11
  4. data/Rakefile +70 -56
  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/ext/gettext/gettext/_locale.BAK +86 -0
  27. data/ext/gettext/gettext/_locale.c +1 -1
  28. data/ext/gettext/gettext/_locale.exp +0 -0
  29. data/ext/gettext/gettext/_locale.lib +0 -0
  30. data/ext/gettext/gettext/_locale.obj +0 -0
  31. data/ext/gettext/gettext/_locale.pdb +0 -0
  32. data/ext/gettext/gettext/_locale.so +0 -0
  33. data/ext/gettext/gettext/mkmf.log +4 -4
  34. data/ext/gettext/gettext/vc70.pdb +0 -0
  35. data/lib/_locale.so +0 -0
  36. data/lib/gettext.rb +17 -4
  37. data/lib/gettext/cgi.rb +34 -19
  38. data/lib/gettext/locale.rb +3 -13
  39. data/lib/gettext/locale_default.rb +2 -2
  40. data/lib/gettext/locale_win32.rb +27 -7
  41. data/lib/gettext/mo.rb +6 -1
  42. data/lib/gettext/parser/activerecord.rb +115 -0
  43. data/lib/gettext/parser/glade.rb +3 -1
  44. data/lib/gettext/parser/ruby.rb +56 -57
  45. data/lib/gettext/poparser.rb +297 -0
  46. data/lib/gettext/rails.rb +161 -3
  47. data/lib/gettext/rgettext.rb +19 -9
  48. data/lib/gettext/rmsgfmt.rb +95 -363
  49. data/lib/gettext/rmsgmerge.rb +381 -0
  50. data/lib/gettext/string.rb +26 -0
  51. data/lib/gettext/textdomain.rb +21 -18
  52. data/lib/gettext/utils.rb +55 -0
  53. data/lib/gettext/version.rb +1 -1
  54. data/po/cs/rails.po +83 -0
  55. data/po/cs/rgettext.po +104 -0
  56. data/po/de/rails.po +79 -0
  57. data/po/de/rgettext.po +72 -21
  58. data/po/es/rails.po +80 -0
  59. data/po/es/rgettext.po +75 -19
  60. data/po/fr/rails.po +81 -0
  61. data/po/fr/rgettext.po +75 -19
  62. data/po/it/rgettext.po +68 -17
  63. data/po/ja/rails.po +78 -0
  64. data/po/ja/rgettext.po +71 -20
  65. data/po/ko/rails.po +77 -0
  66. data/po/ko/rgettext.po +74 -22
  67. data/po/nl/rails.po +80 -0
  68. data/po/nl/rgettext.po +102 -0
  69. data/po/pt_BR/rails.po +79 -0
  70. data/po/pt_BR/rgettext.po +77 -24
  71. data/po/rails.pot +80 -0
  72. data/po/rgettext.pot +63 -13
  73. data/po/sv/rgettext.po +63 -15
  74. data/samples/cgi/cookie.cgi +5 -0
  75. data/samples/cgi/helloerb1.cgi +4 -0
  76. data/samples/cgi/helloerb2.cgi +5 -0
  77. data/samples/cgi/index.cgi +5 -0
  78. data/samples/cgi/locale/cs/LC_MESSAGES/helloerb1.mo +0 -0
  79. data/samples/cgi/locale/cs/LC_MESSAGES/helloerb2.mo +0 -0
  80. data/samples/cgi/locale/cs/LC_MESSAGES/hellolib.mo +0 -0
  81. data/samples/cgi/locale/cs/LC_MESSAGES/main.mo +0 -0
  82. data/samples/cgi/locale/fr/LC_MESSAGES/main.mo +0 -0
  83. data/samples/cgi/locale/ko/LC_MESSAGES/helloerb1.mo +0 -0
  84. data/samples/cgi/locale/ko/LC_MESSAGES/helloerb2.mo +0 -0
  85. data/samples/cgi/locale/ko/LC_MESSAGES/hellolib.mo +0 -0
  86. data/samples/cgi/locale/ko/LC_MESSAGES/main.mo +0 -0
  87. data/samples/cgi/locale/nl/LC_MESSAGES/helloerb1.mo +0 -0
  88. data/samples/cgi/locale/nl/LC_MESSAGES/helloerb2.mo +0 -0
  89. data/samples/cgi/locale/nl/LC_MESSAGES/hellolib.mo +0 -0
  90. data/samples/cgi/locale/nl/LC_MESSAGES/main.mo +0 -0
  91. data/samples/cgi/locale/pt_BR/LC_MESSAGES/helloerb1.mo +0 -0
  92. data/samples/cgi/locale/pt_BR/LC_MESSAGES/helloerb2.mo +0 -0
  93. data/samples/cgi/locale/pt_BR/LC_MESSAGES/hellolib.mo +0 -0
  94. data/samples/cgi/locale/pt_BR/LC_MESSAGES/main.mo +0 -0
  95. data/samples/cgi/po/cs/helloerb1.po +66 -0
  96. data/samples/cgi/po/cs/helloerb2.po +52 -0
  97. data/samples/cgi/po/cs/hellolib.po +25 -0
  98. data/samples/cgi/po/cs/main.po +78 -0
  99. data/samples/cgi/po/fr/main.po +8 -8
  100. data/samples/cgi/po/ko/helloerb1.po +2 -3
  101. data/samples/cgi/po/ko/helloerb2.po +1 -2
  102. data/samples/cgi/po/ko/hellolib.po +1 -2
  103. data/samples/cgi/po/ko/main.po +2 -3
  104. data/samples/cgi/po/nl/helloerb1.po +60 -0
  105. data/samples/cgi/po/nl/helloerb2.po +52 -0
  106. data/samples/cgi/po/nl/hellolib.po +24 -0
  107. data/samples/cgi/po/nl/main.po +76 -0
  108. data/samples/cgi/po/pt_BR/helloerb1.po +59 -0
  109. data/samples/cgi/po/pt_BR/helloerb2.po +51 -0
  110. data/samples/cgi/po/pt_BR/hellolib.po +22 -0
  111. data/samples/cgi/po/pt_BR/main.po +75 -0
  112. data/samples/locale/cs/LC_MESSAGES/hello.mo +0 -0
  113. data/samples/locale/cs/LC_MESSAGES/hello2.mo +0 -0
  114. data/samples/locale/cs/LC_MESSAGES/hello_noop.mo +0 -0
  115. data/samples/locale/cs/LC_MESSAGES/hello_plural.mo +0 -0
  116. data/samples/locale/cs/LC_MESSAGES/helloglade2.mo +0 -0
  117. data/samples/locale/cs/LC_MESSAGES/hellogtk.mo +0 -0
  118. data/samples/locale/cs/LC_MESSAGES/hellotk.mo +0 -0
  119. data/samples/locale/fr/LC_MESSAGES/helloglade2.mo +0 -0
  120. data/samples/locale/ko/LC_MESSAGES/hello.mo +0 -0
  121. data/samples/locale/ko/LC_MESSAGES/hello2.mo +0 -0
  122. data/samples/locale/ko/LC_MESSAGES/hello_noop.mo +0 -0
  123. data/samples/locale/ko/LC_MESSAGES/hello_plural.mo +0 -0
  124. data/samples/locale/ko/LC_MESSAGES/helloglade2.mo +0 -0
  125. data/samples/locale/ko/LC_MESSAGES/hellogtk.mo +0 -0
  126. data/samples/locale/ko/LC_MESSAGES/hellotk.mo +0 -0
  127. data/samples/locale/nl/LC_MESSAGES/hello.mo +0 -0
  128. data/samples/locale/nl/LC_MESSAGES/hello2.mo +0 -0
  129. data/samples/locale/nl/LC_MESSAGES/hello_noop.mo +0 -0
  130. data/samples/locale/nl/LC_MESSAGES/hello_plural.mo +0 -0
  131. data/samples/locale/nl/LC_MESSAGES/helloglade2.mo +0 -0
  132. data/samples/locale/nl/LC_MESSAGES/hellogtk.mo +0 -0
  133. data/samples/locale/nl/LC_MESSAGES/hellotk.mo +0 -0
  134. data/samples/locale/pt_BR/LC_MESSAGES/hello.mo +0 -0
  135. data/samples/locale/pt_BR/LC_MESSAGES/hello2.mo +0 -0
  136. data/samples/locale/pt_BR/LC_MESSAGES/hello_noop.mo +0 -0
  137. data/samples/locale/pt_BR/LC_MESSAGES/hello_plural.mo +0 -0
  138. data/samples/locale/pt_BR/LC_MESSAGES/helloglade2.mo +0 -0
  139. data/samples/locale/pt_BR/LC_MESSAGES/hellogtk.mo +0 -0
  140. data/samples/locale/pt_BR/LC_MESSAGES/hellotk.mo +0 -0
  141. data/samples/po/cs/hello.po +23 -0
  142. data/samples/po/cs/hello2.po +31 -0
  143. data/samples/po/cs/hello_noop.po +27 -0
  144. data/samples/po/cs/hello_plural.po +26 -0
  145. data/samples/po/cs/helloglade2.po +37 -0
  146. data/samples/po/cs/hellogtk.po +23 -0
  147. data/samples/po/cs/hellotk.po +23 -0
  148. data/samples/po/fr/helloglade2.po +2 -2
  149. data/samples/po/hello.pot +1 -0
  150. data/samples/po/hello2.pot +1 -0
  151. data/samples/po/hello_noop.pot +2 -1
  152. data/samples/po/hello_plural.pot +6 -2
  153. data/samples/po/helloglade2.pot +8 -3
  154. data/samples/po/hellotk.pot +4 -0
  155. data/samples/po/ko/hello.po +1 -2
  156. data/samples/po/ko/hello2.po +1 -2
  157. data/samples/po/ko/hello_noop.po +1 -2
  158. data/samples/po/ko/hello_plural.po +1 -2
  159. data/samples/po/ko/helloglade2.po +2 -2
  160. data/samples/po/ko/hellogtk.po +1 -2
  161. data/samples/po/ko/hellotk.po +1 -2
  162. data/samples/po/nl/hello.po +24 -0
  163. data/samples/po/nl/hello2.po +32 -0
  164. data/samples/po/nl/hello_noop.po +28 -0
  165. data/samples/po/nl/hello_plural.po +26 -0
  166. data/samples/po/nl/helloglade2.po +31 -0
  167. data/samples/po/nl/hellogtk.po +24 -0
  168. data/samples/po/nl/hellotk.po +24 -0
  169. data/samples/po/pt_BR/hello.po +6 -5
  170. data/samples/po/pt_BR/hello2.po +6 -5
  171. data/samples/po/pt_BR/hello_noop.po +6 -5
  172. data/samples/po/pt_BR/hello_plural.po +6 -6
  173. data/samples/po/pt_BR/helloglade2.po +6 -5
  174. data/samples/po/pt_BR/hellogtk.po +6 -5
  175. data/samples/po/pt_BR/hellotk.po +6 -5
  176. data/samples/rails/README +21 -15
  177. data/samples/rails/Rakefile +10 -1
  178. data/samples/rails/app/controllers/application.rb +10 -18
  179. data/samples/rails/app/controllers/blog_controller.rb +1 -5
  180. data/samples/rails/app/helpers/blog_helper.rb +1 -1
  181. data/samples/rails/app/models/article.rb +15 -0
  182. data/samples/rails/app/views/blog/_form.rhtml +2 -2
  183. data/samples/rails/config/boot.rb +17 -0
  184. data/samples/rails/config/database.yml +6 -4
  185. data/samples/rails/config/environment.rb +40 -75
  186. data/samples/rails/config/environments/development.rb +12 -7
  187. data/samples/rails/config/environments/production.rb +17 -6
  188. data/samples/rails/config/environments/test.rb +8 -6
  189. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  190. data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  191. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  192. data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  193. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  194. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  195. data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  196. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  197. data/samples/rails/locale/fr/LC_MESSAGES/{lang_helper.mo → gettext_plugin.mo} +0 -0
  198. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  199. data/samples/rails/locale/ja/LC_MESSAGES/{lang_helper.mo → gettext_plugin.mo} +0 -0
  200. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  201. data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  202. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  203. data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  204. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  205. data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  206. data/samples/rails/po/blog.pot +57 -37
  207. data/samples/rails/po/cs/blog.po +116 -0
  208. data/samples/rails/po/cs/gettext_plugin.po +29 -0
  209. data/samples/rails/po/de/blog.po +70 -51
  210. data/samples/rails/po/de/{lang_helper.po → gettext_plugin.po} +4 -5
  211. data/samples/rails/po/en/blog.po +111 -0
  212. data/samples/rails/po/es/blog.po +67 -47
  213. data/samples/rails/po/es/{lang_helper.po → gettext_plugin.po} +5 -5
  214. data/samples/rails/po/fr/blog.po +65 -45
  215. data/samples/rails/po/fr/{lang_helper.po → gettext_plugin.po} +4 -4
  216. data/samples/rails/po/{lang_helper.pot → gettext_plugin.pot} +4 -4
  217. data/samples/rails/po/ja/blog.po +64 -44
  218. data/samples/rails/po/ja/{lang_helper.po → gettext_plugin.po} +4 -4
  219. data/samples/rails/po/ko/blog.po +65 -46
  220. data/samples/rails/po/ko/{lang_helper.po → gettext_plugin.po} +5 -6
  221. data/samples/rails/po/nl/blog.po +115 -0
  222. data/samples/rails/po/nl/gettext_plugin.po +28 -0
  223. data/samples/rails/po/pt_BR/blog.po +109 -0
  224. data/samples/rails/po/pt_BR/gettext_plugin.po +27 -0
  225. data/samples/rails/public/images/rails.png +0 -0
  226. data/samples/rails/public/index.html +272 -71
  227. data/samples/rails/public/javascripts/controls.js +441 -166
  228. data/samples/rails/public/javascripts/dragdrop.js +261 -279
  229. data/samples/rails/public/javascripts/effects.js +657 -277
  230. data/samples/rails/public/javascripts/prototype.js +911 -223
  231. data/samples/rails/public/robots.txt +1 -0
  232. data/samples/rails/public/stylesheets/scaffold.css +1 -1
  233. data/samples/rails/script/about +3 -0
  234. data/samples/rails/script/breakpointer +3 -4
  235. data/samples/rails/script/console +3 -23
  236. data/samples/rails/script/destroy +3 -7
  237. data/samples/rails/script/generate +3 -7
  238. data/samples/rails/script/performance/benchmarker +3 -0
  239. data/samples/rails/script/performance/profiler +3 -0
  240. data/samples/rails/script/plugin +3 -0
  241. data/samples/rails/script/process/reaper +3 -0
  242. data/samples/rails/script/process/spawner +3 -0
  243. data/samples/rails/script/process/spinner +3 -0
  244. data/samples/rails/script/runner +3 -29
  245. data/samples/rails/script/server +3 -49
  246. data/samples/rails/vendor/plugins/gettext/init.rb +19 -0
  247. data/samples/rails/vendor/{lang_helper.rb → plugins/gettext/lib/gettext_plugin.rb} +15 -11
  248. data/src/poparser.ry +171 -0
  249. data/test/gettext_runner.rb +3 -1
  250. data/test/gettext_test.rb +56 -31
  251. data/test/gettext_test_cgi.rb +12 -0
  252. data/test/gettext_test_parser.rb +3 -0
  253. data/test/gettext_test_string.rb +14 -0
  254. data/test/locale/cr/LC_MESSAGES/plural.mo +0 -0
  255. data/test/locale/da/LC_MESSAGES/plural.mo +0 -0
  256. data/test/locale/da/LC_MESSAGES/plural_error.mo +0 -0
  257. data/test/locale/fr/LC_MESSAGES/plural.mo +0 -0
  258. data/test/locale/fr/LC_MESSAGES/plural_error.mo +0 -0
  259. data/test/locale/ir/LC_MESSAGES/plural.mo +0 -0
  260. data/test/locale/la/LC_MESSAGES/plural.mo +0 -0
  261. data/test/locale/li/LC_MESSAGES/plural.mo +0 -0
  262. data/test/locale/po/LC_MESSAGES/plural.mo +0 -0
  263. data/test/locale/sl/LC_MESSAGES/plural.mo +0 -0
  264. data/test/po/cr/plural.po +3 -3
  265. data/test/po/da/plural.po +2 -2
  266. data/test/po/da/plural_error.po +2 -1
  267. data/test/po/fr/plural.po +2 -2
  268. data/test/po/fr/plural_error.po +2 -1
  269. data/test/po/ir/plural.po +3 -3
  270. data/test/po/la/plural.po +3 -3
  271. data/test/po/li/plural.po +3 -3
  272. data/test/po/po/plural.po +3 -3
  273. data/test/po/sl/plural.po +4 -4
  274. data/test/test.sh +1 -0
  275. data/test/test_rubyparser.rb +20 -0
  276. data/test/{test_rubyparser_n.rb → test_rubyparser_N.rb} +0 -0
  277. metadata +163 -43
  278. data/README.ja +0 -115
  279. data/data/locale/de/LC_MESSAGES/rmsgfmt.mo +0 -0
  280. data/data/locale/es/LC_MESSAGES/rmsgfmt.mo +0 -0
  281. data/data/locale/fr/LC_MESSAGES/rmsgfmt.mo +0 -0
  282. data/data/locale/it/LC_MESSAGES/rmsgfmt.mo +0 -0
  283. data/data/locale/ja/LC_MESSAGES/rmsgfmt.mo +0 -0
  284. data/data/locale/ko/LC_MESSAGES/rmsgfmt.mo +0 -0
  285. data/data/locale/pt_BR/LC_MESSAGES/rmsgfmt.mo +0 -0
  286. data/data/locale/sv/LC_MESSAGES/rmsgfmt.mo +0 -0
  287. data/gettext-1.0.0-mswin32.gem +0 -0
  288. data/po/de/rmsgfmt.po +0 -45
  289. data/po/es/rmsgfmt.po +0 -43
  290. data/po/fr/rmsgfmt.po +0 -43
  291. data/po/it/rmsgfmt.po +0 -44
  292. data/po/ja/rmsgfmt.po +0 -43
  293. data/po/ko/rmsgfmt.po +0 -40
  294. data/po/pt_BR/rmsgfmt.po +0 -42
  295. data/po/rmsgfmt.pot +0 -40
  296. data/po/sv/rmsgfmt.po +0 -43
  297. data/samples/rails/locale/de/LC_MESSAGES/lang_helper.mo +0 -0
  298. data/samples/rails/locale/es/LC_MESSAGES/lang_helper.mo +0 -0
  299. data/samples/rails/locale/ko/LC_MESSAGES/lang_helper.mo +0 -0
  300. data/samples/rails/log/development.log +0 -378
  301. data/src/rmsgfmt.ry +0 -233
@@ -0,0 +1,381 @@
1
+ =begin
2
+ rmsgmerge.rb - Merge old .po to new .po
3
+
4
+ Copyright (C) 2005 Masao Mutoh
5
+ Copyright (C) 2005 speakillof
6
+
7
+ You may redistribute it and/or modify it under the same
8
+ license terms as Ruby.
9
+ =end
10
+
11
+ require 'optparse'
12
+ require 'gettext'
13
+ require 'gettext/poparser'
14
+
15
+ module GetText
16
+
17
+ module RMsgMerge
18
+
19
+ class PoData
20
+
21
+ attr_reader :msgids
22
+
23
+ def initialize
24
+ @msgid2msgstr = {}
25
+ @msgid2comment = {}
26
+ @msgids = []
27
+ end
28
+
29
+ def set_comment(msgid_or_sym, comment)
30
+ @msgid2comment[msgid_or_sym] = comment
31
+ end
32
+
33
+ def msgstr(msgid)
34
+ @msgid2msgstr[msgid]
35
+ end
36
+
37
+ def comment(msgid)
38
+ @msgid2comment[msgid]
39
+ end
40
+
41
+ def [](msgid)
42
+ @msgid2msgstr[msgid]
43
+ end
44
+
45
+ def []=(msgid, msgstr)
46
+ # Retain the order
47
+ unless @msgid2msgstr[msgid]
48
+ @msgids << msgid
49
+ end
50
+
51
+ @msgid2msgstr[msgid] = msgstr
52
+ end
53
+
54
+ def each_msgid
55
+ arr = @msgids.delete_if{|i| Symbol === i or i == ''}
56
+ arr.each do |i|
57
+ yield i
58
+ end
59
+ end
60
+
61
+ def msgid?(msgid)
62
+ !(Symbol === msgid) and @msgid2msgstr[msgid] and (msgid != '')
63
+ end
64
+
65
+ # Is it necessary to implement this method?
66
+ def search_msgid_fuzzy(msgid, used_msgids)
67
+ nil
68
+ end
69
+
70
+ def nplural
71
+ unless @msgid2msgstr['']
72
+ return 0
73
+ else
74
+ if /\s*nplural\s*=\s*(\d+)/ =~ @msgid2msgstr['']
75
+ return $1.to_i
76
+ else
77
+ return 0
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ def generate_po
84
+ str = ''
85
+ str << generate_po_header
86
+
87
+ self.each_msgid do |id|
88
+ str << self.generate_po_entry(id)
89
+ end
90
+
91
+ str << @msgid2comment[:last]
92
+ str
93
+ end
94
+
95
+ def generate_po_header
96
+ str = ""
97
+
98
+ str << @msgid2comment[''].strip << "\n"
99
+ str << 'msgid ""' << "\n"
100
+ str << 'msgstr ""' << "\n"
101
+ msgstr = @msgid2msgstr[''].gsub(/"/, '\"').gsub(/\r/, '')
102
+ msgstr = msgstr.gsub(/^(.*)$/, '"\1\n"')
103
+ str << msgstr
104
+ str << "\n"
105
+
106
+ str
107
+ end
108
+
109
+ def generate_po_entry(msgid)
110
+ str = ""
111
+ str << @msgid2comment[msgid] << "\n"
112
+
113
+ id = msgid.gsub(/"/, '\"').gsub(/\r/, '')
114
+ msgstr = @msgid2msgstr[msgid].gsub(/"/, '\"').gsub(/\r/, '')
115
+
116
+ if id.include?("\000")
117
+ ids = id.split(/\000/)
118
+ str << "msgid " << __conv(ids[0]) << "\n"
119
+ ids[1..-1].each do |single_id|
120
+ str << "msgid_plural " << __conv(single_id) << "\n"
121
+ end
122
+
123
+ msgstr.split("\000").each_with_index do |m, n|
124
+ str << "msgstr[#{n}] " << __conv(m) << "\n"
125
+ end
126
+ else
127
+ str << "msgid " << __conv(id) << "\n"
128
+ str << "msgstr " << __conv(msgstr) << "\n"
129
+ end
130
+
131
+ str << "\n"
132
+ str
133
+ end
134
+
135
+ def __conv(str)
136
+ s = ''
137
+
138
+ if str.count("\n") > 1
139
+ s << '""' << "\n"
140
+ s << str.gsub(/^(.*)$/, '"\1\n"')
141
+ else
142
+ s << str.gsub(/^(.*)$/, '"\1\n"')
143
+ end
144
+
145
+ s.rstrip
146
+ end
147
+
148
+ end
149
+
150
+ class Merger__
151
+
152
+ # From gettext source.
153
+ #
154
+ # Merge the reference with the definition: take the #. and
155
+ # #: comments from the reference, take the # comments from
156
+ # the definition, take the msgstr from the definition. Add
157
+ # this merged entry to the output message list.
158
+ COMMENT_RE = /\A#\.|\A#\:/
159
+
160
+ CRLF_RE = /\r?\n/
161
+
162
+ def initialize
163
+ end
164
+
165
+ def merge(definition, reference)
166
+ # deep copy
167
+ result = Marshal.load( Marshal.dump(reference) )
168
+
169
+ used = []
170
+ merge_header(result, definition)
171
+
172
+ result.each_msgid do |msgid|
173
+ if definition.msgid?(msgid)
174
+ used << msgid
175
+ merge_message(msgid, result, msgid, definition)
176
+ elsif other_msgid = definition.search_msgid_fuzzy(msgid, used)
177
+ used << other_msgid
178
+ merge_fuzzy_message(msgid, result, other_msgid, definition)
179
+ else
180
+ if msgid.index("\000") and (reference.msgstr(msgid).gsub("\000", '') == '')
181
+ #plural
182
+ result[msgid] = "\000" * definition.nplural
183
+ end
184
+ end
185
+ end
186
+
187
+ ###################################################################
188
+ # msgids which are not used in reference are handled as obsolete. #
189
+ ###################################################################
190
+ last_comment = result.comment(:last) || ''
191
+ definition.each_msgid do |msgid|
192
+ unless used.include?(msgid)
193
+ last_comment << "\n"
194
+ last_comment << definition.generate_po_entry(msgid).strip.gsub(/^/, '#~ ')
195
+ last_comment << "\n"
196
+ end
197
+ end
198
+ result.set_comment(:last, last_comment)
199
+
200
+ result
201
+ end
202
+
203
+ def merge_message(msgid, target, def_msgid, definition)
204
+ merge_comment(msgid, target, def_msgid, definition)
205
+
206
+ ############################################
207
+ # check mismatch of msgid and msgid_plural #
208
+ ############################################
209
+ def_msgstr = definition[def_msgid]
210
+ if msgid.index("\000")
211
+ if def_msgstr.index("\000")
212
+ # OK
213
+ target[msgid] = def_msgstr
214
+ else
215
+ # NG
216
+ s = ''
217
+ definition.nplural.times {
218
+ s << def_msgstr
219
+ s << "\000"
220
+ }
221
+ target[msgid] = s
222
+ end
223
+ else
224
+ if def_msgstr.index("\000")
225
+ # NG
226
+ target[msgid] = def_msgstr.split("\000")[0]
227
+ else
228
+ # OK
229
+ target[msgid] = def_msgstr
230
+ end
231
+ end
232
+ end
233
+
234
+ # for the future
235
+ def merge_fuzzy_message(msgid, target, def_msgid, definition)
236
+ merge_message(msgid, target, def_msgid, definition)
237
+ end
238
+
239
+ def merge_comment(msgid, target, def_msgid, definition)
240
+ comment = target.comment(msgid)
241
+ def_comment = definition.comment(def_msgid)
242
+ new_comment = []
243
+
244
+ def_comment.split(CRLF_RE).each do |l|
245
+ unless COMMENT_RE =~ l
246
+ new_comment << l
247
+ end
248
+ end
249
+
250
+ comment.split(CRLF_RE).each do |l|
251
+ if COMMENT_RE =~ l
252
+ new_comment << l
253
+ end
254
+ end
255
+
256
+ target.set_comment(msgid, new_comment.join("\n"))
257
+ end
258
+
259
+ def merge_header(target, definition)
260
+ merge_comment('', target, '', definition)
261
+
262
+ msg = target.msgstr('')
263
+ def_msg = definition.msgstr('')
264
+ if /POT-Creation-Date:\s*(.*)?\s*\\n/ =~ msg
265
+ time = $1
266
+ def_msg = def_msg.sub(/POT-Creation-Date:.*\\n/, "POT-Creation-Date: #{time}" + '\n')
267
+ end
268
+
269
+ target[''] = def_msg
270
+ end
271
+
272
+ end
273
+
274
+ end
275
+
276
+ end
277
+
278
+
279
+
280
+ #
281
+ # commands
282
+ #
283
+ module GetText
284
+
285
+ module RMsgMerge
286
+ extend GetText
287
+
288
+ bindtextdomain("rgettext")
289
+
290
+ # constant values
291
+ VERSION = GetText::VERSION
292
+ DATE = %w($Date: 2005/11/27 15:35:55 $)[1]
293
+
294
+ module_function
295
+
296
+ def check_options
297
+ output = STDOUT
298
+
299
+ opts = OptionParser.new
300
+ opts.banner = _("Usage: %s def.po ref.pot [-o output.pot]") % $0
301
+ opts.separator("")
302
+ opts.separator(_("Merges two Uniforum style .po files together. The def.po file is an existing PO file with translations. The ref.pot file is the last created PO file with up-to-date source references. ref.pot is generally created by rgettext."))
303
+ opts.separator("")
304
+ opts.separator(_("Specific options:"))
305
+
306
+ opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
307
+ unless FileTest.exist? out
308
+ output = File.new(File.expand_path(out), "w+")
309
+ else
310
+ #$stderr.puts(_("File '%s' has already existed.") % out)
311
+ #exit 1
312
+ end
313
+ end
314
+
315
+ opts.on_tail("--version", _("display version information and exit")) do
316
+ puts "#{$0} #{VERSION} (#{DATE})"
317
+ exit
318
+ end
319
+
320
+ opts.parse!(ARGV)
321
+
322
+ if ARGV.size != 2
323
+ puts opts.help
324
+ exit 1
325
+ end
326
+
327
+ [ARGV[0], ARGV[1], output]
328
+ end
329
+
330
+ def run(reference = nil, definition = nil, out = STDOUT)
331
+ if reference.nil? or definition.nil?
332
+ definition, reference, out = check_options()
333
+ end
334
+
335
+ if definition.nil?
336
+ raise ArgumentError, _("definition po is not given.")
337
+ elsif reference.nil?
338
+ raise ArgumentError, _("reference pot is not given.")
339
+ end
340
+
341
+ parser = PoParser.new
342
+ defstr = nil; refstr = nil
343
+ File.open(definition){|f| defstr = f.read}; File.open(reference){|f| refstr = f.read}
344
+ defpo = parser.parse(defstr, PoData.new)
345
+ refpot = parser.parse(refstr, PoData.new)
346
+
347
+ m = Merger__.new
348
+ result = m.merge(defpo, refpot)
349
+ pp result if $DEBUG
350
+ print result.generate_po if $DEBUG
351
+
352
+ begin
353
+ if out.is_a? String
354
+ File.open(File.expand_path(out), "w+") do |file|
355
+ file.write(result.generate_po)
356
+ end
357
+ else
358
+ out.puts(result.generate_po)
359
+ end
360
+ ensure
361
+ out.close
362
+ end
363
+ end
364
+ end
365
+
366
+ module_function
367
+ def rmsgmerge(reference = nil, definition = nil, out = STDOUT)
368
+ RMsgMerge.run(reference, definition, out)
369
+ end
370
+ end
371
+
372
+
373
+ if $0 == __FILE__ then
374
+ require 'pp'
375
+
376
+ #parser = GetText::RMsgMerge::PoParser.new;
377
+ #parser = GetText::PoParser.new;
378
+ #pp parser.parse(ARGF.read)
379
+
380
+ GetText.rmsgmerge
381
+ end
@@ -0,0 +1,26 @@
1
+ #! /usr/bin/ruby
2
+ =begin
3
+ string.rb - Extension for String.
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
+ =end
10
+
11
+ class String
12
+ alias :_old_format_m :%
13
+
14
+ def %(args)
15
+ if args.kind_of?(Hash)
16
+ ret = dup
17
+ args.each {|key, value|
18
+ ret.gsub!(/\%\{#{key}\}/, value.to_s)
19
+ }
20
+ ret
21
+ else
22
+ ret = gsub(/%\{/, '%%{')
23
+ ret._old_format_m(args)
24
+ end
25
+ end
26
+ end
@@ -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.4 2005/08/29 18:24:36 mutoh Exp $
13
+ $Id: textdomain.rb,v 1.8 2005/12/23 04:00:52 mutoh Exp $
14
14
  =end
15
15
 
16
16
  require 'rbconfig'
@@ -21,6 +21,8 @@ module GetText
21
21
  GEM_PATH_RE = /(.*)\/lib$/
22
22
  LOCALE_RE = /^([A-Za-z]+)(_[A-Za-z]+)?(\.\S+)?((?:@[^@]*)*)/
23
23
 
24
+ attr_reader :locales
25
+
24
26
  DEFAULT_LOCALE_DIRS = [
25
27
  "#{Config::CONFIG['datadir']}/locale/%s/LC_MESSAGES/%s.mo",
26
28
  "#{Config::CONFIG['prefix']}/share/locale/%s/LC_MESSAGES/%s.mo",
@@ -58,7 +60,7 @@ module GetText
58
60
  @mofiles = Hash.new
59
61
  set_charset(charset, false)
60
62
  set_locale(locale, false)
61
- load_mo(false)
63
+ load_mo
62
64
 
63
65
  $stderr.puts "Search path:#{@locale_dirs.inspect}" if $DEBUG
64
66
  end
@@ -97,8 +99,11 @@ module GetText
97
99
  end
98
100
 
99
101
  def ngettext(msgid, msgid_plural, n)
100
- msg = gettext(msgid + "\000" + msgid_plural)
101
- if msg.include?("\000")
102
+ key = msgid + "\000" + msgid_plural
103
+ msg = gettext(key)
104
+ if msg == key
105
+ msg = n == 1 ? msgid : msgid_plural
106
+ elsif msg.include?("\000")
102
107
  ary = msg.split("\000")
103
108
  if @mo
104
109
  plural = eval(@mo.plural)
@@ -115,13 +120,9 @@ module GetText
115
120
  end
116
121
 
117
122
  def no_mo_file
118
- if (@locales.include?("C") || @locales.include?("en"))
119
- $stderr.puts "\nMO file is not found."
120
- else
121
- $stderr.puts "\nMO file is not found in"
122
- @search_files.each do |fname|
123
- $stderr.puts "\t#{fname}"
124
- end
123
+ $stderr.puts "\nMO file is not found in"
124
+ @search_files.each do |fname|
125
+ $stderr.puts "\t#{fname}"
125
126
  end
126
127
  end
127
128
 
@@ -143,25 +144,27 @@ module GetText
143
144
 
144
145
  def load_mo(cache = true)
145
146
  @mo = nil
146
- return nil if @locales.include?("C") || @locales.include?("en")
147
147
  if cache
148
- @locales.each do |locale|
149
- if @mo = @mofiles[locale]
150
- return @mo
151
- end
152
- end
148
+ @mo = @mofiles[@locales[0]]
149
+ if @mo
150
+ return @mo == :empty ? nil : @mo
151
+ end
153
152
  end
154
153
  @locale_dirs.each do |dir|
155
154
  @locales.each{|locale|
156
155
  fname = dir % [locale, @name]
157
156
  @search_files << fname
158
157
  if File.exist?(fname)
158
+ $stderr.puts "GetText::TextDomain#load_mo: mo file is #{fname}" if $DEBUG
159
159
  @mo = MOFile.open(fname, @charset)
160
- @mofiles[locale] = @mo
160
+ @mofiles[@locales[0]] = @mo
161
161
  break
162
162
  end
163
163
  }
164
164
  end
165
+ unless @mo
166
+ @mofiles[@locales[0]] = :empty
167
+ end
165
168
  @mo
166
169
  end
167
170
  end