gettext 1.91.0 → 1.92.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. data/ChangeLog +111 -1
  2. data/NEWS +35 -0
  3. data/README +26 -24
  4. data/bin/rgettext +2 -2
  5. data/bin/rmsgfmt +2 -2
  6. data/bin/rmsgmerge +2 -2
  7. data/doc/classes/ActionView/Helpers/FormBuilder.html +11 -11
  8. data/doc/classes/ActionView/TemplateFinder.html +152 -0
  9. data/doc/classes/ActiveRecord/Base.html +87 -87
  10. data/doc/classes/ActiveRecord/ConnectionAdapters/Column.html +6 -6
  11. data/doc/classes/GetText.html +617 -491
  12. data/doc/classes/GetText/ActiveRecordParser.html +13 -13
  13. data/doc/classes/GetText/ErbContainer.html +12 -12
  14. data/doc/classes/GetText/ErbParser.html +6 -6
  15. data/doc/classes/GetText/NoboundTextDomainError.html +1 -1
  16. data/doc/classes/GetText/PoParser.html +11 -11
  17. data/doc/classes/GetText/Rails.html +20 -20
  18. data/doc/classes/GetText/RubyParser.html +5 -0
  19. data/doc/classes/GetText/TextDomain.html +53 -53
  20. data/doc/classes/GetText/TextDomainManager.html +54 -54
  21. data/doc/classes/Iconv.html +20 -20
  22. data/doc/classes/Locale.html +151 -151
  23. data/doc/classes/Locale/Object.html +92 -92
  24. data/doc/classes/Locale/SystemBase.html +32 -32
  25. data/doc/classes/Locale/SystemCGI.html +31 -31
  26. data/doc/classes/Locale/SystemWin32.html +6 -6
  27. data/doc/classes/MOFile.html +311 -293
  28. data/doc/classes/MOFile/HeaderRev1.html +150 -0
  29. data/doc/classes/Module.html +6 -6
  30. data/doc/created.rid +1 -1
  31. data/doc/files/ChangeLog.html +143 -2
  32. data/doc/files/README.html +31 -25
  33. data/doc/files/lib/gettext/active_record_rb.html +1 -1
  34. data/doc/files/lib/gettext/mo_rb.html +1 -1
  35. data/doc/files/lib/gettext/parser/active_record_rb.html +1 -1
  36. data/doc/files/lib/gettext/parser/ruby_rb.html +1 -1
  37. data/doc/files/lib/gettext/poparser_rb.html +1 -1
  38. data/doc/files/lib/gettext/rails_rb.html +1 -1
  39. data/doc/files/lib/gettext/rgettext_rb.html +1 -1
  40. data/doc/files/lib/gettext/rmsgfmt_rb.html +2 -1
  41. data/doc/files/lib/gettext/utils_rb.html +1 -1
  42. data/doc/files/lib/gettext/version_rb.html +1 -1
  43. data/doc/files/lib/gettext_rb.html +1 -1
  44. data/doc/fr_class_index.html +2 -0
  45. data/doc/fr_method_index.html +133 -129
  46. data/lib/gettext.rb +49 -7
  47. data/lib/gettext/active_record.rb +49 -4
  48. data/lib/gettext/mo.rb +39 -12
  49. data/lib/gettext/parser/active_record.rb +6 -4
  50. data/lib/gettext/parser/ruby.rb +11 -4
  51. data/lib/gettext/poparser.rb +81 -52
  52. data/lib/gettext/rails.rb +28 -11
  53. data/lib/gettext/rgettext.rb +6 -1
  54. data/lib/gettext/rmsgfmt.rb +3 -11
  55. data/lib/gettext/utils.rb +7 -3
  56. data/lib/gettext/version.rb +1 -1
  57. data/po/bs/rails.po +55 -20
  58. data/po/bs/rgettext.po +3 -3
  59. data/po/ca/rails.po +58 -31
  60. data/po/ca/rgettext.po +16 -18
  61. data/po/cs/rails.po +55 -20
  62. data/po/cs/rgettext.po +3 -3
  63. data/po/de/rails.po +55 -27
  64. data/po/de/rgettext.po +21 -22
  65. data/po/el/rails.po +60 -36
  66. data/po/el/rgettext.po +15 -17
  67. data/po/eo/rails.po +51 -23
  68. data/po/eo/rgettext.po +21 -20
  69. data/po/es/rails.po +57 -31
  70. data/po/es/rgettext.po +17 -18
  71. data/po/et/rails.po +55 -20
  72. data/po/fr/rails.po +56 -21
  73. data/po/fr/rgettext.po +3 -3
  74. data/po/hr/rails.po +55 -20
  75. data/po/hr/rgettext.po +3 -3
  76. data/po/hu/rails.po +54 -26
  77. data/po/hu/rgettext.po +18 -17
  78. data/po/it/rails.po +55 -20
  79. data/po/it/rgettext.po +3 -3
  80. data/po/ja/rails.po +54 -26
  81. data/po/ja/rgettext.po +17 -18
  82. data/po/ko/rails.po +56 -21
  83. data/po/ko/rgettext.po +3 -3
  84. data/po/lv/rails.po +155 -0
  85. data/po/lv/rgettext.po +137 -0
  86. data/po/nb/rails.po +61 -34
  87. data/po/nb/rgettext.po +22 -19
  88. data/po/nl/rails.po +56 -21
  89. data/po/nl/rgettext.po +3 -3
  90. data/po/pt_BR/rails.po +53 -26
  91. data/po/pt_BR/rgettext.po +19 -19
  92. data/po/rails.pot +44 -16
  93. data/po/rgettext.pot +3 -3
  94. data/po/ru/rails.po +62 -36
  95. data/po/ru/rgettext.po +19 -19
  96. data/po/sr/rails.po +87 -58
  97. data/po/sr/rgettext.po +38 -33
  98. data/po/sv/rgettext.po +3 -3
  99. data/po/ua/rails.po +62 -32
  100. data/po/ua/rgettext.po +19 -17
  101. data/po/vi/rails.po +56 -28
  102. data/po/vi/rgettext.po +35 -34
  103. data/po/zh/rails.po +52 -24
  104. data/po/zh/rgettext.po +22 -24
  105. data/po/zh_TW/rails.po +51 -23
  106. data/po/zh_TW/rgettext.po +16 -18
  107. data/samples/cgi/cookie.cgi +0 -0
  108. data/samples/cgi/helloerb1.cgi +0 -0
  109. data/samples/cgi/helloerb2.cgi +0 -0
  110. data/samples/cgi/http.rb +0 -0
  111. data/samples/cgi/index.cgi +0 -0
  112. data/samples/cgi/po/lv/helloerb1.po +65 -0
  113. data/samples/cgi/po/lv/helloerb2.po +52 -0
  114. data/samples/cgi/po/lv/hellolib.po +24 -0
  115. data/samples/cgi/po/lv/main.po +77 -0
  116. data/samples/cgi/po/nb/helloerb1.po +16 -14
  117. data/samples/cgi/po/nb/helloerb2.po +14 -12
  118. data/samples/cgi/po/nb/hellolib.po +9 -7
  119. data/samples/cgi/po/nb/main.po +20 -18
  120. data/samples/cgi/po/sr/helloerb1.po +8 -8
  121. data/samples/cgi/po/sr/helloerb2.po +6 -6
  122. data/samples/cgi/po/sr/hellolib.po +2 -2
  123. data/samples/cgi/po/sr/main.po +15 -15
  124. data/samples/cgi/po/ua/helloerb1.po +2 -2
  125. data/samples/cgi/po/ua/main.po +3 -3
  126. data/samples/hello_plural.rb +0 -0
  127. data/samples/makemo.rb +0 -0
  128. data/samples/po/lv/hello.po +24 -0
  129. data/samples/po/lv/hello2.po +32 -0
  130. data/samples/po/lv/hello_noop.po +28 -0
  131. data/samples/po/lv/hello_plural.po +26 -0
  132. data/samples/po/lv/helloglade2.po +38 -0
  133. data/samples/po/lv/hellogtk.po +24 -0
  134. data/samples/po/lv/hellotk.po +24 -0
  135. data/samples/po/nb/hello.po +9 -8
  136. data/samples/po/nb/hello2.po +9 -9
  137. data/samples/po/nb/hello_noop.po +10 -9
  138. data/samples/po/nb/hello_plural.po +10 -8
  139. data/samples/po/nb/helloglade2.po +10 -8
  140. data/samples/po/nb/hellogtk.po +9 -8
  141. data/samples/po/nb/hellotk.po +9 -7
  142. data/samples/po/sr/hello.po +2 -2
  143. data/samples/po/sr/hello2.po +4 -4
  144. data/samples/po/sr/hello_noop.po +3 -3
  145. data/samples/po/sr/hello_plural.po +3 -3
  146. data/samples/po/sr/helloglade2.po +4 -4
  147. data/samples/po/sr/hellogtk.po +2 -2
  148. data/samples/po/sr/hellotk.po +2 -2
  149. data/samples/po/ua/hello2.po +2 -2
  150. data/samples/po/ua/hello_plural.po +2 -2
  151. data/samples/rails/config/boot.rb +3 -2
  152. data/samples/rails/config/environment.rb +2 -3
  153. data/samples/rails/db/schema.rb +0 -0
  154. data/samples/rails/po/lv/blog.po +110 -0
  155. data/samples/rails/po/nb/blog.po +19 -15
  156. data/samples/rails/po/sr/blog.po +23 -23
  157. data/samples/rails/po/ua/blog.po +3 -3
  158. data/samples/rails/public/dispatch.cgi +0 -0
  159. data/samples/rails/public/dispatch.fcgi +0 -0
  160. data/samples/rails/public/dispatch.rb +0 -0
  161. data/samples/rails/public/javascripts/controls.js +1 -1
  162. data/samples/rails/public/javascripts/dragdrop.js +1 -1
  163. data/samples/rails/public/javascripts/effects.js +1 -1
  164. data/samples/rails/script/about +0 -0
  165. data/samples/rails/script/breakpointer +0 -0
  166. data/samples/rails/script/console +0 -0
  167. data/samples/rails/script/destroy +0 -0
  168. data/samples/rails/script/generate +0 -0
  169. data/samples/rails/script/performance/benchmarker +0 -0
  170. data/samples/rails/script/performance/profiler +0 -0
  171. data/samples/rails/script/plugin +0 -0
  172. data/samples/rails/script/process/reaper +0 -0
  173. data/samples/rails/script/process/spawner +0 -0
  174. data/samples/rails/script/process/spinner +0 -0
  175. data/samples/rails/script/runner +0 -0
  176. data/samples/rails/script/server +0 -0
  177. data/samples/rails/vendor/plugins/gettext/po/lv/gettext_plugin.po +28 -0
  178. data/samples/rails/vendor/plugins/gettext/po/nb/gettext_plugin.po +11 -8
  179. data/samples/rails/vendor/plugins/gettext/po/sr/gettext_plugin.po +5 -5
  180. data/src/poparser.ry +27 -6
  181. data/test/benchmark.rb +1 -1
  182. data/test/db/mysql.drop.sql +1 -0
  183. data/test/db/mysql.sql +13 -0
  184. data/test/fixtures/inept_wizard.rb +3 -0
  185. data/test/fixtures/people.yml +6 -0
  186. data/test/fixtures/topic.rb +30 -0
  187. data/test/fixtures/wizard.rb +5 -0
  188. data/test/po/active_record.pot +151 -66
  189. data/test/po/ja/active_record.po +177 -92
  190. data/test/po/ja/test_pgettext.po +41 -0
  191. data/test/rails/app/controllers/users_controller.rb +1 -0
  192. data/test/rails/app/views/articles/_form_fr.html.erb +1 -0
  193. data/test/rails/config/boot.rb +96 -32
  194. data/test/rails/config/environment.rb +3 -2
  195. data/test/rails/db/schema.rb +4 -4
  196. data/test/rails/public/dispatch.cgi +0 -0
  197. data/test/rails/public/dispatch.fcgi +0 -0
  198. data/test/rails/public/dispatch.rb +0 -0
  199. data/test/rails/public/javascripts/controls.js +484 -354
  200. data/test/rails/public/javascripts/dragdrop.js +88 -58
  201. data/test/rails/public/javascripts/effects.js +396 -364
  202. data/test/rails/public/javascripts/prototype.js +2817 -1107
  203. data/test/rails/script/about +0 -0
  204. data/test/rails/script/breakpointer +0 -0
  205. data/test/rails/script/console +0 -0
  206. data/test/rails/script/destroy +0 -0
  207. data/test/rails/script/generate +0 -0
  208. data/test/rails/script/performance/benchmarker +0 -0
  209. data/test/rails/script/performance/profiler +0 -0
  210. data/test/rails/script/plugin +0 -0
  211. data/test/rails/script/process/inspector +0 -0
  212. data/test/rails/script/process/reaper +0 -0
  213. data/test/rails/script/process/spawner +0 -0
  214. data/test/rails/script/runner +0 -0
  215. data/test/rails/script/server +0 -0
  216. data/test/rails/test/functional/articles_controller_test.rb +5 -0
  217. data/test/rails/test/result/en/create_error.html +3 -3
  218. data/test/rails/test/result/en/custom_error_message.html +3 -3
  219. data/test/rails/test/result/en/custom_error_message_with_plural.html +60 -60
  220. data/test/rails/test/result/en/multi_error_messages_for.html +6 -6
  221. data/test/rails/test/result/en/new.html +3 -3
  222. data/test/rails/test/result/fr/custom_error_message.html +3 -3
  223. data/test/rails/test/result/fr/custom_error_message_with_plural.html +60 -60
  224. data/test/rails/test/result/fr/new.html +23 -0
  225. data/test/rails/test/result/ja/create_error.html +3 -3
  226. data/test/rails/test/result/ja/custom_error_message.html +3 -3
  227. data/test/rails/test/result/ja/custom_error_message_with_plural.html +60 -60
  228. data/test/rails/test/result/ja/multi_error_messages_for.html +6 -6
  229. data/test/rails/test/result/ja/new.html +3 -3
  230. data/test/test.sh +2 -2
  231. data/test/test_active_record.rb +824 -20
  232. data/test/test_gettext.rb +34 -4
  233. data/test/test_java.sh +0 -0
  234. data/test/test_locale.rb +2 -2
  235. data/test/test_parser.rb +13 -2
  236. data/test/test_rails_caching.rb +11 -4
  237. data/test/testlib/pgettext.rb +33 -0
  238. metadata +32 -4
