gettext 1.5.0-mswin32 → 1.6.0-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +113 -0
- data/NEWS +17 -1
- data/README +56 -46
- data/Rakefile +7 -3
- 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/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/ext/gettext/locale_system.c +3 -3
- data/lib/gettext.rb +149 -98
- data/lib/gettext/container.rb +3 -23
- data/lib/gettext/erb.rb +2 -2
- data/lib/gettext/locale_posix.rb +37 -5
- data/lib/gettext/locale_win32.rb +2 -1
- data/lib/gettext/mo.rb +6 -4
- data/lib/gettext/parser/activerecord.rb +7 -3
- data/lib/gettext/poparser.rb +298 -298
- data/lib/gettext/rails.rb +131 -112
- data/lib/gettext/rgettext.rb +3 -1
- data/lib/gettext/rmsgfmt.rb +3 -1
- data/lib/gettext/rmsgmerge.rb +3 -1
- data/lib/gettext/textdomain.rb +14 -8
- data/lib/gettext/textdomainmanager.rb +103 -0
- data/lib/gettext/version.rb +1 -1
- data/po/cs/rails.po +16 -16
- data/po/cs/rgettext.po +7 -3
- data/po/de/rails.po +16 -16
- data/po/de/rgettext.po +7 -3
- data/po/el/rails.po +16 -16
- data/po/el/rgettext.po +7 -3
- data/po/es/rails.po +16 -16
- data/po/es/rgettext.po +7 -3
- data/po/fr/rails.po +16 -16
- data/po/fr/rgettext.po +7 -3
- data/po/it/rails.po +79 -0
- data/po/it/rgettext.po +42 -32
- data/po/ja/rails.po +20 -18
- data/po/ja/rgettext.po +7 -3
- data/po/ko/rails.po +16 -16
- data/po/ko/rgettext.po +7 -3
- data/po/nl/rails.po +16 -16
- data/po/nl/rgettext.po +7 -3
- data/po/pt_BR/rails.po +16 -16
- data/po/pt_BR/rgettext.po +7 -3
- data/po/rails.pot +16 -16
- data/po/rgettext.pot +7 -3
- data/po/ru/rails.po +18 -18
- data/po/ru/rgettext.po +13 -9
- data/po/sv/rgettext.po +7 -3
- data/po/zh/rails.po +78 -0
- data/po/zh/rgettext.po +104 -0
- data/pre-setup.rb +1 -4
- data/samples/cgi/helloerb.rhtml +1 -0
- data/samples/cgi/locale/zh/LC_MESSAGES/helloerb1.mo +0 -0
- data/samples/cgi/locale/zh/LC_MESSAGES/helloerb2.mo +0 -0
- data/samples/cgi/locale/zh/LC_MESSAGES/hellolib.mo +0 -0
- data/samples/cgi/locale/zh/LC_MESSAGES/main.mo +0 -0
- data/samples/cgi/po/zh/helloerb1.po +60 -0
- data/samples/cgi/po/zh/helloerb2.po +52 -0
- data/samples/cgi/po/zh/hellolib.po +24 -0
- data/samples/cgi/po/zh/main.po +80 -0
- data/samples/hello.rb +28 -5
- data/samples/hello2.rb +13 -6
- data/samples/hello_noop.rb +20 -8
- data/samples/hello_plural.rb +16 -6
- data/samples/hello_textdomain.rb +13 -4
- data/samples/hellogtk.rb +5 -4
- data/samples/hellogtk2.rb +5 -6
- data/samples/locale/cs/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/cs/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/de/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/de/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/el/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/el/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/es/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/es/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/fr/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/fr/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/it/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/it/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/ja/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/ja/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/ko/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/ko/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/nl/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/nl/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/pt_BR/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/pt_BR/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/ru/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/ru/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/sv/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/sv/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/hello.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/hello2.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/hello_noop.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/hello_plural.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/helloglade2.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/hellogtk.mo +0 -0
- data/samples/locale/zh/LC_MESSAGES/hellotk.mo +0 -0
- data/samples/po/cs/hello2.po +4 -4
- data/samples/po/cs/hello_plural.po +5 -5
- data/samples/po/de/hello2.po +4 -4
- data/samples/po/de/hello_plural.po +9 -6
- data/samples/po/el/hello2.po +4 -4
- data/samples/po/el/hello_plural.po +3 -3
- data/samples/po/es/hello2.po +4 -4
- data/samples/po/es/hello_plural.po +6 -6
- data/samples/po/fr/hello2.po +4 -4
- data/samples/po/fr/hello_plural.po +3 -3
- data/samples/po/hello2.pot +2 -2
- data/samples/po/hello_plural.pot +1 -1
- data/samples/po/it/hello2.po +4 -4
- data/samples/po/it/hello_plural.po +4 -5
- data/samples/po/ja/hello2.po +4 -4
- data/samples/po/ja/hello_plural.po +4 -5
- data/samples/po/ko/hello2.po +4 -4
- data/samples/po/ko/hello_plural.po +10 -7
- data/samples/po/nl/hello2.po +4 -4
- data/samples/po/nl/hello_plural.po +6 -7
- data/samples/po/pt_BR/hello2.po +4 -4
- data/samples/po/pt_BR/hello_plural.po +6 -6
- data/samples/po/ru/hello2.po +4 -4
- data/samples/po/ru/hello_plural.po +10 -7
- data/samples/po/sv/hello2.po +4 -4
- data/samples/po/sv/hello_plural.po +4 -4
- data/samples/po/zh/hello.po +23 -0
- data/samples/po/zh/hello2.po +31 -0
- data/samples/po/zh/hello_noop.po +27 -0
- data/samples/po/zh/hello_plural.po +25 -0
- data/samples/po/zh/helloglade2.po +31 -0
- data/samples/po/zh/hellogtk.po +23 -0
- data/samples/po/zh/hellotk.po +23 -0
- data/samples/rails/README +2 -2
- data/samples/rails/lib/tasks/gettext.rake +0 -3
- 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/po/blog.pot +1 -1
- data/samples/rails/po/cs/blog.po +1 -1
- data/samples/rails/po/de/blog.po +1 -1
- data/samples/rails/po/el/blog.po +1 -1
- data/samples/rails/po/en/blog.po +3 -3
- data/samples/rails/po/es/blog.po +1 -1
- data/samples/rails/po/fr/blog.po +1 -1
- data/samples/rails/po/it/blog.po +109 -0
- data/samples/rails/po/ja/blog.po +1 -14
- data/samples/rails/po/ko/blog.po +2 -2
- data/samples/rails/po/nl/blog.po +1 -1
- data/samples/rails/po/pt_BR/blog.po +1 -1
- data/samples/rails/po/ru/blog.po +1 -2
- data/samples/rails/po/zh/blog.po +109 -0
- data/samples/rails/vendor/plugins/gettext/README +17 -0
- data/samples/rails/vendor/plugins/gettext/Rakefile +17 -0
- data/samples/rails/vendor/plugins/gettext/lib/gettext_plugin.rb +16 -35
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/de/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/el/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/es/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/vendor/plugins/gettext/locale/it/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{locale → vendor/plugins/gettext/locale}/ru/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/vendor/plugins/gettext/locale/zh/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/{po → vendor/plugins/gettext/po}/cs/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/de/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/el/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/es/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/fr/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/gettext_plugin.pot +4 -4
- data/samples/rails/vendor/plugins/gettext/po/it/gettext_plugin.po +27 -0
- data/samples/rails/{po → vendor/plugins/gettext/po}/ja/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/ko/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/nl/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/pt_BR/gettext_plugin.po +4 -4
- data/samples/rails/{po → vendor/plugins/gettext/po}/ru/gettext_plugin.po +4 -5
- data/samples/rails/vendor/plugins/gettext/po/zh/gettext_plugin.po +27 -0
- data/test/gettext_test.rb +18 -14
- data/test/gettext_test_multi_textdomain.rb +49 -0
- data/test/locale/fr/LC_MESSAGES/test6.mo +0 -0
- data/test/locale/ja/LC_MESSAGES/test6.mo +0 -0
- data/test/po/fr/test6.po +23 -0
- data/test/po/ja/test6.po +23 -0
- data/test/test.sh +3 -1
- data/test/testlib1.rb +0 -5
- data/test/testlib5.rb +70 -0
- data/test/testlib6.rb +19 -0
- metadata +128 -33
- data/COPYING.ja +0 -51
- data/ext/gettext/Makefile +0 -178
- data/ext/gettext/locale_system-i386-mswin32.def +0 -2
- data/ext/gettext/locale_system.exp +0 -0
- data/ext/gettext/locale_system.lib +0 -0
- data/ext/gettext/locale_system.obj +0 -0
- data/ext/gettext/locale_system.pdb +0 -0
- data/ext/gettext/locale_system.so +0 -0
- data/ext/gettext/mkmf.log +0 -16
- data/ext/gettext/vc70.pdb +0 -0
data/lib/gettext/rails.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: rails.rb,v 1.
|
9
|
+
$Id: rails.rb,v 1.36 2006/06/04 14:43:37 mutoh Exp $
|
10
10
|
=end
|
11
11
|
|
12
12
|
require 'gettext/cgi'
|
@@ -22,12 +22,15 @@ module GetText #:nodoc:
|
|
22
22
|
# See <Ruby-GetText-Package HOWTO for Ruby on Rails (http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html>.
|
23
23
|
module Rails
|
24
24
|
include GetText
|
25
|
-
extend GetText
|
26
25
|
|
27
26
|
Rails = ::Rails #:nodoc:
|
28
27
|
|
29
28
|
alias :_bindtextdomain :bindtextdomain #:nodoc:
|
30
29
|
|
30
|
+
def self.included(mod) #:nodoc:
|
31
|
+
mod.extend self
|
32
|
+
end
|
33
|
+
|
31
34
|
module_function
|
32
35
|
# Bind a textdomain(#{path}/#{locale}/LC_MESSAGES/#{domainname}.mo) to your program.
|
33
36
|
# Notes the textdomain scope becomes all of the controllers/views/models in your app.
|
@@ -39,58 +42,44 @@ module GetText #:nodoc:
|
|
39
42
|
# On the other hand, you need to call this in helpers/plugins.
|
40
43
|
#
|
41
44
|
# * domainname: the textdomain name.
|
42
|
-
# *
|
43
|
-
#
|
44
|
-
#
|
45
|
+
# * options: options as a Hash.
|
46
|
+
# * :locale - the locale value such as "ja-JP". When the value is nil,
|
47
|
+
# locale is searched the order by this value > "lang" value of QUERY_STRING >
|
48
|
+
# params["lang"] > "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value
|
49
|
+
# > Default locale(en).
|
50
|
+
# * :path - the path to the mo-files. Default is "RAIL_ROOT/locale".
|
51
|
+
# * :charset - the charset. Generally UTF-8 is recommanded.
|
52
|
+
# And the charset is set order by "the argument of bindtextdomain"
|
53
|
+
# > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
|
54
|
+
# * :with_model - false if you want to ignore ActiveRecord support.
|
55
|
+
# * :with_helper - false if you want to ignore ApplicationHelper support.
|
45
56
|
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
|
57
|
+
# Note: Don't use locale, charset, with_model argument(not in options).
|
58
|
+
# They are remained for backward compatibility.
|
49
59
|
#
|
50
|
-
def bindtextdomain(domainname,
|
60
|
+
def bindtextdomain(domainname, options = {}, locale = nil, charset = nil, with_model = true)
|
61
|
+
opt = {:with_helper => true, :with_model => true}
|
62
|
+
if options.kind_of? CGI
|
63
|
+
# For backward compatibility
|
64
|
+
opt.merge!(:cgi => options, :locale => locale, :charset => charset, :with_model => with_model)
|
65
|
+
else
|
66
|
+
opt.merge!(options)
|
67
|
+
end
|
68
|
+
opt[:path] ||= File.join(RAILS_ROOT, "locale")
|
51
69
|
Locale.set_current(nil) # IMPORTANT! current locale should be nil once(default is used).
|
52
|
-
set_cgi(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
bindtextdomain_to(ActiveRecord::Base, domainname) if with_model
|
70
|
+
set_cgi(opt[:cgi]) if opt[:cgi]
|
71
|
+
ret = _bindtextdomain(domainname, opt)
|
72
|
+
bindtextdomain_to(ActiveRecord::Base, domainname) if opt[:with_model]
|
73
|
+
bindtextdomain_to(ApplicationHelper, domainname) if opt[:with_helper]
|
74
|
+
ret
|
58
75
|
end
|
59
76
|
|
60
77
|
def bindtextdomain_to(klass, domainname) #:nodoc:
|
61
78
|
klass.class_eval {
|
79
|
+
include GetText
|
62
80
|
textdomain(domainname)
|
63
|
-
def self.human_attribute_name(attribute_key_name) #:nodoc:
|
64
|
-
s_("#{self}|#{attribute_key_name.humanize}")
|
65
|
-
end
|
66
|
-
def self.human_attribute_table_name_for_error(table_name) #:nodoc:
|
67
|
-
_(table_name.gsub(/_/, " "))
|
68
|
-
end
|
69
81
|
}
|
70
82
|
end
|
71
|
-
|
72
|
-
def callersrc #:nodoc:
|
73
|
-
@gettext_container_domainname = nil unless defined? @gettext_container_domainname
|
74
|
-
@gettext_container_domainname
|
75
|
-
end
|
76
|
-
|
77
|
-
# true to use localized templates such as list.rhtml, list_ja.rhtml, list_ja_JP.rhtml.
|
78
|
-
# * setting: true if localized, otherwise false. Default is true.
|
79
|
-
# * Returns: setting
|
80
|
-
def use_localized_templates(setting)
|
81
|
-
@@gettext_use_localized_templates = setting
|
82
|
-
end
|
83
|
-
|
84
|
-
# true if it use localized templates. See GetText::Rails.use_localized_templates
|
85
|
-
# for more details.
|
86
|
-
# * Returns: true or false.
|
87
|
-
def use_localized_templates?
|
88
|
-
if defined? @@gettext_use_localized_templates
|
89
|
-
@@gettext_use_localized_templates
|
90
|
-
else
|
91
|
-
true
|
92
|
-
end
|
93
|
-
end
|
94
83
|
end
|
95
84
|
end
|
96
85
|
|
@@ -99,7 +88,6 @@ module ActionController #:nodoc:
|
|
99
88
|
class Base
|
100
89
|
helper GetText::Rails
|
101
90
|
include GetText::Rails
|
102
|
-
extend GetText::Rails
|
103
91
|
|
104
92
|
@@gettext_domainname = nil
|
105
93
|
@@gettext_content_type = nil
|
@@ -111,9 +99,9 @@ module ActionController #:nodoc:
|
|
111
99
|
if defined? request.cgi
|
112
100
|
cgi_ = request.cgi
|
113
101
|
cgi_.params["lang"] = [@params["lang"]] if @params["lang"]
|
114
|
-
bindtextdomain(@@gettext_domainname, cgi_) #You need to pass CGI object first.
|
102
|
+
bindtextdomain(@@gettext_domainname, {:cgi => cgi_}) #You need to pass CGI object first.
|
115
103
|
else
|
116
|
-
bindtextdomain(@@gettext_domainname,
|
104
|
+
bindtextdomain(@@gettext_domainname, {:locale => @params["lang"]})
|
117
105
|
end
|
118
106
|
end
|
119
107
|
|
@@ -131,19 +119,23 @@ module ActionController #:nodoc:
|
|
131
119
|
ActiveRecord::Errors.class_eval{
|
132
120
|
# You need to call bindtextdomain here because ActiveRecord::Errors doesn't know
|
133
121
|
# what locale is used in.
|
134
|
-
|
122
|
+
bindtextdomain("rails")
|
135
123
|
}
|
136
124
|
end
|
137
125
|
|
138
126
|
# Bind a 'textdomain' to all of the controllers/views/models. Call this instead of GetText.bindtextdomain.
|
139
127
|
# * textdomain: the textdomain
|
140
|
-
# *
|
141
|
-
#
|
128
|
+
# * options: options as a Hash.
|
129
|
+
# * :charset - the output charset. Default is "UTF-8"
|
130
|
+
# * :content_type - the content type. Default is "text/html"
|
142
131
|
#
|
143
132
|
# locale is searched the order by @params["lang"] > "lang" value of QUERY_STRING >
|
144
133
|
# "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
|
145
134
|
# And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
|
146
135
|
#
|
136
|
+
# Note: Don't use content_type argument(not in options).
|
137
|
+
# They are remained for backward compatibility.
|
138
|
+
#
|
147
139
|
# If you want to separate the textdomain each controllers, you need to call this function in the each controllers.
|
148
140
|
#
|
149
141
|
# app/controller/blog_controller.rb:
|
@@ -154,10 +146,15 @@ module ActionController #:nodoc:
|
|
154
146
|
# :
|
155
147
|
# :
|
156
148
|
# end
|
157
|
-
def self.init_gettext(domainname,
|
158
|
-
|
149
|
+
def self.init_gettext(domainname, options = {}, content_type = "text/html")
|
150
|
+
opt = {:charset => "UTF-8", :content_type => content_type}
|
151
|
+
if options.kind_of? String
|
152
|
+
# For backward compatibility
|
153
|
+
opt.merge!(:charset => options, :content_type => content_type)
|
154
|
+
end
|
155
|
+
GetText.output_charset = opt[:charset]
|
159
156
|
@@gettext_domainname = domainname
|
160
|
-
@@gettext_content_type = content_type
|
157
|
+
@@gettext_content_type = opt[:content_type]
|
161
158
|
end
|
162
159
|
end
|
163
160
|
|
@@ -183,8 +180,13 @@ module ActiveRecord #:nodoc:
|
|
183
180
|
end
|
184
181
|
|
185
182
|
class Base
|
186
|
-
|
187
|
-
|
183
|
+
def self.human_attribute_name(attribute_key_name) #:nodoc:
|
184
|
+
s_("#{self}|#{attribute_key_name.humanize}")
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.human_attribute_table_name_for_error(table_name) #:nodoc:
|
188
|
+
_(table_name.gsub(/_/, " "))
|
189
|
+
end
|
188
190
|
|
189
191
|
@@error_message_title = nil
|
190
192
|
@@error_message_explanation = nil
|
@@ -205,6 +207,19 @@ module ActiveRecord #:nodoc:
|
|
205
207
|
@@error_message_title = [single_msg, plural_msg]
|
206
208
|
end
|
207
209
|
|
210
|
+
# Very ugly but...
|
211
|
+
@@custom_error_messages_d = {}
|
212
|
+
def self.validates_length_of(*attrs) #:nodoc:
|
213
|
+
if attrs.last.is_a?(Hash)
|
214
|
+
msg = attrs.last[:message]
|
215
|
+
@@custom_error_messages_d[msg] = /#{Regexp.escape(msg).sub(/%d/, '(\d+)')}/ if msg
|
216
|
+
end
|
217
|
+
validates_size_of(*attrs)
|
218
|
+
end
|
219
|
+
def custom_error_messages_d #:nodoc:
|
220
|
+
@@custom_error_messages_d
|
221
|
+
end
|
222
|
+
|
208
223
|
def self.columns
|
209
224
|
unless @columns
|
210
225
|
@columns = connection.columns(table_name, "#{name} Columns")
|
@@ -254,7 +269,6 @@ module ActiveRecord #:nodoc:
|
|
254
269
|
|
255
270
|
class Errors #:nodoc:
|
256
271
|
include GetText
|
257
|
-
extend GetText
|
258
272
|
|
259
273
|
RE_FIELD_NAME = /%\{fn\}/ #:nodoc:
|
260
274
|
|
@@ -274,34 +288,39 @@ module ActiveRecord #:nodoc:
|
|
274
288
|
:not_a_number => N_("%{fn} is not a number")
|
275
289
|
)
|
276
290
|
@@default_error_messages_d = {
|
277
|
-
:too_long => /#{Regexp.escape(default_error_messages[:too_long]).sub(/%d/, '(\d+)')}/,
|
278
|
-
:too_short
|
279
|
-
:wrong_length
|
291
|
+
default_error_messages[:too_long] => /#{Regexp.escape(default_error_messages[:too_long]).sub(/%d/, '(\d+)')}/,
|
292
|
+
default_error_messages[:too_short] =>/#{Regexp.escape(default_error_messages[:too_short]).sub(/%d/, '(\d+)')}/,
|
293
|
+
default_error_messages[:wrong_length] =>/#{Regexp.escape(default_error_messages[:wrong_length]).sub(/%d/, '(\d+)')}/,
|
280
294
|
}
|
295
|
+
cattr_accessor :default_error_messages_d
|
281
296
|
|
282
297
|
def full_messages #:nodoc:
|
283
298
|
full_messages = []
|
284
299
|
@errors.each_key do |attr|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
300
|
+
@errors[attr].each do |msg|
|
301
|
+
next if msg.nil?
|
302
|
+
custom_msg = nil
|
303
|
+
#Ugly but... :-<
|
304
|
+
@@default_error_messages_d.merge(@base.custom_error_messages_d).each do |key, regexp|
|
305
|
+
if regexp =~ msg
|
306
|
+
custom_msg = @base.gettext(key)
|
307
|
+
custom_msg = _(msg) if custom_msg == msg
|
308
|
+
custom_msg = _(custom_msg) % $1.to_i
|
309
|
+
break
|
310
|
+
end
|
311
|
+
end
|
312
|
+
unless custom_msg
|
313
|
+
custom_msg = @base.gettext(msg)
|
314
|
+
custom_msg = _(msg) if custom_msg == msg
|
315
|
+
end
|
316
|
+
if attr == "base"
|
317
|
+
full_messages << custom_msg
|
318
|
+
elsif RE_FIELD_NAME =~ custom_msg
|
319
|
+
full_messages << custom_msg % {:fn => @base.class.human_attribute_name(attr)}
|
320
|
+
else
|
321
|
+
full_messages << @base.class.human_attribute_name(attr) + " " + custom_msg
|
322
|
+
end
|
323
|
+
end
|
305
324
|
end
|
306
325
|
full_messages
|
307
326
|
end
|
@@ -315,12 +334,10 @@ module ActionView #:nodoc:
|
|
315
334
|
# This provides to find localized template files such as foo_ja.rhtml, foo_ja_JP.rhtml
|
316
335
|
# instead of foo.rhtml. If the file isn't found, foo.rhtml is used.
|
317
336
|
def render_file(template_path, use_full_path = true, local_assigns = {})
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
return render_file_without_locale(localized_path, use_full_path, local_assigns) if file_exists? localized_path
|
323
|
-
end
|
337
|
+
locale = GetText.locale
|
338
|
+
[locale.to_general, locale.to_s, locale.language, Locale.default.language].each do |v|
|
339
|
+
localized_path = "#{template_path}_#{v}"
|
340
|
+
return render_file_without_locale(localized_path, use_full_path, local_assigns) if file_exists? localized_path
|
324
341
|
end
|
325
342
|
render_file_without_locale(template_path, use_full_path, local_assigns)
|
326
343
|
end
|
@@ -375,36 +392,38 @@ module ActionView #:nodoc:
|
|
375
392
|
end
|
376
393
|
end
|
377
394
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
end
|
392
|
-
text = TMail::Base64.folding_encode(text)
|
393
|
-
"=?#{charset}?B?#{text}?="
|
394
|
-
end
|
395
|
-
|
396
|
-
def create!(*arg) #:nodoc:
|
397
|
-
_create!(*arg)
|
398
|
-
if Locale.get.language == "ja"
|
399
|
-
require 'nkf'
|
400
|
-
@mail.subject = base64(@mail.subject)
|
401
|
-
part = @mail.parts.empty? ? @mail : @mail.parts.first
|
402
|
-
if part.content_type == 'text/plain'
|
403
|
-
part.charset = 'iso-2022-jp'
|
404
|
-
part.body = NKF.nkf('-j', part.body)
|
395
|
+
if defined? ActionMailer
|
396
|
+
module ActionMailer #:nodoc:
|
397
|
+
class Base #:nodoc:
|
398
|
+
helper GetText::Rails
|
399
|
+
include GetText::Rails
|
400
|
+
extend GetText::Rails
|
401
|
+
|
402
|
+
alias :_create! :create! #:nodoc:
|
403
|
+
|
404
|
+
def base64(text, charset="iso-2022-jp", convert=true)
|
405
|
+
if convert
|
406
|
+
if charset == "iso-2022-jp"
|
407
|
+
text = NKF.nkf('-j -m0', text)
|
405
408
|
end
|
409
|
+
end
|
410
|
+
text = TMail::Base64.folding_encode(text)
|
411
|
+
"=?#{charset}?B?#{text}?="
|
406
412
|
end
|
413
|
+
|
414
|
+
def create!(*arg) #:nodoc:
|
415
|
+
_create!(*arg)
|
416
|
+
if Locale.get.language == "ja"
|
417
|
+
require 'nkf'
|
418
|
+
@mail.subject = base64(@mail.subject)
|
419
|
+
part = @mail.parts.empty? ? @mail : @mail.parts.first
|
420
|
+
if part.content_type == 'text/plain'
|
421
|
+
part.charset = 'iso-2022-jp'
|
422
|
+
part.body = NKF.nkf('-j', part.body)
|
423
|
+
end
|
424
|
+
end
|
407
425
|
@mail
|
426
|
+
end
|
408
427
|
end
|
409
428
|
end
|
410
429
|
end
|
data/lib/gettext/rgettext.rb
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'optparse'
|
16
16
|
require 'gettext'
|
17
|
+
require 'rbconfig'
|
17
18
|
|
18
19
|
module GetText
|
19
20
|
|
@@ -24,7 +25,7 @@ module GetText
|
|
24
25
|
|
25
26
|
# constant values
|
26
27
|
VERSION = GetText::VERSION
|
27
|
-
DATE = %w($Date: 2006/
|
28
|
+
DATE = %w($Date: 2006/06/04 15:07:34 $)[1]
|
28
29
|
MAX_LINE_LEN = 70
|
29
30
|
|
30
31
|
@ex_parsers = []
|
@@ -142,6 +143,7 @@ msgstr ""
|
|
142
143
|
|
143
144
|
opts.on_tail("--version", _("display version information and exit")) do
|
144
145
|
puts "#{$0} #{VERSION} (#{DATE})"
|
146
|
+
puts "#{File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
145
147
|
exit
|
146
148
|
end
|
147
149
|
|
data/lib/gettext/rmsgfmt.rb
CHANGED
@@ -11,6 +11,7 @@ require 'optparse'
|
|
11
11
|
require 'fileutils'
|
12
12
|
require 'gettext'
|
13
13
|
require 'gettext/poparser'
|
14
|
+
require 'rbconfig'
|
14
15
|
|
15
16
|
module GetText
|
16
17
|
GetText.bindtextdomain("rgettext")
|
@@ -19,7 +20,7 @@ module GetText
|
|
19
20
|
extend GetText
|
20
21
|
|
21
22
|
VERSION = GetText::VERSION
|
22
|
-
DATE = %w($Date: 2006/
|
23
|
+
DATE = %w($Date: 2006/06/04 15:07:34 $)[1] # :nodoc:
|
23
24
|
|
24
25
|
module_function
|
25
26
|
def run(targetfile = nil, output_path = nil) # :nodoc:
|
@@ -55,6 +56,7 @@ module GetText
|
|
55
56
|
|
56
57
|
opts.on_tail("--version", _("display version information and exit")) do
|
57
58
|
puts "#{$0} #{VERSION} (#{DATE})"
|
59
|
+
puts "#{File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
58
60
|
exit
|
59
61
|
end
|
60
62
|
opts.parse!(ARGV)
|
data/lib/gettext/rmsgmerge.rb
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
require 'optparse'
|
12
12
|
require 'gettext'
|
13
13
|
require 'gettext/poparser'
|
14
|
+
require 'rbconfig'
|
14
15
|
|
15
16
|
module GetText
|
16
17
|
|
@@ -393,7 +394,7 @@ module GetText
|
|
393
394
|
|
394
395
|
# constant values
|
395
396
|
VERSION = GetText::VERSION
|
396
|
-
DATE = %w($Date: 2006/
|
397
|
+
DATE = %w($Date: 2006/06/04 15:07:34 $)[1]
|
397
398
|
|
398
399
|
module_function
|
399
400
|
|
@@ -419,6 +420,7 @@ module GetText
|
|
419
420
|
|
420
421
|
opts.on_tail("--version", _("display version information and exit")) do
|
421
422
|
puts "#{$0} #{VERSION} (#{DATE})"
|
423
|
+
puts "#{File.join(::Config::CONFIG["bindir"], ::Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
422
424
|
exit
|
423
425
|
end
|
424
426
|
|
data/lib/gettext/textdomain.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
You may redistribute it and/or modify it under the same
|
11
11
|
license terms as Ruby.
|
12
12
|
|
13
|
-
$Id: textdomain.rb,v 1.
|
13
|
+
$Id: textdomain.rb,v 1.17 2006/06/04 14:43:37 mutoh Exp $
|
14
14
|
=end
|
15
15
|
|
16
16
|
require 'gettext/string'
|
@@ -27,7 +27,9 @@ module GetText
|
|
27
27
|
GEM_PATH_RE = /(.*)\/lib$/ # :nodoc:
|
28
28
|
|
29
29
|
attr_reader :current_locale
|
30
|
+
attr_reader :locale_paths
|
30
31
|
attr_reader :current_mo
|
32
|
+
attr_reader :name
|
31
33
|
|
32
34
|
@@check_mo = false
|
33
35
|
# Check mo-file is modified or not, and if mo-file is modified,
|
@@ -46,10 +48,12 @@ module GetText
|
|
46
48
|
@@check_mo = val
|
47
49
|
end
|
48
50
|
# The default locale paths.
|
51
|
+
CONFIG_PREFIX = Config::CONFIG['prefix'].gsub(/\/local/, "")
|
49
52
|
DEFAULT_LOCALE_PATHS = [
|
50
53
|
"#{Config::CONFIG['datadir']}/locale/%{locale}/LC_MESSAGES/%{name}.mo",
|
51
|
-
"#{Config::CONFIG['
|
52
|
-
"#{
|
54
|
+
"#{Config::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{locale}/LC_MESSAGES/%{name}.mo",
|
55
|
+
"#{CONFIG_PREFIX}/share/locale/%{locale}/LC_MESSAGES/%{name}.mo",
|
56
|
+
"#{CONFIG_PREFIX}/local/share/locale/%{locale}/LC_MESSAGES/%{name}.mo"
|
53
57
|
].uniq
|
54
58
|
|
55
59
|
# Add default locale path. Usually you should use GetText.add_default_locale_path instead.
|
@@ -109,13 +113,13 @@ module GetText
|
|
109
113
|
|
110
114
|
# Gets the translated string.
|
111
115
|
# * msgid: the original message.
|
112
|
-
# * Returns: the translated string.
|
116
|
+
# * Returns: the translated string or nil if not found.
|
113
117
|
def gettext(msgid)
|
114
118
|
return "" if msgid == "" or msgid.nil?
|
115
119
|
if @current_mo and @current_mo[msgid] and (@current_mo[msgid].size > 0)
|
116
120
|
@current_mo[msgid]
|
117
121
|
else
|
118
|
-
|
122
|
+
nil
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
@@ -123,11 +127,13 @@ module GetText
|
|
123
127
|
# * msgid: the original message(single).
|
124
128
|
# * msgid: the original message(plural).
|
125
129
|
# * n: the number
|
126
|
-
# * Returns: the translated string.
|
130
|
+
# * Returns: the translated string or nil if not found.
|
127
131
|
def ngettext(msgid, msgid_plural, n)
|
128
132
|
key = msgid + "\000" + msgid_plural
|
129
133
|
msg = gettext(key)
|
130
|
-
if msg
|
134
|
+
if ! msg
|
135
|
+
nil
|
136
|
+
elsif msg == key
|
131
137
|
msg = n == 1 ? msgid : msgid_plural
|
132
138
|
elsif msg.include?("\000")
|
133
139
|
ary = msg.split("\000")
|
@@ -172,7 +178,7 @@ module GetText
|
|
172
178
|
end
|
173
179
|
end
|
174
180
|
end
|
175
|
-
locales = [@current_locale.orig_str, @current_locale.to_posix, @current_locale.language]
|
181
|
+
locales = [@current_locale.orig_str, @current_locale.to_posix, @current_locale.language].uniq
|
176
182
|
@locale_paths.each do |dir|
|
177
183
|
locales.each{|locale|
|
178
184
|
fname = dir % {:locale => locale, :name => @name}
|