gettext 1.8.0-mswin32 → 1.9.0-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. data/ChangeLog +120 -0
  2. data/NEWS +16 -0
  3. data/README +27 -19
  4. data/data/locale/ca/LC_MESSAGES/rails.mo +0 -0
  5. data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
  6. data/data/locale/cs/LC_MESSAGES/rails.mo +0 -0
  7. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  8. data/data/locale/de/LC_MESSAGES/rails.mo +0 -0
  9. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  10. data/data/locale/el/LC_MESSAGES/rails.mo +0 -0
  11. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  12. data/data/locale/eo/LC_MESSAGES/rails.mo +0 -0
  13. data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
  14. data/data/locale/es/LC_MESSAGES/rails.mo +0 -0
  15. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  16. data/data/locale/et/LC_MESSAGES/rails.mo +0 -0
  17. data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
  18. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/it/LC_MESSAGES/rails.mo +0 -0
  20. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/ja/LC_MESSAGES/rails.mo +0 -0
  22. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/ko/LC_MESSAGES/rails.mo +0 -0
  24. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/nl/LC_MESSAGES/rails.mo +0 -0
  26. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  27. data/data/locale/pt_BR/LC_MESSAGES/rails.mo +0 -0
  28. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  29. data/data/locale/ru/LC_MESSAGES/rails.mo +0 -0
  30. data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
  31. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  32. data/data/locale/zh/LC_MESSAGES/rails.mo +0 -0
  33. data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
  34. data/data/locale/zh_TW/LC_MESSAGES/rails.mo +0 -0
  35. data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
  36. data/ext/gettext/Makefile +22 -19
  37. data/ext/gettext/mkmf.log +3 -9
  38. data/lib/gettext.rb +13 -10
  39. data/lib/gettext/active_record.rb +130 -113
  40. data/lib/gettext/erb.rb +2 -2
  41. data/lib/gettext/locale.rb +11 -5
  42. data/lib/gettext/locale_cgi.rb +3 -3
  43. data/lib/gettext/locale_posix.rb +2 -2
  44. data/lib/gettext/locale_win32.rb +2 -1
  45. data/lib/gettext/parser/active_record.rb +24 -14
  46. data/lib/gettext/parser/ruby.rb +4 -63
  47. data/lib/gettext/rails.rb +23 -20
  48. data/lib/gettext/rgettext.rb +6 -6
  49. data/lib/gettext/utils.rb +12 -6
  50. data/lib/gettext/version.rb +2 -2
  51. data/po/ca/rails.po +121 -0
  52. data/po/ca/rgettext.po +130 -0
  53. data/po/cs/rails.po +30 -26
  54. data/po/cs/rgettext.po +44 -36
  55. data/po/de/rails.po +28 -24
  56. data/po/de/rgettext.po +43 -35
  57. data/po/el/rails.po +38 -34
  58. data/po/el/rgettext.po +54 -46
  59. data/po/eo/rails.po +121 -0
  60. data/po/eo/rgettext.po +127 -0
  61. data/po/es/rails.po +28 -24
  62. data/po/es/rgettext.po +45 -37
  63. data/po/et/rails.po +28 -24
  64. data/po/fr/rails.po +39 -33
  65. data/po/fr/rgettext.po +43 -35
  66. data/po/it/rails.po +28 -24
  67. data/po/it/rgettext.po +43 -35
  68. data/po/ja/rails.po +30 -26
  69. data/po/ja/rgettext.po +44 -36
  70. data/po/ko/rails.po +36 -32
  71. data/po/ko/rgettext.po +43 -35
  72. data/po/nl/rails.po +32 -28
  73. data/po/nl/rgettext.po +46 -38
  74. data/po/pt_BR/rails.po +36 -31
  75. data/po/pt_BR/rgettext.po +45 -37
  76. data/po/rails.pot +28 -24
  77. data/po/rgettext.pot +39 -31
  78. data/po/ru/rails.po +36 -30
  79. data/po/ru/rgettext.po +50 -41
  80. data/po/sv/rgettext.po +40 -32
  81. data/po/zh/rails.po +29 -24
  82. data/po/zh/rgettext.po +46 -36
  83. data/po/zh_TW/rails.po +29 -24
  84. data/po/zh_TW/rgettext.po +45 -36
  85. data/samples/cgi/locale/ca/LC_MESSAGES/helloerb1.mo +0 -0
  86. data/samples/cgi/locale/ca/LC_MESSAGES/helloerb2.mo +0 -0
  87. data/samples/cgi/locale/ca/LC_MESSAGES/hellolib.mo +0 -0
  88. data/samples/cgi/locale/ca/LC_MESSAGES/main.mo +0 -0
  89. data/samples/cgi/locale/eo/LC_MESSAGES/helloerb1.mo +0 -0
  90. data/samples/cgi/locale/eo/LC_MESSAGES/helloerb2.mo +0 -0
  91. data/samples/cgi/locale/eo/LC_MESSAGES/hellolib.mo +0 -0
  92. data/samples/cgi/locale/eo/LC_MESSAGES/main.mo +0 -0
  93. data/samples/cgi/po/ca/helloerb1.po +59 -0
  94. data/samples/cgi/po/ca/helloerb2.po +51 -0
  95. data/samples/cgi/po/ca/hellolib.po +23 -0
  96. data/samples/cgi/po/ca/main.po +83 -0
  97. data/samples/cgi/po/eo/helloerb1.po +60 -0
  98. data/samples/cgi/po/eo/helloerb2.po +52 -0
  99. data/samples/cgi/po/eo/hellolib.po +24 -0
  100. data/samples/cgi/po/eo/main.po +84 -0
  101. data/samples/locale/ca/LC_MESSAGES/hello.mo +0 -0
  102. data/samples/locale/ca/LC_MESSAGES/hello2.mo +0 -0
  103. data/samples/locale/ca/LC_MESSAGES/hello_noop.mo +0 -0
  104. data/samples/locale/ca/LC_MESSAGES/hello_plural.mo +0 -0
  105. data/samples/locale/ca/LC_MESSAGES/helloglade2.mo +0 -0
  106. data/samples/locale/ca/LC_MESSAGES/hellogtk.mo +0 -0
  107. data/samples/locale/ca/LC_MESSAGES/hellotk.mo +0 -0
  108. data/samples/locale/eo/LC_MESSAGES/hello.mo +0 -0
  109. data/samples/locale/eo/LC_MESSAGES/hello2.mo +0 -0
  110. data/samples/locale/eo/LC_MESSAGES/hello_noop.mo +0 -0
  111. data/samples/locale/eo/LC_MESSAGES/hello_plural.mo +0 -0
  112. data/samples/locale/eo/LC_MESSAGES/helloglade2.mo +0 -0
  113. data/samples/locale/eo/LC_MESSAGES/hellogtk.mo +0 -0
  114. data/samples/locale/eo/LC_MESSAGES/hellotk.mo +0 -0
  115. data/samples/po/ca/hello.po +23 -0
  116. data/samples/po/ca/hello2.po +31 -0
  117. data/samples/po/ca/hello_noop.po +27 -0
  118. data/samples/po/ca/hello_plural.po +25 -0
  119. data/samples/po/ca/helloglade2.po +31 -0
  120. data/samples/po/ca/hellogtk.po +23 -0
  121. data/samples/po/ca/hellotk.po +23 -0
  122. data/samples/po/eo/hello.po +23 -0
  123. data/samples/po/eo/hello2.po +31 -0
  124. data/samples/po/eo/hello_noop.po +27 -0
  125. data/samples/po/eo/hello_plural.po +26 -0
  126. data/samples/po/eo/helloglade2.po +32 -0
  127. data/samples/po/eo/hellogtk.po +23 -0
  128. data/samples/po/eo/hellotk.po +24 -0
  129. data/samples/rails/app/views/blog/list.rhtml +0 -1
  130. data/samples/rails/config/environment.rb +2 -0
  131. data/samples/rails/db/schema.rb +0 -79
  132. data/samples/rails/lib/tasks/gettext.rake +2 -1
  133. data/samples/rails/locale/ca/LC_MESSAGES/blog.mo +0 -0
  134. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  135. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  136. data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
  137. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  138. data/samples/rails/locale/eo/LC_MESSAGES/blog.mo +0 -0
  139. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  140. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  141. data/samples/rails/locale/it/LC_MESSAGES/blog.mo +0 -0
  142. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  143. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  144. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  145. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  146. data/samples/rails/locale/ru/LC_MESSAGES/blog.mo +0 -0
  147. data/samples/rails/locale/zh/LC_MESSAGES/blog.mo +0 -0
  148. data/samples/rails/locale/zh_TW/LC_MESSAGES/blog.mo +0 -0
  149. data/samples/rails/po/blog.pot +106 -106
  150. data/samples/rails/po/ca/blog.po +105 -0
  151. data/samples/rails/po/cs/blog.po +107 -110
  152. data/samples/rails/po/de/blog.po +107 -107
  153. data/samples/rails/po/el/blog.po +105 -105
  154. data/samples/rails/po/en/blog.po +107 -107
  155. data/samples/rails/po/eo/blog.po +106 -0
  156. data/samples/rails/po/es/blog.po +105 -105
  157. data/samples/rails/po/fr/blog.po +105 -105
  158. data/samples/rails/po/it/blog.po +105 -105
  159. data/samples/rails/po/ja/blog.po +105 -105
  160. data/samples/rails/po/ko/blog.po +105 -105
  161. data/samples/rails/po/nl/blog.po +105 -105
  162. data/samples/rails/po/pt_BR/blog.po +105 -105
  163. data/samples/rails/po/ru/blog.po +105 -105
  164. data/samples/rails/po/zh/blog.po +105 -105
  165. data/samples/rails/po/zh_TW/blog.po +107 -107
  166. data/samples/rails/vendor/plugins/gettext/locale/ca/LC_MESSAGES/gettext_plugin.mo +0 -0
  167. data/samples/rails/vendor/plugins/gettext/po/ca/gettext_plugin.po +27 -0
  168. data/test/README +6 -0
  169. data/test/Rakefile +1 -1
  170. data/test/fixtures/book.rb +3 -0
  171. data/test/fixtures/user.rb +3 -0
  172. data/test/gettext_test_active_record.rb +347 -67
  173. data/test/gettext_test_cgi.rb +27 -2
  174. data/test/gettext_test_parser.rb +102 -4
  175. data/test/gettext_test_rails.rb +6 -1
  176. data/test/locale/ja/LC_MESSAGES/active_record.mo +0 -0
  177. data/test/po/ja/active_record.po +17 -17
  178. data/test/test.sh +1 -0
  179. data/test/test_rubyparser.rb +6 -4
  180. metadata +92 -3