@@ -1,12 +1,12 @@
1
1
  =begin
2
2
  gettext/active_record.rb - GetText for ActiveRecord
3
3
 
4
- Copyright (C) 2006,2007 Masao Mutoh
4
+ Copyright (C) 2006-2008 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: active_record.rb,v 1.22 2008/05/05 14:31:06 mutoh Exp $
9
+ $Id: active_record.rb,v 1.25 2008/07/24 17:17:48 mutoh Exp $
10
10
  =end
11
11
  require 'gettext'
12
12
  require 'active_record'
@@ -107,6 +107,34 @@ module ActiveRecord #:nodoc:
107
107
  end
108
108
  alias_method_chain :validates_length_of, :gettext
109
109
 
110
+ def _validates_parse_custom_messages(*attrs) #:nodoc:
111
+ if attrs.last.is_a?(Hash) and attrs.last[:message]
112
+ msg = attrs.last[:message]
113
+ key = msg.dup
114
+ msg.sub!(/%\{val\}/, '%s')
115
+ @@custom_error_messages_d[key] = /\A#{Regexp.escape(msg).sub('%s', '(.*)')}\Z/
116
+ end
117
+ attrs
118
+ end
119
+
120
+ def validates_format_of_with_gettext(*attrs) #:nodoc:
121
+ attrs = _validates_parse_custom_messages(*attrs)
122
+ validates_format_of_without_gettext(*attrs)
123
+ end
124
+ alias_method_chain :validates_format_of, :gettext
125
+
126
+ def validates_inclusion_of_with_gettext(*attrs) #:nodoc:
127
+ attrs = _validates_parse_custom_messages(*attrs)
128
+ validates_inclusion_of_without_gettext(*attrs)
129
+ end
130
+ alias_method_chain :validates_inclusion_of, :gettext
131
+
132
+ def validates_exclusion_of_with_gettext(*attrs) #:nodoc:
133
+ attrs = _validates_parse_custom_messages(*attrs)
134
+ validates_exclusion_of_without_gettext(*attrs)
135
+ end
136
+ alias_method_chain :validates_exclusion_of, :gettext
137
+
110
138
  def custom_error_messages_d #:nodoc:
