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.
- data/ChangeLog +120 -0
- data/NEWS +16 -0
- data/README +27 -19
- data/data/locale/ca/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/cs/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/eo/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/es/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/et/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/it/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ru/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh_TW/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
- data/ext/gettext/Makefile +22 -19
- data/ext/gettext/mkmf.log +3 -9
- data/lib/gettext.rb +13 -10
- data/lib/gettext/active_record.rb +130 -113
- data/lib/gettext/erb.rb +2 -2
- data/lib/gettext/locale.rb +11 -5
- data/lib/gettext/locale_cgi.rb +3 -3
- data/lib/gettext/locale_posix.rb +2 -2
- data/lib/gettext/locale_win32.rb +2 -1
- data/lib/gettext/parser/active_record.rb +24 -14
- data/lib/gettext/parser/ruby.rb +4 -63
- data/lib/gettext/rails.rb +23 -20
- data/lib/gettext/rgettext.rb +6 -6
- data/lib/gettext/utils.rb +12 -6
- data/lib/gettext/version.rb +2 -2
- data/po/ca/rails.po +121 -0
- data/po/ca/rgettext.po +130 -0
- data/po/cs/rails.po +30 -26
- data/po/cs/rgettext.po +44 -36
- data/po/de/rails.po +28 -24
- data/po/de/rgettext.po +43 -35
- data/po/el/rails.po +38 -34
- data/po/el/rgettext.po +54 -46
- data/po/eo/rails.po +121 -0
- data/po/eo/rgettext.po +127 -0
- data/po/es/rails.po +28 -24
- data/po/es/rgettext.po +45 -37
- data/po/et/rails.po +28 -24
- data/po/fr/rails.po +39 -33
- data/po/fr/rgettext.po +43 -35
- data/po/it/rails.po +28 -24
- data/po/it/rgettext.po +43 -35
- data/po/ja/rails.po +30 -26
- data/po/ja/rgettext.po +44 -36
- data/po/ko/rails.po +36 -32
- data/po/ko/rgettext.po +43 -35
- data/po/nl/rails.po +32 -28
- data/po/nl/rgettext.po +46 -38
- data/po/pt_BR/rails.po +36 -31
- data/po/pt_BR/rgettext.po +45 -37
- data/po/rails.pot +28 -24
- data/po/rgettext.pot +39 -31
- data/po/ru/rails.po +36 -30
- data/po/ru/rgettext.po +50 -41
- data/po/sv/rgettext.po +40 -32
- data/po/zh/rails.po +29 -24
- data/po/zh/rgettext.po +46 -36
- data/po/zh_TW/rails.po +29 -24
- data/po/zh_TW/rgettext.po +45 -36
- data/samples/cgi/locale/ca/LC_MESSAGES/helloerb1.mo +0 -0
- data/samples/cgi/locale/ca/LC_MESSAGES/helloerb2.mo +0 -0
- data/samples/cgi/locale/ca/LC_MESSAGES/hellolib.mo +0 -0
- data/samples/cgi/locale/ca/LC_MESSAGES/main.mo +0 -0
- data/samples/cgi/locale/eo/LC_MESSAGES/helloerb1.mo +0 -0
- data/samples/cgi/locale/eo/LC_MESSAGES/helloerb2.mo +0 -0
- data/samples/cgi/locale/eo/LC_MESSAGES/hellolib.mo +0 -0
- data/samples/cgi/locale/eo/LC_MESSAGES/main.mo +0 -0
- data/samples/cgi/po/ca/helloerb1.po +59 -0
- data/samples/cgi/po/ca/helloerb2.po +51 -0
- data/samples/cgi/po/ca/hellolib.po +23 -0
- data/samples/cgi/po/ca/main.po +83 -0
- data/samples/cgi/po/eo/helloerb1.po +60 -0
- data/samples/cgi/po/eo/helloerb2.po +52 -0
- data/samples/cgi/po/eo/hellolib.po +24 -0
- data/samples/cgi/po/eo/main.po +84 -0
- data/samples/locale/ca/LC_MESSAGES/hello.mo +0 -0
- data/samples/locale/ca/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/ca/LC_MESSAGES/hello_noop.mo +0 -0
- data/samples/locale/ca/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/ca/LC_MESSAGES/helloglade2.mo +0 -0
- data/samples/locale/ca/LC_MESSAGES/hellogtk.mo +0 -0
- data/samples/locale/ca/LC_MESSAGES/hellotk.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/hello.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/hello_noop.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/helloglade2.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/hellogtk.mo +0 -0
- data/samples/locale/eo/LC_MESSAGES/hellotk.mo +0 -0
- data/samples/po/ca/hello.po +23 -0
- data/samples/po/ca/hello2.po +31 -0
- data/samples/po/ca/hello_noop.po +27 -0
- data/samples/po/ca/hello_plural.po +25 -0
- data/samples/po/ca/helloglade2.po +31 -0
- data/samples/po/ca/hellogtk.po +23 -0
- data/samples/po/ca/hellotk.po +23 -0
- data/samples/po/eo/hello.po +23 -0
- data/samples/po/eo/hello2.po +31 -0
- data/samples/po/eo/hello_noop.po +27 -0
- data/samples/po/eo/hello_plural.po +26 -0
- data/samples/po/eo/helloglade2.po +32 -0
- data/samples/po/eo/hellogtk.po +23 -0
- data/samples/po/eo/hellotk.po +24 -0
- data/samples/rails/app/views/blog/list.rhtml +0 -1
- data/samples/rails/config/environment.rb +2 -0
- data/samples/rails/db/schema.rb +0 -79
- data/samples/rails/lib/tasks/gettext.rake +2 -1
- data/samples/rails/locale/ca/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/eo/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/it/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/ru/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/zh/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/zh_TW/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/po/blog.pot +106 -106
- data/samples/rails/po/ca/blog.po +105 -0
- data/samples/rails/po/cs/blog.po +107 -110
- data/samples/rails/po/de/blog.po +107 -107
- data/samples/rails/po/el/blog.po +105 -105
- data/samples/rails/po/en/blog.po +107 -107
- data/samples/rails/po/eo/blog.po +106 -0
- data/samples/rails/po/es/blog.po +105 -105
- data/samples/rails/po/fr/blog.po +105 -105
- data/samples/rails/po/it/blog.po +105 -105
- data/samples/rails/po/ja/blog.po +105 -105
- data/samples/rails/po/ko/blog.po +105 -105
- data/samples/rails/po/nl/blog.po +105 -105
- data/samples/rails/po/pt_BR/blog.po +105 -105
- data/samples/rails/po/ru/blog.po +105 -105
- data/samples/rails/po/zh/blog.po +105 -105
- data/samples/rails/po/zh_TW/blog.po +107 -107
- data/samples/rails/vendor/plugins/gettext/locale/ca/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/vendor/plugins/gettext/po/ca/gettext_plugin.po +27 -0
- data/test/README +6 -0
- data/test/Rakefile +1 -1
- data/test/fixtures/book.rb +3 -0
- data/test/fixtures/user.rb +3 -0
- data/test/gettext_test_active_record.rb +347 -67
- data/test/gettext_test_cgi.rb +27 -2
- data/test/gettext_test_parser.rb +102 -4
- data/test/gettext_test_rails.rb +6 -1
- data/test/locale/ja/LC_MESSAGES/active_record.mo +0 -0
- data/test/po/ja/active_record.po +17 -17
- data/test/test.sh +1 -0
- data/test/test_rubyparser.rb +6 -4
- 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
|
+
$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
|
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
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
119
|
-
|
120
|
-
@columns = nil
|
131
|
+
def untranslate_data #:nodoc:
|
132
|
+
[@@gettext_untranslate[self], @@gettext_untranslate_columns[self] || []]
|
121
133
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
130
|
-
end
|
148
|
+
alias_method_chain :columns, :gettext
|
131
149
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
168
|
-
|
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
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
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
|
250
|
-
|
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
|
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.
|
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
|
37
|
+
include GetText
|
38
38
|
|
39
39
|
# Evaluates ERB source(String) in the instance and returns the result HTML.
|
40
40
|
#
|
data/lib/gettext/locale.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: locale.rb,v 1.
|
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
|
-
|
65
|
-
|
66
|
-
|
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
|
data/lib/gettext/locale_cgi.rb
CHANGED
@@ -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.
|
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
|
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
|
data/lib/gettext/locale_posix.rb
CHANGED
@@ -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.
|
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
|
data/lib/gettext/locale_win32.rb
CHANGED
@@ -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.
|
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.
|
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
|
-
|
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 <<
|
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
|
-
|
140
|
-
|
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
|