@@ -1,12 +1,12 @@
1
1
  =begin
2
2
  gettext/active_record.rb - GetText for ActiveRecord
3
3
 
4
- Copyright (C) 2006 Masao Mutoh
4
+ Copyright (C) 2006,2007 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.9 2006/09/10 15:08:32 mutoh Exp $
9
+ $Id: active_record.rb,v 1.14 2007/01/21 15:16:06 mutoh Exp $
10
10
  =end
11
11
  require 'gettext'
12
12
  require 'active_record'
@@ -16,6 +16,19 @@ module ActiveRecord #:nodoc:
16
16
  extend GetText
17
17
  include GetText
18
18
  end
19
+
20
+ class RecordInvalid < ActiveRecordError #:nodoc:
21
+ attr_reader :record
22
+ include GetText
23
+ bindtextdomain("rails")
24
+
25
+ def initialize(record)
26
+ @record = record
27
+ super(_("Validation failed: %{error_messages}") %
28
+ {:error_messages => @record.errors.full_messages.join(", ")})
29
+ end
30
+ end
31
+
19
32
 
20
33
  module ConnectionAdapters #:nodoc:
21
34
  # An abstract definition of a column in a table.
@@ -46,12 +59,13 @@ module ActiveRecord #:nodoc:
46
59
  end