111
139
  @@custom_error_messages_d
112
140
  end
@@ -227,12 +255,26 @@ module ActiveRecord #:nodoc:
227
255
  :too_short => N_("%{fn} is too short (minimum is %d characters)"),
228
256
  :wrong_length => N_("%{fn} is the wrong length (should be %d characters)"),
229
257
  :taken => N_("%{fn} has already been taken"),
230
- :not_a_number => N_("%{fn} is not a number")
258
+ :not_a_number => N_("%{fn} is not a number"),
259
+ :greater_than => N_("%{fn} must be greater than %d"),
260
+ :greater_than_or_equal_to => N_("%{fn} must be greater than or equal to %d"),
261
+ :equal_to => N_("%{fn} must be equal to %d"),
262
+ :less_than => N_("%{fn} must be less than %d"),
263
+ :less_than_or_equal_to => N_("%{fn} must be less than or equal to %d"),
264
+ :odd => N_("%{fn} must be odd"),
265
+ :even => N_("%{fn} must be even")
231
266
  )
232
267
  @@default_error_messages_d = {
233
268
  default_error_messages[:too_long] => /#{Regexp.escape(default_error_messages[:too_long]).sub(/%d/, '(\d+)')}/,
234
269
  default_error_messages[:too_short] => /#{Regexp.escape(default_error_messages[:too_short]).sub(/%d/, '(\d+)')}/,
235
270
  default_error_messages[:wrong_length] => /#{Regexp.escape(default_error_messages[:wrong_length]).sub(/%d/, '(\d+)')}/,
271
+ default_error_messages[:greater_than] => /#{Regexp.escape(default_error_messages[:greater_than]).sub(/%d/, '(\d+)')}/,
272
+ default_error_messages[:greater_than_or_equal_to] => /#{Regexp.escape(default_error_messages[:greater_than_or_equal_to]).sub(/%d/, '(\d+)')}/,
273
+ default_error_messages[:equal_to] => /#{Regexp.escape(default_error_messages[:equal_to]).sub(/%d/, '(\d+)')}/,
274
+ default_error_messages[:less_than] => /#{Regexp.escape(default_error_messages[:less_than]).sub(/%d/, '(\d+)')}/,
275
+ default_error_messages[:less_than_or_equal_to] => /#{Regexp.escape(default_error_messages[:less_than_or_equal_to]).sub(/%d/, '(\d+)')}/,
276
+ default_error_messages[:odd] => /#{Regexp.escape(default_error_messages[:odd]).sub(/%d/, '(\d+)')}/,
277
+ default_error_messages[:even] => /#{Regexp.escape(default_error_messages[:even]).sub(/%d/, '(\d+)')}/,
236
278
  }
