gettext 1.7.0-mswin32 → 1.8.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 +139 -0
- data/NEWS +31 -0
- data/README +31 -15
- data/Rakefile +3 -2
- data/bin/rgettext +1 -1
- data/bin/rmsgfmt +1 -1
- data/bin/rmsgmerge +1 -1
- 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/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/lib/gettext.rb +50 -23
- data/lib/gettext/active_record.rb +275 -0
- data/lib/gettext/locale.rb +9 -2
- data/lib/gettext/locale_cgi.rb +5 -4
- data/lib/gettext/locale_object.rb +5 -4
- data/lib/gettext/parser/{activerecord.rb → active_record.rb} +31 -14
- data/lib/gettext/parser/ruby.rb +48 -44
- data/lib/gettext/rails.rb +111 -253
- data/lib/gettext/rgettext.rb +34 -6
- data/lib/gettext/string.rb +3 -2
- data/lib/gettext/textdomain.rb +3 -3
- data/lib/gettext/version.rb +1 -1
- data/po/cs/rails.po +61 -61
- data/po/cs/rgettext.po +37 -55
- data/po/de/rails.po +73 -72
- data/po/de/rgettext.po +39 -56
- data/po/el/rails.po +60 -60
- data/po/el/rgettext.po +26 -44
- data/po/es/rails.po +60 -60
- data/po/es/rgettext.po +28 -52
- data/po/et/rails.po +118 -0
- data/po/fr/rails.po +60 -60
- data/po/fr/rgettext.po +26 -46
- data/po/it/rails.po +68 -68
- data/po/it/rgettext.po +35 -53
- data/po/ja/rails.po +62 -61
- data/po/ja/rgettext.po +27 -45
- data/po/ko/rails.po +61 -60
- data/po/ko/rgettext.po +34 -54
- data/po/nl/rails.po +59 -60
- data/po/nl/rgettext.po +35 -55
- data/po/pt_BR/rails.po +74 -73
- data/po/pt_BR/rgettext.po +36 -52
- data/po/rails.pot +61 -61
- data/po/rgettext.pot +25 -43
- data/po/ru/rails.po +61 -62
- data/po/ru/rgettext.po +26 -51
- data/po/sv/rgettext.po +27 -44
- data/po/zh/rails.po +62 -60
- data/po/zh/rgettext.po +28 -47
- data/po/zh_TW/rails.po +114 -0
- data/po/zh_TW/rgettext.po +121 -0
- data/samples/cgi/locale/zh_TW/LC_MESSAGES/helloerb1.mo +0 -0
- data/samples/cgi/locale/zh_TW/LC_MESSAGES/helloerb2.mo +0 -0
- data/samples/cgi/locale/zh_TW/LC_MESSAGES/hellolib.mo +0 -0
- data/samples/cgi/locale/zh_TW/LC_MESSAGES/main.mo +0 -0
- data/samples/cgi/po/zh_TW/helloerb1.po +67 -0
- data/samples/cgi/po/zh_TW/helloerb2.po +54 -0
- data/samples/cgi/po/zh_TW/hellolib.po +26 -0
- data/samples/cgi/po/zh_TW/main.po +79 -0
- data/samples/locale/zh_TW/LC_MESSAGES/hello.mo +0 -0
- data/samples/locale/zh_TW/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/zh_TW/LC_MESSAGES/hello_noop.mo +0 -0
- data/samples/locale/zh_TW/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/zh_TW/LC_MESSAGES/helloglade2.mo +0 -0
- data/samples/locale/zh_TW/LC_MESSAGES/hellogtk.mo +0 -0
- data/samples/locale/zh_TW/LC_MESSAGES/hellotk.mo +0 -0
- data/samples/po/hellogtk.pot +1 -1
- data/samples/po/zh_TW/hello.po +26 -0
- data/samples/po/zh_TW/hello2.po +34 -0
- data/samples/po/zh_TW/hello_noop.po +30 -0
- data/samples/po/zh_TW/hello_plural.po +28 -0
- data/samples/po/zh_TW/helloglade2.po +40 -0
- data/samples/po/zh_TW/hellogtk.po +25 -0
- data/samples/po/zh_TW/hellotk.po +26 -0
- data/samples/rails/README +8 -11
- data/samples/rails/app/controllers/application.rb +6 -9
- data/samples/rails/app/views/layouts/blog.rhtml +1 -1
- data/samples/rails/config/database.yml +1 -1
- data/samples/rails/config/environment.rb +1 -0
- data/samples/rails/db/schema.rb +90 -0
- data/samples/rails/lib/tasks/gettext.rake +1 -1
- 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/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 -110
- data/samples/rails/po/cs/blog.po +110 -115
- data/samples/rails/po/de/blog.po +107 -112
- data/samples/rails/po/el/blog.po +105 -109
- data/samples/rails/po/en/blog.po +107 -111
- data/samples/rails/po/es/blog.po +105 -110
- data/samples/rails/po/fr/blog.po +105 -109
- data/samples/rails/po/it/blog.po +105 -109
- data/samples/rails/po/ja/blog.po +105 -109
- data/samples/rails/po/ko/blog.po +105 -109
- data/samples/rails/po/nl/blog.po +105 -110
- data/samples/rails/po/pt_BR/blog.po +105 -109
- data/samples/rails/po/ru/blog.po +105 -107
- data/samples/rails/po/zh/blog.po +105 -109
- data/samples/rails/po/zh_TW/blog.po +107 -0
- data/samples/rails/vendor/plugins/gettext/locale/zh_TW/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/vendor/plugins/gettext/po/zh_TW/gettext_plugin.po +30 -0
- data/test/Rakefile +44 -0
- data/test/fixtures/developer.rb +5 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/reply.rb +40 -0
- data/test/fixtures/topic.rb +23 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/gettext_test.rb +2 -2
- data/test/gettext_test_active_record.rb +1479 -0
- data/test/gettext_test_rails.rb +2 -0
- data/test/locale/ja/LC_MESSAGES/active_record.mo +0 -0
- data/test/po/active_record.pot +295 -0
- data/test/po/ja/active_record.po +294 -0
- data/test/test.sh +1 -0
- data/test/test_rubyparser.rb +10 -2
- metadata +66 -6
- data/samples/rails/db/mysql.sql +0 -8
- data/samples/rails/db/postgresql.sql +0 -7
@@ -0,0 +1,275 @@
|
|
1
|
+
=begin
|
2
|
+
gettext/active_record.rb - GetText for ActiveRecord
|
3
|
+
|
4
|
+
Copyright (C) 2006 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby.
|
8
|
+
|
9
|
+
$Id: active_record.rb,v 1.9 2006/09/10 15:08:32 mutoh Exp $
|
10
|
+
=end
|
11
|
+
require 'gettext'
|
12
|
+
require 'active_record'
|
13
|
+
|
14
|
+
module ActiveRecord #:nodoc:
|
15
|
+
class Migration
|
16
|
+
extend GetText
|
17
|
+
include GetText
|
18
|
+
end
|
19
|
+
|
20
|
+
module ConnectionAdapters #:nodoc:
|
21
|
+
# An abstract definition of a column in a table.
|
22
|
+
class Column
|
23
|
+
attr_accessor :table_class
|
24
|
+
alias :human_name_witout_localized :human_name
|
25
|
+
|
26
|
+
def human_name
|
27
|
+
table_class.human_attribute_name(@name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Validations # :nodoc:
|
33
|
+
def self.real_included(base)
|
34
|
+
base.extend ClassMethods
|
35
|
+
base.class_eval{
|
36
|
+
include GetText
|
37
|
+
def gettext(str) #:nodoc:
|
38
|
+
_(str)
|
39
|
+
end
|
40
|
+
def self.human_attribute_name(attribute_key_name) #:nodoc:
|
41
|
+
s_("#{self}|#{attribute_key_name.humanize}")
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.human_attribute_table_name_for_error(table_name) #:nodoc:
|
45
|
+
_(table_name.gsub(/_/, " "))
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
if ActiveRecord::VERSION::STRING >= "1.14.5"
|
50
|
+
def self.included(base) # :nodoc:
|
51
|
+
super
|
52
|
+
real_included(base)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
def self.append_features(base) # :nodoc:
|
56
|
+
super
|
57
|
+
real_included(base)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
module ClassMethods #:nodoc:
|
62
|
+
@@custom_error_messages_d = {}
|
63
|
+
# Very ugly but...
|
64
|
+
def validates_length_of(*attrs) #:nodoc:
|
65
|
+
if attrs.last.is_a?(Hash)
|
66
|
+
msg = attrs.last[:message] || attrs.last[:too_long] || attrs.last[:too_short] || attrs.last[:wrong_length]
|
67
|
+
if msg
|
68
|
+
@@custom_error_messages_d[msg] = /\A#{Regexp.escape(msg).sub(/%d/, '(\d+)')}\Z/
|
69
|
+
end
|
70
|
+
end
|
71
|
+
validates_size_of(*attrs)
|
72
|
+
end
|
73
|
+
def custom_error_messages_d #:nodoc:
|
74
|
+
@@custom_error_messages_d
|
75
|
+
end
|
76
|
+
end
|
77
|
+
def custom_error_messages_d #:nodoc:
|
78
|
+
self.class.custom_error_messages_d
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class Base
|
83
|
+
include GetText
|
84
|
+
include Validations
|
85
|
+
|
86
|
+
@@gettext_untranslate = Hash.new(false)
|
87
|
+
@@gettext_untranslate_columns = {}
|
88
|
+
|
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
|
106
|
+
|
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
|
113
|
+
|
114
|
+
def self.untranslate_data #:nodoc:
|
115
|
+
[@@gettext_untranslate[self], @@gettext_untranslate_columns[self] || []]
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.columns
|
119
|
+
unless defined? @columns
|
120
|
+
@columns = nil
|
121
|
+
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
|
+
}
|
128
|
+
end
|
129
|
+
@columns
|
130
|
+
end
|
131
|
+
|
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)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# activerecord-1.14.3/lib/active_record/validations.rb
|
162
|
+
class Errors #:nodoc:
|
163
|
+
include GetText
|
164
|
+
alias initialize_without_locale initialize #:nodoc:
|
165
|
+
alias full_messages_without_localized full_messages #:nodoc:
|
166
|
+
|
167
|
+
def initialize(base) # :nodoc:
|
168
|
+
initialize_without_locale(base)
|
169
|
+
bindtextdomain("rails")
|
170
|
+
end
|
171
|
+
|
172
|
+
def @@default_error_messages.[]=(id, msg) #:nodoc:
|
173
|
+
@@default_error_messages.update({id => msg})
|
174
|
+
if [:message, :too_long, :too_short, :wrong_length].include?(id)
|
175
|
+
@@default_error_messages_d[msg] = /\A#{Regexp.escape(msg).sub(/%d/, '(\d+)')}\Z/
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# You need to define this here, because this values will be updated by application.
|
180
|
+
default_error_messages.update(
|
181
|
+
:inclusion => N_("%{fn} is not included in the list"),
|
182
|
+
:exclusion => N_("%{fn} is reserved"),
|
183
|
+
:invalid => N_("%{fn} is invalid"),
|
184
|
+
:confirmation => N_("%{fn} doesn't match confirmation"),
|
185
|
+
:accepted => N_("%{fn} must be accepted"),
|
186
|
+
:empty => N_("%{fn} can't be empty"),
|
187
|
+
:blank => N_("%{fn} can't be blank"),
|
188
|
+
:too_long => N_("%{fn} is too long (maximum is %d characters)"),
|
189
|
+
:too_short => N_("%{fn} is too short (minimum is %d characters)"),
|
190
|
+
:wrong_length => N_("%{fn} is the wrong length (should be %d characters)"),
|
191
|
+
:taken => N_("%{fn} has already been taken"),
|
192
|
+
:not_a_number => N_("%{fn} is not a number")
|
193
|
+
)
|
194
|
+
@@default_error_messages_d = {
|
195
|
+
default_error_messages[:too_long] => /#{Regexp.escape(default_error_messages[:too_long]).sub(/%d/, '(\d+)')}/,
|
196
|
+
default_error_messages[:too_short] => /#{Regexp.escape(default_error_messages[:too_short]).sub(/%d/, '(\d+)')}/,
|
197
|
+
default_error_messages[:wrong_length] => /#{Regexp.escape(default_error_messages[:wrong_length]).sub(/%d/, '(\d+)')}/,
|
198
|
+
}
|
199
|
+
cattr_accessor :default_error_messages_d
|
200
|
+
|
201
|
+
def localize_error_messages(append_field = true) # :nodoc:
|
202
|
+
# e.g.) foo field: "%{fn} foo" => "Foo foo", "foo" => "Foo foo".
|
203
|
+
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
|
235
|
+
errors
|
236
|
+
end
|
237
|
+
|
238
|
+
# Returns error messages.
|
239
|
+
# * Returns nil, if no errors are associated with the specified attribute.
|
240
|
+
# * Returns the error message, if one error is associated with the specified attribute.
|
241
|
+
# * Returns an array of error messages, if more than one error is associated with the specified attribute.
|
242
|
+
# And for GetText,
|
243
|
+
# * If the error messages include %{fn}, it returns formatted text such as "foo %{fn}" => "foo Field"
|
244
|
+
# * else, the error messages are prepended the field name such as "foo" => "foo" (Same as default behavior).
|
245
|
+
# Note that this behaviour is different from full_messages.
|
246
|
+
def on(attribute)
|
247
|
+
# 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
|
256
|
+
end
|
257
|
+
|
258
|
+
# Returns all the full error messages in an array.
|
259
|
+
# * If the error messages include %{fn}, it returns formatted text such as "foo %{fn}" => "foo Field"
|
260
|
+
# * else, the error messages are prepended the field name such as "foo" => "Field foo" (Same as default behavior).
|
261
|
+
# As L10n, first one is recommanded because the order of subject,verb and others are not same in languages.
|
262
|
+
def full_messages
|
263
|
+
full_messages = []
|
264
|
+
errors = localize_error_messages
|
265
|
+
errors.each_key do |attr|
|
266
|
+
errors[attr].each do |msg|
|
267
|
+
next if msg.nil?
|
268
|
+
full_messages << msg
|
269
|
+
end
|
270
|
+
end
|
271
|
+
full_messages
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
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.12 2006/08/17 17:24:18 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
12
|
require 'gettext/locale_object'
|
@@ -147,7 +147,8 @@ module Locale
|
|
147
147
|
# * charset: charset as String or nil
|
148
148
|
# * Returns: a Locale::Object.
|
149
149
|
#
|
150
|
-
# Sets a default locale. This function is an alias of Locale.set_default
|
150
|
+
# Sets a default locale. This function is an alias of Locale.set_default with
|
151
|
+
# calling set_current(nil).
|
151
152
|
#
|
152
153
|
# *Notice*: Locale.set(lctype, locale) is deprecated.
|
153
154
|
def set(lang, country = nil, charset = nil)
|
@@ -214,4 +215,10 @@ module Locale
|
|
214
215
|
set_current(nil)
|
215
216
|
self
|
216
217
|
end
|
218
|
+
|
219
|
+
# Gets the current system module. This is used for debugging.
|
220
|
+
# * Returns: the system module.
|
221
|
+
def system_module
|
222
|
+
@@locale_system_module
|
223
|
+
end
|
217
224
|
end
|
data/lib/gettext/locale_cgi.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
You may redistribute it and/or modify it under the same
|
7
7
|
license terms as Ruby.
|
8
8
|
|
9
|
-
$Id: locale_cgi.rb,v 1.
|
9
|
+
$Id: locale_cgi.rb,v 1.6 2006/09/10 15:08:32 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
12
|
|
@@ -26,15 +26,16 @@ module Locale
|
|
26
26
|
if ret = cgi_["lang"] and ret.size > 0
|
27
27
|
elsif ret = cgi_.cookies["lang"][0]
|
28
28
|
elsif lang = cgi_.accept_language and lang.size > 0
|
29
|
-
|
29
|
+
num = lang.index(/;|,/)
|
30
|
+
ret = num ? lang[0, num] : lang
|
30
31
|
else
|
31
32
|
ret = @@default_locale.to_str
|
32
33
|
end
|
33
34
|
|
34
35
|
codesets = cgi_.accept_charset
|
35
36
|
if codesets and codesets.size > 0
|
36
|
-
|
37
|
-
codeset =
|
37
|
+
num = codesets.index(',')
|
38
|
+
codeset = num ? codesets[0, num] : codesets
|
38
39
|
codeset = @@default_locale.charset if codeset == "*"
|
39
40
|
else
|
40
41
|
codeset = @@default_locale.charset
|
@@ -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_object.rb,v 1.
|
9
|
+
$Id: locale_object.rb,v 1.10 2006/09/10 15:08:32 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
12
|
|
@@ -53,6 +53,7 @@ module Locale
|
|
53
53
|
# "zh_Hant" => ["zh", nil, nil, "Hant", nil]
|
54
54
|
# "zh_Hant_HK" => ["zh", "HK", nil, "Hant", nil]
|
55
55
|
# "de_DE@collation=phonebook,currency=DDM" => ["de", "DE", nil, nil, "collation=phonebook,currency=DDM"]
|
56
|
+
|
56
57
|
def self.parse(locale_name)
|
57
58
|
lang_charset, modifier = locale_name.split(/@/)
|
58
59
|
lang, charset = lang_charset.split(/\./)
|
@@ -60,10 +61,10 @@ module Locale
|
|
60
61
|
language = language ? language.downcase : nil
|
61
62
|
language = "en" if language == "c" || language == "posix"
|
62
63
|
if country
|
63
|
-
if country =~
|
64
|
+
if country =~ /\A[A-Z][a-z]+\Z/ #Latn => script
|
64
65
|
tmp = script
|
65
66
|
script = country
|
66
|
-
if tmp =~
|
67
|
+
if tmp =~ /\A[A-Z]+\Z/ #US => country
|
67
68
|
country = tmp
|
68
69
|
else
|
69
70
|
country = nil
|
@@ -71,7 +72,7 @@ module Locale
|
|
71
72
|
end
|
72
73
|
else
|
73
74
|
country = country.upcase
|
74
|
-
if script !~
|
75
|
+
if script !~ /\A[A-Z][a-z]+\Z/ #Latn => script
|
75
76
|
variant = script
|
76
77
|
script = nil
|
77
78
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
=begin
|
3
|
-
parser/
|
3
|
+
parser/active_record.rb - parser for ActiveRecord
|
4
4
|
|
5
5
|
Copyright (C) 2005, 2006 Masao Mutoh
|
6
6
|
|
7
7
|
You may redistribute it and/or modify it under the same
|
8
8
|
license terms as Ruby.
|
9
9
|
|
10
|
-
$Id:
|
10
|
+
$Id: active_record.rb,v 1.2 2006/08/28 23:54:53 mutoh Exp $
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'gettext'
|
@@ -48,6 +48,13 @@ module GetText
|
|
48
48
|
# * :db_mode - the mode of the database. Default is "development"
|
49
49
|
# * :activerecord_classes - an Array of the superclass of the models. The classes should be String value. Default is ["ActiveRecord::Base"]
|
50
50
|
# * :untranslate_columns - an Array of the column names which is ignored as the msgid.
|
51
|
+
# * :adapter - the options for ActiveRecord::Base.establish_connection. If this value is set, :db_yml option is ignored.
|
52
|
+
# * :host - ditto
|
53
|
+
# * :username - ditto
|
54
|
+
# * :password - ditto
|
55
|
+
# * :database - ditto
|
56
|
+
# * :socket - ditto
|
57
|
+
# * :encoding - ditto
|
51
58
|
#
|
52
59
|
# "ClassName|FieldName" uses GetText.sgettext. So you don't need to translate the left-side of "|".
|
53
60
|
# See <Documents for Translators for more details(http://www.yotabanana.com/hiki/ruby-gettext-translate.html)>.
|
@@ -75,15 +82,17 @@ module GetText
|
|
75
82
|
loaded_constants = constants - old_constants
|
76
83
|
loaded_constants.each do |classname|
|
77
84
|
klass = eval(classname)
|
78
|
-
if klass < ActiveRecord::Base
|
85
|
+
if klass.is_a?(Class) && klass < ActiveRecord::Base
|
79
86
|
unless klass.untranslate_all?
|
80
87
|
add_target(targets, file, ::Inflector.singularize(klass.table_name.gsub(/_/, " ")))
|
81
|
-
|
88
|
+
unless klass.class_name == classname
|
89
|
+
add_target(targets, file, ::Inflector.singularize(classname.gsub(/_/, " ").downcase))
|
90
|
+
end
|
82
91
|
begin
|
83
92
|
klass.columns.each do |column|
|
84
93
|
unless untranslate_column?(klass, column.name)
|
85
94
|
if @config[:use_classname]
|
86
|
-
msgid =
|
95
|
+
msgid = classname + "|" + klass.human_attribute_name(column.name)
|
87
96
|
else
|
88
97
|
msgid = klass.human_attribute_name(column.name)
|
89
98
|
end
|
@@ -114,28 +123,36 @@ module GetText
|
|
114
123
|
targets
|
115
124
|
end
|
116
125
|
|
126
|
+
@@db_loaded = nil
|
117
127
|
def target?(file) # :nodoc:
|
118
128
|
init(nil) unless @ar_re
|
119
129
|
data = IO.readlines(file)
|
120
130
|
data.each do |v|
|
121
131
|
if @ar_re =~ v
|
122
|
-
unless
|
132
|
+
unless @@db_loaded
|
123
133
|
begin
|
124
134
|
require 'rubygems'
|
135
|
+
require_gem 'activerecord'
|
125
136
|
rescue LoadError
|
126
137
|
$stderr.puts _("rubygems are not found.") if $DEBUG
|
127
138
|
end
|
128
139
|
require 'active_record'
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
140
|
+
require 'gettext/active_record'
|
141
|
+
if @config[:adapter]
|
142
|
+
ActiveRecord::Base.establish_connection(@config)
|
143
|
+
else
|
144
|
+
begin
|
145
|
+
yml = YAML.load(ERB.new(IO.read(@config[:db_yml])).result)
|
146
|
+
rescue
|
147
|
+
return false
|
148
|
+
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'
|
133
153
|
end
|
134
|
-
ENV["RAILS_ENV"] = @config[:db_mode]
|
135
|
-
require_rails 'config/boot.rb'
|
136
|
-
require_rails 'config/environment.rb'
|
137
|
-
require_rails 'app/controllers/application.rb'
|
138
154
|
end
|
155
|
+
@@db_loaded = true
|
139
156
|
return true
|
140
157
|
end
|
141
158
|
end
|