47
60
  }
48
61
  end
49
- if ActiveRecord::VERSION::STRING >= "1.14.5"
62
+ if respond_to? :included
50
63
  def self.included(base) # :nodoc:
51
64
  super
52
65
  real_included(base)
53
66
  end
54
67
  else
68
+ # Since rails-1.2.0.
55
69
  def self.append_features(base) # :nodoc:
56
70
  super
57
71
  real_included(base)
@@ -61,7 +75,7 @@ end
61
75
  module ClassMethods #:nodoc:
62
76
  @@custom_error_messages_d = {}
63
77
  # Very ugly but...
64
- def validates_length_of(*attrs) #:nodoc:
78
+ def validates_length_of_with_gettext(*attrs) #:nodoc:
65
79
  if attrs.last.is_a?(Hash)
66
80
  msg = attrs.last[:message] || attrs.last[:too_long] || attrs.last[:too_short] || attrs.last[:wrong_length]
67
81
  if msg
@@ -70,6 +84,8 @@ end
70
84
  end
71
85
  validates_size_of(*attrs)
72
86
  end
87
+ alias_method_chain :validates_length_of, :gettext
88
+
73
89
  def custom_error_messages_d #:nodoc:
74
90
  @@custom_error_messages_d
75
91
  end
@@ -86,88 +102,90 @@ end
86
102
  @@gettext_untranslate = Hash.new(false)