237
279
  cattr_accessor :default_error_messages_d
238
280
 
@@ -243,7 +285,8 @@ module ActiveRecord #:nodoc:
243
285
  if regexp =~ msg
244
286
  custom_msg = @base.gettext(key)
245
287
  custom_msg = _(msg) if custom_msg == msg
246
- custom_msg = _(custom_msg) % $1.to_i
288
+ custom_msg = _(custom_msg) % $1
289
+ custom_msg = _(custom_msg) % {:val => $1}
247
290
  break
248
291
  end
249
292
  end
@@ -252,6 +295,7 @@ module ActiveRecord #:nodoc:
252
295
  custom_msg = @base.gettext(msg)
253
296
  custom_msg = _(msg) if custom_msg == msg
254
297
  end
298
+
255
299
  if attr == "base"
256
300
  full_message = custom_msg
257
301
  elsif /%\{fn\}/ =~ custom_msg
@@ -290,6 +334,7 @@ module ActiveRecord #:nodoc:
290
334
  errors.size == 1 ? errors.first : errors
291
335
  end
292
336
  alias_method_chain :on, :gettext
337
+ alias :[] :on
293
338
 
294
339
  # Returns all the full error messages in an array.
295
340
  # * If the error messages include %{fn}, it returns formatted text such as "foo %{fn}" => "foo Field"
