gettext 1.5.0 → 1.6.0
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 +113 -0
- data/NEWS +17 -1
- data/README +56 -46
- data/Rakefile +6 -2
- 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 +2 -2
- 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 -26
- data/COPYING.ja +0 -51
- data/po/it/messages.mo +0 -0
- data/samples/cgi/po/it/messages.mo +0 -0
data/lib/gettext/container.rb
CHANGED
|
@@ -6,34 +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: container.rb,v 1.
|
|
9
|
+
$Id: container.rb,v 1.5 2006/06/04 14:43:37 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
12
|
require 'gettext'
|
|
13
13
|
|
|
14
|
-
module GetText
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# Normaly, GetText.bindtexdomain should be called once a ruby-script-file.
|
|
18
|
-
# But if the class includes GetText::Container, a TextDomain is bound to an instance of the class.
|
|
19
|
-
# So you don't need to call bindtextdomain in each files if the files define a class.
|
|
20
|
-
#
|
|
21
|
-
# This module is useful for application-side classes, but you shouldn't use this for libraries.
|
|
22
|
-
# Because the user of your library may override/add new features to the original library and the
|
|
23
|
-
# user needs to prepare another TextDomain(Otherwise, apply po/mo patch to the original library).
|
|
14
|
+
module GetText # :nodoc:
|
|
15
|
+
# Deprecated. You don't need this. Use GetText instead.
|
|
24
16
|
module Container
|
|
25
17
|
include GetText
|
|
26
|
-
|
|
27
|
-
alias :_bindtextdomain :bindtextdomain #:nodoc:
|
|
28
|
-
|
|
29
|
-
def bindtextdomain(domainname, path = nil, locale = nil, charset = nil) #:nodoc:
|
|
30
|
-
@gettext_container_domainname = domainname
|
|
31
|
-
_bindtextdomain(domainname, path, locale, charset)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def callersrc #:nodoc:
|
|
35
|
-
@gettext_container_domainname
|
|
36
|
-
end
|
|
37
|
-
|
|
38
18
|
end
|
|
39
19
|
end
|
data/lib/gettext/erb.rb
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
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.3 2006/06/04 14:43:37 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
12
|
require 'erb'
|
|
13
|
-
require 'gettext
|
|
13
|
+
require 'gettext'
|
|
14
14
|
|
|
15
15
|
module GetText
|
|
16
16
|
|
data/lib/gettext/locale_posix.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_posix.rb,v 1.
|
|
9
|
+
$Id: locale_posix.rb,v 1.3 2006/06/07 15:56:04 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
12
|
|
|
@@ -16,12 +16,20 @@ module Locale # :nodoc:
|
|
|
16
16
|
module SystemPosix
|
|
17
17
|
extend Locale::System
|
|
18
18
|
module_function
|
|
19
|
+
@@default_locale = Locale::Object.new("C", nil, "UTF-8")
|
|
20
|
+
|
|
19
21
|
# Gets the system locale using setlocale and nl_langinfo.
|
|
20
22
|
# * Returns the system locale (Locale::Object).
|
|
21
23
|
def system
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
locale = nil
|
|
25
|
+
[ENV["LC_ALL"], ENV["LC_MESSAGES"], ENV["LANG"],
|
|
26
|
+
@@default_locale.orig_str].each do |loc|
|
|
27
|
+
if loc != nil and loc.size > 0
|
|
28
|
+
locale = Locale::Object.new(loc)
|
|
29
|
+
locale.charset = get_charset(locale)
|
|
30
|
+
break
|
|
31
|
+
end
|
|
32
|
+
end
|
|
25
33
|
locale
|
|
26
34
|
end
|
|
27
35
|
|
|
@@ -36,7 +44,31 @@ module Locale # :nodoc:
|
|
|
36
44
|
ret
|
|
37
45
|
end
|
|
38
46
|
end
|
|
39
|
-
|
|
47
|
+
|
|
48
|
+
# Sets a default locale. en.UTF-8 is the default value if not set.
|
|
49
|
+
# * locale: Locale::Object object. You can't set nil.
|
|
50
|
+
# * Returns: self
|
|
51
|
+
def set_default_locale(locale)
|
|
52
|
+
raise "Wrong parameter: #{locale}" if locale.nil?
|
|
53
|
+
@@default_locale = locale
|
|
54
|
+
self
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Sets a default locale. en.UTF-8 is the default value if not set.
|
|
58
|
+
# * locale: Locale::Object
|
|
59
|
+
# * Returns: locale
|
|
60
|
+
def default_locale=(locale)
|
|
61
|
+
set_default_locale(locale)
|
|
62
|
+
locale
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Gets the default Locale::Object.
|
|
66
|
+
# * Returns: the default locale
|
|
67
|
+
def default_locale
|
|
68
|
+
@@default_locale
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if defined? Locale::System::MESSAGES
|
|
40
72
|
CTYPE = Locale::System::CTYPE #:nodoc:
|
|
41
73
|
NUMERIC = Locale::System::NUMERIC #:nodoc:
|
|
42
74
|
TIME = Locale::System::TIME #:nodoc:
|
data/lib/gettext/locale_win32.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_win32.rb,v 1.
|
|
9
|
+
$Id: locale_win32.rb,v 1.13 2006/06/04 14:43:37 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
12
|
require 'gettext/locale_table_win32'
|
|
@@ -32,6 +32,7 @@ module Locale #:nodoc:
|
|
|
32
32
|
# * Returns the system locale (Locale::Object)
|
|
33
33
|
def system
|
|
34
34
|
lang = nil
|
|
35
|
+
ret = nil
|
|
35
36
|
["LC_ALL", "LC_CTYPE", "LC_MESSAGES", "LANG"].each do |env|
|
|
36
37
|
lang = ENV[env]
|
|
37
38
|
if lang
|
data/lib/gettext/mo.rb
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
of Ruby. License of Ruby is included with Ruby distribution in
|
|
13
13
|
the file "README".
|
|
14
14
|
|
|
15
|
-
$Id: mo.rb,v 1.
|
|
15
|
+
$Id: mo.rb,v 1.6 2006/05/19 15:42:14 mutoh Exp $
|
|
16
16
|
=end
|
|
17
17
|
|
|
18
18
|
require 'gettext/iconv'
|
|
@@ -38,7 +38,7 @@ class MOFile < Hash #:nodoc:
|
|
|
38
38
|
|
|
39
39
|
def initialize(output_charset = nil)
|
|
40
40
|
@filename = nil
|
|
41
|
-
@last_modified =
|
|
41
|
+
@last_modified = nil
|
|
42
42
|
@little_endian = true
|
|
43
43
|
@output_charset = output_charset
|
|
44
44
|
super()
|
|
@@ -46,7 +46,8 @@ class MOFile < Hash #:nodoc:
|
|
|
46
46
|
|
|
47
47
|
def update!
|
|
48
48
|
if FileTest.exist?(@filename)
|
|
49
|
-
|
|
49
|
+
st = File.stat(@filename)
|
|
50
|
+
load(@filename) unless (@last_modified == [st.ctime, st.mtime])
|
|
50
51
|
else
|
|
51
52
|
puts "#{@filename} was lost." if $DEBUG
|
|
52
53
|
clear
|
|
@@ -58,7 +59,8 @@ class MOFile < Hash #:nodoc:
|
|
|
58
59
|
case arg
|
|
59
60
|
when String
|
|
60
61
|
begin
|
|
61
|
-
|
|
62
|
+
st = File.stat(arg)
|
|
63
|
+
@last_modified = [st.ctime, st.mtime]
|
|
62
64
|
rescue Exception
|
|
63
65
|
end
|
|
64
66
|
load_from_file(arg)
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
=begin
|
|
3
3
|
parser/activerecord.rb - parser for ActiveRecord
|
|
4
4
|
|
|
5
|
-
Copyright (C) 2005 Masao Mutoh
|
|
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: activerecord.rb,v 1.
|
|
10
|
+
$Id: activerecord.rb,v 1.9 2006/05/13 17:20:52 mutoh Exp $
|
|
11
11
|
=end
|
|
12
12
|
|
|
13
13
|
require 'gettext'
|
|
@@ -110,7 +110,11 @@ module GetText
|
|
|
110
110
|
data.each do |v|
|
|
111
111
|
if @ar_re =~ v
|
|
112
112
|
unless @db
|
|
113
|
-
|
|
113
|
+
begin
|
|
114
|
+
require 'rubygems'
|
|
115
|
+
rescue LoadError
|
|
116
|
+
$stderr.puts _("rubygems are not found.") if $DEBUG
|
|
117
|
+
end
|
|
114
118
|
require 'active_record'
|
|
115
119
|
begin
|
|
116
120
|
yml = YAML.load(ERB.new(IO.read(@config[:db_yml])).result)
|
data/lib/gettext/poparser.rb
CHANGED
|
@@ -20,7 +20,7 @@ module GetText
|
|
|
20
20
|
|
|
21
21
|
class PoParser < Racc::Parser
|
|
22
22
|
|
|
23
|
-
module_eval <<'..end src/poparser.ry modeval..
|
|
23
|
+
module_eval <<'..end src/poparser.ry modeval..id2c720ef3d7', 'src/poparser.ry', 90
|
|
24
24
|
include GetText
|
|
25
25
|
GetText.bindtextdomain("rgettext")
|
|
26
26
|
|
|
@@ -103,7 +103,7 @@ module_eval <<'..end src/poparser.ry modeval..id4c20337d09', 'src/poparser.ry',
|
|
|
103
103
|
@comments << comment
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
..end src/poparser.ry modeval..
|
|
106
|
+
..end src/poparser.ry modeval..id2c720ef3d7
|
|
107
107
|
|
|
108
108
|
##### racc 1.4.4 generates ###
|
|
109
109
|
|
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
|