87
103
  @@gettext_untranslate_columns = {}
88
104
 
89
- # Untranslate all of the tablename/fieldnames in this model class.
90
- def self.untranslate_all
91
- @@gettext_untranslate[self] = true
92
- end
93
-
94
- # Returns true if "untranslate_all" is called. Otherwise false.
95
- def self.untranslate_all?
96
- @@gettext_untranslate[self]
97
- end
98
-
99
- # Sets the untranslate columns.
100
- # (e.g.) untranslate :foo, :bar, :baz
101
- def self.untranslate(*w)
102
- ary = @@gettext_untranslate_columns[self] || []
103
- ary += w.collect{|v| v.to_s}
104
- @@gettext_untranslate_columns[self] = ary
105
- end
105
+ class << self
106
+ # Untranslate all of the tablename/fieldnames in this model class.
107
+ def untranslate_all
108
+ @@gettext_untranslate[self] = true
109
+ end
106
110
 
107
- # Returns true if the column is set "untranslate".
108
- # (e.g.) untranslate? :foo
109
- def self.untranslate?(columnname)
110
- ary = @@gettext_untranslate_columns[self] || []
111
- ary.include?(columnname)
112
- end
111
+ # Returns true if "untranslate_all" is called. Otherwise false.
112
+ def untranslate_all?
113
+ @@gettext_untranslate[self]
114
+ end
113
115
 
114
- def self.untranslate_data #:nodoc:
115
- [@@gettext_untranslate[self], @@gettext_untranslate_columns[self] || []]
116
- end
116
+ # Sets the untranslate columns.
117
+ # (e.g.) untranslate :foo, :bar, :baz
118
+ def untranslate(*w)
119
+ ary = @@gettext_untranslate_columns[self] || []
120
+ ary += w.collect{|v| v.to_s}
121
+ @@gettext_untranslate_columns[self] = ary
122
+ end
123
+
124
+ # Returns true if the column is set "untranslate".
125
+ # (e.g.) untranslate? :foo
126
+ def untranslate?(columnname)
127
+ ary = @@gettext_untranslate_columns[self] || []
128
+ ary.include?(columnname)
129
+ end
117
130
 
118
- def self.columns
119
- unless defined? @columns
120
- @columns = nil
131
+ def untranslate_data #:nodoc:
132
+ [@@gettext_untranslate[self], @@gettext_untranslate_columns[self] || []]
121
133
  end
122
- unless @columns
123
- @columns = connection.columns(table_name, "#{name} Columns")
124
- @columns.each {|column|
125
- column.table_class = self
126
- column.primary = column.name == primary_key
127
- }
134
+
135
+ def columns_with_gettext
136
+ unless defined? @columns
137
+ @columns = nil
138
+ end
139
+ unless @columns
140
+ @columns = connection.columns(table_name, "#{name} Columns")
141
+ @columns.each {|column|
142
+ column.table_class = self
143
+ column.primary = column.name == primary_key
144
+ }
145
+ end
146
+ @columns
128
147
  end
129
- @columns
130
- end
148
+ alias_method_chain :columns, :gettext
131
149
 