data/lib/gettext/mo.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  =begin
2
2
  mo.rb - A simple class for operating GNU MO file.
3
3
 
4
- Copyright (C) 2003-2006 Masao Mutoh
4
+ Copyright (C) 2003-2008 Masao Mutoh
5
5
  Copyright (C) 2002 Masahiro Sakai, Masao Mutoh
6
6
  Copyright (C) 2001 Masahiro Sakai
7
7
 
8
- Masahiro Sakai <s01397ms@sfc.keio.ac.jp>
9
- Masao Mutoh <mutoh@highway.ne.jp>
8
+ Masahiro Sakai <s01397ms at sfc.keio.ac.jp>
9
+ Masao Mutoh <mutoh at highway.ne.jp>
10
10
 
11
11
  You can redistribute this file and/or modify it under the same term
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.9 2008/03/22 04:43:32 mutoh Exp $
15
+ $Id: mo.rb,v 1.10 2008/06/17 16:40:52 mutoh Exp $
16
16
  =end
17
17
 
18
18
  require 'gettext/iconv'
@@ -31,6 +31,16 @@ class MOFile < Hash
31
31
  :hash_table_size,
32
32
  :hash_table_offset)
33
33
 
34
+ # The following are only used in .mo files
35
+ # with minor revision >= 1.
36
+ class HeaderRev1 < Header
37
+ attr_accessor :n_sysdep_segments,
38
+ :sysdep_segments_offset,
39
+ :n_sysdep_strings,
40
+ :orig_sysdep_tab_offset,
41
+ :trans_sysdep_tab_offset
42
+ end
43
+
34
44
  MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde"
35
45
  MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95"
36
46
 
@@ -84,14 +94,26 @@ class MOFile < Hash
84
94
  raise InvalidFormat.new(sprintf("Unknown signature %s", magic.dump))
85
95
  end
86
96
 
87
- header = Header.new(magic, *(io.read(4 * 6).unpack(@little_endian ? 'V6' : 'N6')))
88
- raise InvalidFormat.new(sprintf("file format revision %d isn't supported", header.revision)) if header.revision > 0
97
+ endian_type6 = @little_endian ? 'V6' : 'N6'
98
+ endian_type_astr = @little_endian ? 'V*' : 'N*'
99
+
100
+ header = HeaderRev1.new(magic, *(io.read(4 * 6).unpack(endian_type6)))
89
101
 
102
+ if header.revision == 1
103
+ # FIXME: It doesn't support sysdep correctly.
104
+ header.n_sysdep_segments = io.read(4).unpack(endian_type6)
105
+ header.sysdep_segments_offset = io.read(4).unpack(endian_type6)
106
+ header.n_sysdep_strings = io.read(4).unpack(endian_type6)
107
+ header.orig_sysdep_tab_offset = io.read(4).unpack(endian_type6)
108
+ header.trans_sysdep_tab_offset = io.read(4).unpack(endian_type6)
109
+ elsif header.revision > 1
110
+ raise InvalidFormat.new(sprintf("file format revision %d isn't supported", header.revision))
111
+ end
90
112
  io.pos = header.orig_table_offset
91
- orig_table_data = io.read((4 * 2) * header.nstrings).unpack(@little_endian ? 'V*' : 'N*')
113
+ orig_table_data = io.read((4 * 2) * header.nstrings).unpack(endian_type_astr)
92
114
 
93
115
  io.pos = header.translated_table_offset
94
- trans_table_data = io.read((4 * 2) * header.nstrings).unpack(@little_endian ? 'V*' : 'N*')
116
+ trans_table_data = io.read((4 * 2) * header.nstrings).unpack(endian_type_astr)
95
117
 
96
118
  original_strings = Array.new(header.nstrings)
97
119
  for i in 0...header.nstrings
@@ -135,7 +157,7 @@ class MOFile < Hash
135
157
  end
136
158
  end
137
159
  end
138
- self[original_strings[i]] = str
160
+ self[original_strings[i]] = str.freeze
139
161
  end
140
162
  self
141
163
  end
@@ -252,7 +274,12 @@ class MOFile < Hash
252
274
 
253
275
  def load_from_file(filename)
254
276
  @filename = filename
255
- File.open(filename, 'rb'){|f| load_from_stream(f)}
277
+ begin
278
+ File.open(filename, 'rb'){|f| load_from_stream(f)}
279
+ rescue => e
280
+ e.set_backtrace("File: #{@filename}")
281
+ raise e
282
+ end
256
283
  end
257
284
 
258
285
  def save_to_file(filename)
@@ -285,8 +312,8 @@ if $0 == __FILE__
285
312
  puts "plural = \"#{mo.plural}\""
286
313
  puts "------------------------------------------------------------------"
287
314
  mo.each do |key, value|