132
- # call-seq:
133
- # set_error_message_title(msg)
134
- #
135
- # ((*Deprecated*))
136
- # Use ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title
137
- # instead.
138
- #
139
- # Sets a your own title of error message dialog.
140
- # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
141
- # * Returns: [single_msg, plural_msg]
142
- def self.set_error_message_title(msg, plural_msg = nil)
143
- ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title(msg, plural_msg)
144
- end
145
-
146
- # call-seq:
147
- # set_error_message_explanation(msg)
148
- #
149
- # ((*Deprecated*))
150
- # Use ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_explanation
151
- # instead.
152
- #
153
- # Sets a your own explanation of the error message dialog.
154
- # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
155
- # * Returns: [single_msg, plural_msg]
156
- def self.set_error_message_explanation(msg, plural_msg = nil)
157
- ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_explanation(msg, plural_msg)
150
+ # call-seq:
151
+ # set_error_message_title(msg)
152
+ #
153
+ # ((*Deprecated*))
154
+ # Use ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title
155
+ # instead.
156
+ #
157
+ # Sets a your own title of error message dialog.
158
+ # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
159
+ # * Returns: [single_msg, plural_msg]
160
+ def set_error_message_title(msg, plural_msg = nil)
161
+ ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title(msg, plural_msg)
162
+ end
163
+
164
+ # call-seq:
165
+ # set_error_message_explanation(msg)
166
+ #
167
+ # ((*Deprecated*))
168
+ # Use ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_explanation
169
+ # instead.
170
+ #
171
+ # Sets a your own explanation of the error message dialog.
172
+ # * msg: [single_msg, plural_msg]. Usually you need to call this with Nn_().
173
+ # * Returns: [single_msg, plural_msg]
174
+ def set_error_message_explanation(msg, plural_msg = nil)
175
+ ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_explanation(msg, plural_msg)
176
+ end
158
177
  end
159
178
  end
160
-
179
+
161
180
  # activerecord-1.14.3/lib/active_record/validations.rb
162
181
  class Errors #:nodoc:
163
182
  include GetText
164
- alias initialize_without_locale initialize #:nodoc:
165
- alias full_messages_without_localized full_messages #:nodoc:
166
183
 
167
- def initialize(base) # :nodoc:
168
- initialize_without_locale(base)
184
+ def initialize_with_gettext(base) # :nodoc:
185
+ initialize_without_gettext(base)
169
186
  bindtextdomain("rails")
170
187
  end
188
+ alias_method_chain :initialize, :gettext
171
189
 
172
190
  def @@default_error_messages.[]=(id, msg) #:nodoc:
173
191
  @@default_error_messages.update({id => msg})
@@ -198,40 +216,42 @@ end
198
216
  }
199
217
  cattr_accessor :default_error_messages_d
200
218
 
219
+ def localize_error_message(attr, msg, append_field) # :nodoc:
220
+ custom_msg = nil
221
+ #Ugly but... :-<
222
+ @@default_error_messages_d.dup.merge(@base.custom_error_messages_d).each do |key, regexp|
223
+ if regexp =~ msg
224
+ custom_msg = @base.gettext(key)
225
+ custom_msg = _(msg) if custom_msg == msg
226
+ custom_msg = _(custom_msg) % $1.to_i
227
+ break
228
+ end
229
+ end
230
+
231
+ unless custom_msg
232
+ custom_msg = @base.gettext(msg)
233
+ custom_msg = _(msg) if custom_msg == msg
234
+ end
235
+ if attr == "base"
236
+ full_message = custom_msg
237
+ elsif /%\{fn\}/ =~ custom_msg
238
+ full_message = custom_msg % {:fn => @base.class.human_attribute_name(attr)}
239
+ elsif append_field
240
+ full_message = @base.class.human_attribute_name(attr) + " " + custom_msg
241
+ else
242
+ full_message = custom_msg
243
+ end
244
+ full_message
245
+ end
246
+
201
247
  def localize_error_messages(append_field = true) # :nodoc:
202
248
  # e.g.) foo field: "%{fn} foo" => "Foo foo", "foo" => "Foo foo".
203
249
  errors = {}
204
- @errors.each_key do |attr|
205
- @errors[attr].each do |msg|
206
- next if msg.nil?
207
- custom_msg = nil
208
- #Ugly but... :-<
209
- @@default_error_messages_d.dup.merge(@base.custom_error_messages_d).each do |key, regexp|
210
- if regexp =~ msg
211
- custom_msg = @base.gettext(key)
212
- custom_msg = _(msg) if custom_msg == msg
213
- custom_msg = _(custom_msg) % $1.to_i
214
- break
215
- end
216
- end
217
-
218
- unless custom_msg
219
- custom_msg = @base.gettext(msg)
220
- custom_msg = _(msg) if custom_msg == msg
221
- end
222
- if attr == "base"
223
- full_message = custom_msg
224
- elsif /%\{fn\}/ =~ custom_msg
225
- full_message = custom_msg % {:fn => @base.class.human_attribute_name(attr)}
226
- elsif append_field
227
- full_message = @base.class.human_attribute_name(attr) + " " + custom_msg
228
- else
229
- full_message = custom_msg
230
- end
231
- errors[attr] ||= []
232
- errors[attr] << full_message
233
- end
234
- end
250
+ each {|attr, msg|
251
+ next if msg.nil?
252
+ errors[attr] ||= []
253
+ errors[attr] << localize_error_message(attr, msg, append_field)
254
+ }
235
255
  errors
236
256
  end
237
257
 
@@ -243,23 +263,19 @@ end
243
263
  # * If the error messages include %{fn}, it returns formatted text such as "foo %{fn}" => "foo Field"
244
264
  # * else, the error messages are prepended the field name such as "foo" => "foo" (Same as default behavior).
245
265
  # Note that this behaviour is different from full_messages.
246
- def on(attribute)
266
+ def on_with_gettext(attribute)
247
267
  # e.g.) foo field: "%{fn} foo" => "Foo foo", "foo" => "foo".
248
- errors = localize_error_messages(false)
249
- if errors[attribute.to_s].nil?
250
- nil
251
- elsif errors[attribute.to_s].length == 1
252
- errors[attribute.to_s].first
253
- else
254
- errors[attribute.to_s]
255
- end
268
+ errors = localize_error_messages(false)[attribute.to_s]
269
+ return nil if errors.nil?
270
+ errors.size == 1 ? errors.first : errors
256
271
  end
272
+ alias_method_chain :on, :gettext
257
273
 
258
274
  # Returns all the full error messages in an array.
259
275
  # * If the error messages include %{fn}, it returns formatted text such as "foo %{fn}" => "foo Field"
260
276
  # * else, the error messages are prepended the field name such as "foo" => "Field foo" (Same as default behavior).
261
277
  # As L10n, first one is recommanded because the order of subject,verb and others are not same in languages.
262
- def full_messages
278
+ def full_messages_with_gettext
263
279
  full_messages = []
264
280
  errors = localize_error_messages
265
281
  errors.each_key do |attr|
@@ -270,6 +286,7 @@ end
270
286
  end
271
287
  full_messages
272
288
  end
289
+ alias_method_chain :full_messages, :gettext
273
290
  end
274
291
  end
275
292
 
data/lib/gettext/erb.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: erb.rb,v 1.3 2006/06/04 14:43:37 mutoh Exp $
9
+ $Id: erb.rb,v 1.4 2006/12/06 16:39:58 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'erb'
@@ -34,7 +34,7 @@ module GetText
34
34
  # This module is an example for template engines such as ERB.
35
35
  # You can implement another implementation easily to read gettext/erb.rb.
36
36
  module ErbContainer
37
- include Container
37
+ include GetText
38
38
 
39
39
  # Evaluates ERB source(String) in the instance and returns the result HTML.
40
40
  #
@@ -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.12 2006/08/17 17:24:18 mutoh Exp $
9
+ $Id: locale.rb,v 1.13 2006/12/03 16:26:59 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'gettext/locale_object'
@@ -56,14 +56,20 @@ module Locale
56
56
  @@current = nil
57
57
 
58
58
  module_function
59
- # Sets the default locale (Locale::Object).
59
+ # Sets the default locale (Locale::Object or String(such as ja_JP.eucjP)).
60
60
  #
61
61
  # * locale: the default locale
62
62
  # * Returns: self.
63
63
  def set_default(locale)
64
- @@default = locale
65
- if @@default
66
- @@default.charset ||= @@locale_system_module.get_charset(locale)
64
+ if locale
65
+ if locale.kind_of? Locale::Object
66
+ @@default = locale
67
+ else
68
+ @@default = Locale::Object.new(locale)
69
+ end
70
+ @@default.charset ||= @@locale_system_module.get_charset(@@default)
71
+ else
72
+ @@default = nil
67
73
  end
68
74
  self
69
75
  end
@@ -6,13 +6,13 @@
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.6 2006/09/10 15:08:32 mutoh Exp $
9
+ $Id: locale_cgi.rb,v 1.7 2006/12/14 16:35:57 mutoh Exp $
10
10
  =end
11
11
 
12
12
 
13
13
  module Locale
14
- # Locale::System module for Default OS (Unix)
15
- # This is low-level class. Application shouldn't use this directly.
14
+ # Locale::System module for CGI.
15
+ # This is a low-level class. Application shouldn't use this directly.
16
16
  module SystemCGI
17
17
  @@default_locale = Locale::Object.new("en", nil, "UTF-8")
18
18
  @@cgi = nil