288
- puts "original message = \"#{key}\""
289
- puts "translated message = \"#{value}\""
315
+ puts "original message = #{key.inspect}"
316
+ puts "translated message = #{value.inspect}"
290
317
  puts "--------------------------------------------------------------------"
291
318
  end
292
319
  }
@@ -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: active_record.rb,v 1.6 2007/07/03 01:58:47 mutoh Exp $
10
+ $Id: active_record.rb,v 1.7 2008/07/14 15:35:07 mutoh Exp $
11
11
  =end
12
12
 
13
13
  require 'gettext'
@@ -84,7 +84,7 @@ module GetText
84
84
  loaded_constants.each do |classname|
85
85
  klass = eval(classname, TOPLEVEL_BINDING)
86
86
  if klass.is_a?(Class) && klass < ActiveRecord::Base
87
- unless klass.untranslate_all?
87
+ unless (klass.untranslate_all? || klass.abstract_class?)
88
88
  add_target(targets, file, ::Inflector.singularize(klass.table_name.gsub(/_/, " ")))
89
89
  unless klass.class_name == classname
90
90
  add_target(targets, file, ::Inflector.singularize(classname.gsub(/_/, " ").downcase))
@@ -117,8 +117,10 @@ module GetText
117
117
  def add_target(targets, file, msgid) # :nodoc:
118
118
  file_lineno = "#{file}:-"
119
119
  key_existed = targets.assoc(msgid)
120
- if key_existed and ! targets[targets.index(key_existed)].include?(file_lineno)
121
- targets[targets.index(key_existed)] = key_existed << file_lineno
120
+ if key_existed
121
+ unless targets[targets.index(key_existed)].include?(file_lineno)
122
+ targets[targets.index(key_existed)] = key_existed << file_lineno
123
+ end
122
124
  else
123
125
  targets << [msgid, "#{file}:-"]
124
126
  end
@@ -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.10 2007/07/02 16:40:18 mutoh Exp $
12
+ $Id: ruby.rb,v 1.11 2008/07/26 06:59:35 mutoh Exp $
13
13
  =end
14
14
 
15
15
  require 'irb/ruby-lex.rb'
@@ -63,6 +63,7 @@ module GetText
63
63
  module RubyParser
64
64
  ID = ['gettext', '_', 'N_', 'sgettext', 's_']
65
65
  PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
66
+ MSGCTXT_ID = ['pgettext', 'p_']
66
67
 
67
68
  module_function
68
69
  def parse(file, targets = []) # :nodoc:
@@ -89,6 +90,8 @@ module GetText
89
90
  target = :normal
90
91
  elsif PLURAL_ID.include?(tk.name)
91
92
  target = :plural
93
+ elsif MSGCTXT_ID.include?(tk.name)
94
+ target = :msgctxt
92
95
  else
93
96
  target = nil
94
97
  end
@@ -104,9 +107,13 @@ module GetText
104
107
  when RubyToken::TkPLUS, RubyToken::TkNL
105
108
  #do nothing
106
109
  when RubyToken::TkCOMMA
107
- if msgid and target == :plural
108
- msgid += "\000"
109
- target = :normal
110
+ if msgid
111
+ if target == :plural
112
+ msgid += "\000"
113
+ elsif target == :msgctxt
114
+ msgid += "\004"
115
+ end
116
+ target = :normal
110
117
  end
111
118
  else
112
119
  if msgid
@@ -20,7 +20,7 @@ module GetText
20
20
 
21
21
  class PoParser < Racc::Parser
22
22
 
23
- module_eval <<'..end src/poparser.ry modeval..id99edf64163', 'src/poparser.ry', 94
23
+ module_eval <<'..end src/poparser.ry modeval..ida6d91c8151', 'src/poparser.ry', 108
24
24
  include GetText
25
25
  GetText.bindtextdomain("rgettext")
26
26
 
@@ -36,13 +36,18 @@ module_eval <<'..end src/poparser.ry modeval..id99edf64163', 'src/poparser.ry',
36
36
  @comments = []
37
37
  @data = data
38
38
  @fuzzy = false
39
+ @msgctxt = ""
39
40
  $ignore_fuzzy = ignore_fuzzy
41
+
40
42
  str.strip!
41
43
  @q = []
42
44
  until str.empty? do
43
45
  case str
44
46
  when /\A\s+/
45
47
  str = $'
48
+ when /\Amsgctxt/
49
+ @q.push [:MSGCTXT, $&]
50
+ str = $'
46
51
  when /\Amsgid_plural/
47
52
  @q.push [:MSGID_PLURAL, $&]
48
53
  str = $'
@@ -97,6 +102,7 @@ module_eval <<'..end src/poparser.ry modeval..id99edf64163', 'src/poparser.ry',
97
102
  @data.set_comment(msgid, @comments.join("\n"))
98
103
  end
99
104
  @comments.clear
105
+ @msgctxt = ""
100
106
  end
101
107
 
102
108
  def on_comment(comment)
@@ -104,73 +110,79 @@ module_eval <<'..end src/poparser.ry modeval..id99edf64163', 'src/poparser.ry',
104
110
  @comments << comment
105
111
  end
106
112
 