@@ -6,13 +6,13 @@
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.4 2006/06/11 15:36:20 mutoh Exp $
9
+ $Id: locale_posix.rb,v 1.5 2006/12/14 16:35:57 mutoh Exp $
10
10
  =end
11
11
 
12
12
 
13
13
  module Locale
14
14
  # Locale::SystemPosix module for Posix OS (Unix)
15
- # This is low-level class. Application shouldn't use this directly.
15
+ # This is a low-level class. Application shouldn't use this directly.
16
16
  module SystemPosix
17
17
  extend Locale::System
18
18
  module_function
@@ -6,13 +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_win32.rb,v 1.14 2006/06/11 15:36:20 mutoh Exp $
9
+ $Id: locale_win32.rb,v 1.15 2006/12/14 16:35:57 mutoh Exp $
10
10
  =end
11
11
 
12
12
  require 'gettext/locale_table_win32'
13
13
 
14
14
  module Locale
15
15
  # Locale::SystemWin32 module for win32.
16
+ # This is a low-level class. Application shouldn't use this directly.
16
17
  module SystemWin32
17
18
  extend Locale::System
18
19
 
@@ -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.2 2006/08/28 23:54:53 mutoh Exp $
10
+ $Id: active_record.rb,v 1.5 2007/01/21 15:16:06 mutoh Exp $
11
11
  =end
12
12
 
13
13
  require 'gettext'
@@ -72,16 +72,17 @@ module GetText
72
72
  end
73
73
 
74
74
  def parse(file, targets = []) # :nodoc:
75
- old_constants = constants
75
+ GetText.locale = "en"
76
+ old_constants = Object.constants
76
77
  begin
77
- eval(open(file).read)
78
+ eval(open(file).read, TOPLEVEL_BINDING)
78
79
  rescue
79
80
  $stderr.puts _("Ignored '%{file}'. Solve dependencies first.") % {:file => file}
80
81
  $stderr.puts $!
81
82
  end
82
- loaded_constants = constants - old_constants
83
+ loaded_constants = Object.constants - old_constants
83
84
  loaded_constants.each do |classname|
84
- klass = eval(classname)
85
+ klass = eval(classname, TOPLEVEL_BINDING)
85
86
  if klass.is_a?(Class) && klass < ActiveRecord::Base
86
87
  unless klass.untranslate_all?
87
88
  add_target(targets, file, ::Inflector.singularize(klass.table_name.gsub(/_/, " ")))
@@ -114,9 +115,10 @@ module GetText
114
115
  end
115
116
 
116
117
  def add_target(targets, file, msgid) # :nodoc:
118
+ file_lineno = "#{file}:-"
117
119
  key_existed = targets.assoc(msgid)
118
- if key_existed
119
- targets[targets.index(key_existed)] = key_existed << "#{file}:-"
120
+ if key_existed and ! targets[targets.index(key_existed)].include?(file_lineno)
121
+ targets[targets.index(key_existed)] = key_existed << file_lineno
120
122
  else
121
123
  targets << [msgid, "#{file}:-"]
122
124
  end
@@ -132,12 +134,24 @@ module GetText
132
134
  unless @@db_loaded
133
135
  begin
134
136
  require 'rubygems'
135
- require_gem 'activerecord'
136
137
  rescue LoadError
137
138
  $stderr.puts _("rubygems are not found.") if $DEBUG
138
139
  end
139
- require 'active_record'
140
- require 'gettext/active_record'
140
+ begin
141
+ ENV["RAILS_ENV"] = @config[:db_mode]
142
+ require 'config/boot.rb'
143
+ require 'config/environment.rb'
144
+ require 'app/controllers/application.rb'
145
+ rescue LoadError
146
+ require_rails 'rubygems'
147
+ if Kernel.respond_to? :gem
148
+ gem 'activerecord'
149
+ else
150
+ require_gem 'activerecord'
151
+ end
152
+ require_rails 'active_record'
153
+ require_rails 'gettext/active_record'
154
+ end
141
155
  if @config[:adapter]
142
156
  ActiveRecord::Base.establish_connection(@config)
143
157
  else
@@ -146,10 +160,6 @@ module GetText
146
160
  rescue
147
161
  return false
148
162
  end
149
- ENV["RAILS_ENV"] = @config[:db_mode]
150
- require_rails 'config/boot.rb'
151
- require_rails 'config/environment.rb'
152
- require_rails 'app/controllers/application.rb'
153
163
  end
154
164
  end
155
165
  @@db_loaded = true