107
- ..end src/poparser.ry modeval..id99edf64163
113
+
114
+ ..end src/poparser.ry modeval..ida6d91c8151
108
115
 
109
116
  ##### racc 1.4.5 generates ###
110
117
 
111
118
  racc_reduce_table = [
112
119
  0, 0, :racc_error,
113
- 0, 9, :_reduce_none,
114
- 2, 9, :_reduce_none,
115
- 2, 9, :_reduce_none,
116
- 4, 11, :_reduce_4,
117
- 5, 11, :_reduce_5,
118
- 2, 13, :_reduce_6,
120
+ 0, 10, :_reduce_none,
121
+ 2, 10, :_reduce_none,
122
+ 2, 10, :_reduce_none,
123
+ 2, 10, :_reduce_none,
124
+ 2, 12, :_reduce_5,
119
125
  1, 13, :_reduce_none,
120
- 3, 14, :_reduce_8,
121
- 1, 10, :_reduce_9,
122
- 2, 12, :_reduce_10,
123
- 1, 12, :_reduce_11 ]
126
+ 1, 13, :_reduce_none,
127
+ 4, 15, :_reduce_8,
128
+ 5, 16, :_reduce_9,
129
+ 2, 17, :_reduce_10,
130
+ 1, 17, :_reduce_none,
131
+ 3, 18, :_reduce_12,
132
+ 1, 11, :_reduce_13,
133
+ 2, 14, :_reduce_14,
134
+ 1, 14, :_reduce_15 ]
124
135
 
125
- racc_reduce_n = 12
136
+ racc_reduce_n = 16
126
137
 
127
- racc_shift_n = 21
138
+ racc_shift_n = 26
128
139
 
129
140
  racc_action_table = [
130
- 3, 9, 4, 5, 10, 11, 12, 17, 12, 9,
131
- 9, 7, 12, 17, 19, 9, 12 ]
141
+ 3, 13, 5, 7, 9, 15, 16, 17, 20, 17,
142
+ 13, 17, 13, 13, 11, 17, 23, 20, 13, 17 ]
132
143
 
133
144
  racc_action_check = [
134
- 1, 5, 1, 1, 8, 8, 8, 13, 13, 10,
135
- 11, 3, 14, 15, 17, 19, 20 ]
145
+ 1, 16, 1, 1, 1, 12, 12, 12, 18, 18,
146
+ 7, 14, 15, 9, 3, 19, 20, 21, 23, 25 ]
136
147
 
137
148
  racc_action_pointer = [
138
- nil, 0, nil, 11, nil, -5, nil, nil, 0, nil,
139
- 3, 4, nil, 2, 6, 8, nil, 7, nil, 9,
140
- 10 ]
149
+ nil, 0, nil, 14, nil, nil, nil, 3, nil, 6,
150
+ nil, nil, 0, nil, 4, 5, -6, nil, 2, 8,
151
+ 8, 11, nil, 11, nil, 12 ]
141
152
 
142
153
  racc_action_default = [
143
- -1, -12, -3, -12, -9, -12, -2, 21, -12, -11,
144
- -12, -12, -10, -12, -4, -5, -7, -12, -6, -12,
145
- -8 ]
154
+ -1, -16, -2, -16, -3, -13, -4, -16, -6, -16,
155
+ -7, 26, -16, -15, -5, -16, -16, -14, -16, -8,
156
+ -16, -9, -11, -16, -10, -12 ]
146
157
 
147
158
  racc_goto_table = [
148
- 8, 16, 2, 18, 6, 13, 14, 15, 1, nil,
149
- nil, nil, nil, nil, 20 ]
159
+ 12, 22, 14, 4, 24, 6, 2, 8, 18, 19,
160
+ 10, 21, 1, nil, nil, nil, 25 ]
150
161
 
151
162
  racc_goto_check = [
152
- 4, 6, 3, 6, 2, 4, 4, 5, 1, nil,
153
- nil, nil, nil, nil, 4 ]
163
+ 5, 9, 5, 3, 9, 4, 2, 6, 5, 5,
164
+ 7, 8, 1, nil, nil, nil, 5 ]
154
165
 
155
166
  racc_goto_pointer = [
156
- nil, 8, 3, 1, -5, -6, -12 ]
167
+ nil, 12, 5, 2, 4, -7, 6, 9, -7, -17 ]
157
168
 
158
169
  racc_goto_default = [
159
- nil, nil, nil, nil, nil, nil, nil ]
170
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ]
160
171
 
161
172
  racc_token_table = {
162
173
  false => 0,
163
174
  Object.new => 1,
164
175
  :COMMENT => 2,
165
176
  :MSGID => 3,
166
- :MSGID_PLURAL => 4,
167
- :MSGSTR => 5,
168
- :STRING => 6,
169
- :PLURAL_NUM => 7 }
177
+ :MSGCTXT => 4,
178
+ :MSGID_PLURAL => 5,
179
+ :MSGSTR => 6,
180
+ :STRING => 7,
181
+ :PLURAL_NUM => 8 }
170
182
 
171
183
  racc_use_result_var = true
172
184
 
173
- racc_nt_base = 8
185
+ racc_nt_base = 9
174
186
 
175
187
  Racc_arg = [
176
188
  racc_action_table,
@@ -193,6 +205,7 @@ Racc_token_to_s_table = [
193
205
  'error',
194
206
  'COMMENT',
195
207
  'MSGID',
208
+ 'MSGCTXT',
196
209
  'MSGID_PLURAL',
197
210
  'MSGSTR',
198
211
  'STRING',
@@ -200,8 +213,11 @@ Racc_token_to_s_table = [
200
213
  '$start',
201
214
  'msgfmt',
202
215
  'comment',
216
+ 'msgctxt',
203
217
  'message',
204
218
  'string_list',
219
+ 'single_message',
220
+ 'plural_message',
205
221
  'msgstr_plural',
206
222
  'msgstr_plural_line']
207
223
 
@@ -217,8 +233,21 @@ Racc_debug_parser = true
217
233
 
218
234
  # reduce 3 omitted
219
235
 
220
- module_eval <<'.,.,', 'src/poparser.ry', 36
221
- def _reduce_4( val, _values, result )
236
+ # reduce 4 omitted
237
+
238
+ module_eval <<'.,.,', 'src/poparser.ry', 25
239
+ def _reduce_5( val, _values, result )
240
+ @msgctxt = unescape(val[1]) + "\004"
241
+ result
242
+ end
243
+ .,.,
244
+
245
+ # reduce 6 omitted
246
+
247
+ # reduce 7 omitted
248
+
249
+ module_eval <<'.,.,', 'src/poparser.ry', 48
250
+ def _reduce_8( val, _values, result )
222
251
  if @fuzzy and $ignore_fuzzy
223
252
  if val[1] != ""
224
253
  $stderr.print _("Warning: fuzzy message was ignored.\n")
@@ -228,15 +257,15 @@ module_eval <<'.,.,', 'src/poparser.ry', 36
228
257
  end
229
258
  @fuzzy = false
230
259
  else
231
- on_message(unescape(val[1]), unescape(val[3]))
260
+ on_message(@msgctxt + unescape(val[1]), unescape(val[3]))
232
261
  end
233
262
  result = ""
234
263
  result
235
264
  end
236
265
  .,.,
237
266
 
238
- module_eval <<'.,.,', 'src/poparser.ry', 51
239
- def _reduce_5( val, _values, result )
267
+ module_eval <<'.,.,', 'src/poparser.ry', 65
268
+ def _reduce_9( val, _values, result )
240
269
  if @fuzzy and $ignore_fuzzy
241
270
  if val[1] != ""
242
271
  $stderr.print _("Warning: fuzzy message was ignored.\n")
@@ -246,15 +275,15 @@ module_eval <<'.,.,', 'src/poparser.ry', 51
246
275
  end
247
276
  @fuzzy = false
248
277
  else
249
- on_message(unescape(val[1]) + "\000" + unescape(val[3]), unescape(val[4]))
278
+ on_message(@msgctxt + unescape(val[1]) + "\000" + unescape(val[3]), unescape(val[4]))
250
279
  end
251
280
  result = ""
252
281
  result
253
282
  end
254
283
  .,.,
255
284
 
256
- module_eval <<'.,.,', 'src/poparser.ry', 62
257
- def _reduce_6( val, _values, result )
285
+ module_eval <<'.,.,', 'src/poparser.ry', 76
286
+ def _reduce_10( val, _values, result )
258
287
  if val[0].size > 0
259
288
  result = val[0] + "\000" + val[1]
260
289
  else
@@ -264,31 +293,31 @@ module_eval <<'.,.,', 'src/poparser.ry', 62
264
293
  end
265
294
  .,.,
266
295
 
267
- # reduce 7 omitted
296
+ # reduce 11 omitted
268
297
 
269
- module_eval <<'.,.,', 'src/poparser.ry', 70
270
- def _reduce_8( val, _values, result )
298
+ module_eval <<'.,.,', 'src/poparser.ry', 84
299
+ def _reduce_12( val, _values, result )
271
300
  result = val[2]
272
301
  result
273
302
  end
274
303
  .,.,
275
304
 
276
- module_eval <<'.,.,', 'src/poparser.ry', 77
277
- def _reduce_9( val, _values, result )
305
+ module_eval <<'.,.,', 'src/poparser.ry', 91
306
+ def _reduce_13( val, _values, result )
278
307
  on_comment(val[0])
279
308
  result
280
309
  end
281
310
  .,.,
282
311
 
283
- module_eval <<'.,.,', 'src/poparser.ry', 85
284
- def _reduce_10( val, _values, result )
312
+ module_eval <<'.,.,', 'src/poparser.ry', 99
313
+ def _reduce_14( val, _values, result )
285
314
  result = val.delete_if{|item| item == ""}.join
286
315
  result
287
316
  end
288
317
  .,.,
289
318
 
290
- module_eval <<'.,.,', 'src/poparser.ry', 89
291
- def _reduce_11( val, _values, result )
319
+ module_eval <<'.,.,', 'src/poparser.ry', 103
320
+ def _reduce_15( val, _values, result )
292
321
  result = val[0]
293
322
  result
294
323
  end