gettext 1.1.1 → 1.2.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 +128 -0
- data/NEWS +10 -0
- data/README +21 -23
- data/Rakefile +39 -20
- 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/fr/LC_MESSAGES/rails.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rgettext.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/sv/LC_MESSAGES/rgettext.mo +0 -0
- data/ext/gettext/extconf.rb +20 -0
- data/ext/gettext/{gettext/_locale.c → locale_system.c} +15 -19
- data/lib/gettext.rb +186 -38
- data/lib/gettext/cgi.rb +35 -69
- data/lib/gettext/container.rb +14 -5
- data/lib/gettext/erb.rb +30 -2
- data/lib/gettext/iconv.rb +19 -4
- data/lib/gettext/locale.rb +188 -39
- data/lib/gettext/locale_cgi.rb +102 -0
- data/lib/gettext/locale_object.rb +131 -0
- data/lib/gettext/locale_posix.rb +50 -0
- data/lib/gettext/locale_table_win32.rb +224 -182
- data/lib/gettext/locale_win32.rb +59 -35
- data/lib/gettext/mo.rb +2 -2
- data/lib/gettext/parser/activerecord.rb +19 -5
- data/lib/gettext/parser/erb.rb +6 -3
- data/lib/gettext/parser/glade.rb +5 -5
- data/lib/gettext/parser/ruby.rb +6 -6
- data/lib/gettext/poparser.rb +7 -6
- data/lib/gettext/rails.rb +122 -44
- data/lib/gettext/rgettext.rb +21 -8
- data/lib/gettext/rmsgfmt.rb +16 -8
- data/lib/gettext/rmsgmerge.rb +172 -50
- data/lib/gettext/string.rb +25 -3
- data/lib/gettext/textdomain.rb +89 -90
- data/lib/gettext/utils.rb +63 -3
- data/lib/gettext/version.rb +2 -2
- data/pkg/ruby-gettext-package-1.2.0/ext/gettext/extconf.rb +20 -0
- data/po/cs/rails.po +28 -28
- data/po/cs/rgettext.po +14 -14
- data/po/de/rails.po +29 -26
- data/po/de/rgettext.po +24 -17
- data/po/el/rails.po +26 -26
- data/po/el/rgettext.po +18 -15
- data/po/es/rails.po +26 -26
- data/po/es/rgettext.po +16 -16
- data/po/fr/rails.po +27 -27
- data/po/fr/rgettext.po +14 -14
- data/po/it/rgettext.po +14 -14
- data/po/ja/rails.po +24 -24
- data/po/ja/rgettext.po +14 -14
- data/po/ko/rails.po +24 -24
- data/po/ko/rgettext.po +17 -18
- data/po/nl/rails.po +27 -27
- data/po/nl/rgettext.po +18 -18
- data/po/pt_BR/rails.po +26 -26
- data/po/pt_BR/rgettext.po +14 -14
- data/po/rails.pot +26 -26
- data/po/rgettext.pot +14 -14
- data/po/sv/rgettext.po +14 -14
- data/post-setup.rb +8 -3
- data/pre-setup.rb +14 -1
- data/samples/cgi/http.rb +2 -1
- data/samples/makemo.rb +1 -1
- data/samples/rails/app/models/article.rb +15 -1
- data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/el/LC_MESSAGES/gettext_plugin.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/es/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
- data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
- data/samples/rails/po/blog.pot +1 -1
- data/samples/rails/po/cs/blog.po +1 -2
- data/samples/rails/po/cs/gettext_plugin.po +1 -1
- data/samples/rails/po/de/blog.po +1 -2
- data/samples/rails/po/de/gettext_plugin.po +1 -1
- data/samples/rails/po/el/blog.po +1 -1
- data/samples/rails/po/el/gettext_plugin.po +1 -1
- data/samples/rails/po/en/blog.po +1 -1
- data/samples/rails/po/es/blog.po +1 -2
- data/samples/rails/po/es/gettext_plugin.po +1 -1
- data/samples/rails/po/fr/blog.po +1 -1
- data/samples/rails/po/fr/gettext_plugin.po +1 -1
- data/samples/rails/po/gettext_plugin.pot +1 -1
- data/samples/rails/po/ja/blog.po +2 -1
- data/samples/rails/po/ja/gettext_plugin.po +1 -1
- data/samples/rails/po/ko/blog.po +1 -2
- data/samples/rails/po/ko/gettext_plugin.po +1 -1
- data/samples/rails/po/nl/blog.po +1 -3
- data/samples/rails/po/nl/gettext_plugin.po +1 -1
- data/samples/rails/po/pt_BR/blog.po +1 -1
- data/samples/rails/po/pt_BR/gettext_plugin.po +1 -1
- data/setup.rb +799 -574
- data/src/poparser.ry +6 -5
- data/test/gettext_runner.rb +3 -1
- data/test/gettext_test.rb +40 -24
- data/test/gettext_test_cgi.rb +60 -6
- data/test/gettext_test_locale.rb +136 -0
- data/test/gettext_test_parser.rb +12 -12
- data/test/locale/la/LC_MESSAGES/plural_error.mo +0 -0
- data/test/po/la/plural_error.po +21 -0
- data/test/test.bat +2 -0
- data/test/test.sh +2 -4
- data/test/{test_rubyparser_n.rb → test_rubyparser_n_.rb} +0 -0
- metadata +17 -12
- data/ext/gettext/gettext/MANIFEST +0 -3
- data/ext/gettext/gettext/extconf.rb +0 -20
- data/lib/gettext/locale_default.rb +0 -35
data/lib/gettext/locale_win32.rb
CHANGED
|
@@ -1,55 +1,79 @@
|
|
|
1
1
|
=begin
|
|
2
|
-
locale_win32.rb
|
|
2
|
+
locale_win32.rb
|
|
3
3
|
|
|
4
|
-
Copyright (C) 2002
|
|
4
|
+
Copyright (C) 2002-2006 Masao Mutoh <mutoh@highway.ne.jp>
|
|
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: locale_win32.rb,v 1.
|
|
9
|
+
$Id: locale_win32.rb,v 1.12 2006/02/20 16:12:05 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
12
|
require 'gettext/locale_table_win32'
|
|
13
13
|
|
|
14
|
-
module Locale
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
module Locale #:nodoc:
|
|
15
|
+
# Locale::SystemWin32 module for win32.
|
|
16
|
+
module SystemWin32
|
|
17
|
+
extend Locale::System
|
|
18
|
+
|
|
19
|
+
@@default_locale = Locale::Object.new("en", nil, "CP1252")
|
|
20
|
+
|
|
21
|
+
module_function
|
|
22
|
+
# Gets the charset of the locale. ENV(LC_ALL > LC_CTYPE > LC_MESSAGES > LANG) >
|
|
23
|
+
# the default locale from GetUserDefaultLangID.
|
|
24
|
+
# * locale: Locale::Object
|
|
25
|
+
# * Returns the charset of the locale
|
|
26
|
+
def get_charset(locale)
|
|
27
|
+
loc = LocaleTable.find{|v| v[1] == locale.to_win}
|
|
28
|
+
loc ? loc[2] : "CP1252"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Gets the system locale.
|
|
32
|
+
# * Returns the system locale (Locale::Object)
|
|
33
|
+
def system
|
|
34
|
+
lang = nil
|
|
35
|
+
["LC_ALL", "LC_CTYPE", "LC_MESSAGES", "LANG"].each do |env|
|
|
36
|
+
lang = ENV[env]
|
|
37
|
+
if lang
|
|
38
|
+
ret = Locale::Object.new(lang)
|
|
39
|
+
ret.charset = get_charset(ret)
|
|
40
|
+
break
|
|
41
|
+
end
|
|
24
42
|
end
|
|
25
|
-
unless
|
|
26
|
-
|
|
27
|
-
lang
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
unless lang
|
|
44
|
+
lang = LocaleTable.assoc(locale_id)
|
|
45
|
+
if lang
|
|
46
|
+
ret = Locale::Object.new(lang[1], nil, lang[2])
|
|
47
|
+
else
|
|
48
|
+
ret = @@default_locale
|
|
30
49
|
end
|
|
31
|
-
ret = lang ? lang[1] : "C"
|
|
32
50
|
end
|
|
33
|
-
|
|
51
|
+
ret
|
|
34
52
|
end
|
|
35
|
-
ret
|
|
36
|
-
end
|
|
37
53
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
# Sets a default locale. en.UTF-8 is the default value if not set.
|
|
55
|
+
# * locale: Locale::Object object. You can't set nil.
|
|
56
|
+
# * Returns: self
|
|
57
|
+
def set_default_locale(locale)
|
|
58
|
+
raise "Wrong parameter: #{locale}" if locale.nil?
|
|
59
|
+
@@default_locale = locale
|
|
60
|
+
self
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Sets a default locale. en.UTF-8 is the default value if not set.
|
|
64
|
+
# * locale: Locale::Object
|
|
65
|
+
# * Returns: locale
|
|
66
|
+
def default_locale=(locale)
|
|
67
|
+
set_default_locale(locale)
|
|
68
|
+
locale
|
|
41
69
|
end
|
|
42
|
-
end
|
|
43
70
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
MONETARY = 4
|
|
50
|
-
MESSAGES = 5
|
|
51
|
-
ALL = 6
|
|
71
|
+
# Gets the default Locale::Object.
|
|
72
|
+
# * Returns: the default locale
|
|
73
|
+
def default_locale
|
|
74
|
+
@@default_locale
|
|
75
|
+
end
|
|
52
76
|
end
|
|
53
|
-
|
|
77
|
+
@@locale_system_module = SystemWin32
|
|
54
78
|
end
|
|
55
79
|
|
data/lib/gettext/mo.rb
CHANGED
|
@@ -12,12 +12,12 @@
|
|
|
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.3 2006/02/23 14:53:59 mutoh Exp $
|
|
16
16
|
=end
|
|
17
17
|
|
|
18
18
|
require 'gettext/iconv'
|
|
19
19
|
|
|
20
|
-
class MOFile < Hash
|
|
20
|
+
class MOFile < Hash #:nodoc:
|
|
21
21
|
class InvalidFormat < RuntimeError; end;
|
|
22
22
|
|
|
23
23
|
Header = Struct.new(:magic,
|
|
@@ -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: activerecord.rb,v 1.
|
|
10
|
+
$Id: activerecord.rb,v 1.6 2006/02/22 16:42:41 mutoh Exp $
|
|
11
11
|
=end
|
|
12
12
|
|
|
13
13
|
require 'gettext'
|
|
@@ -31,7 +31,7 @@ module GetText
|
|
|
31
31
|
@ar_re = nil
|
|
32
32
|
|
|
33
33
|
module_function
|
|
34
|
-
def require_rails(file)
|
|
34
|
+
def require_rails(file) # :nodoc:
|
|
35
35
|
begin
|
|
36
36
|
require file
|
|
37
37
|
rescue MissingSourceFile
|
|
@@ -39,6 +39,16 @@ module GetText
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# Sets some preferences to parse ActiveRecord files.
|
|
43
|
+
#
|
|
44
|
+
# * config: a Hash of the config. It can takes some values below:
|
|
45
|
+
# * :use_classname: If true, the msgids of ActiveRecord become "ClassName|FieldName" (e.g. "Article|Title"). Otherwise the ClassName is not used (e.g. "Title"). Default is true.
|
|
46
|
+
# * :db_yml: the path of database.yml. Default is "config/database.yml".
|
|
47
|
+
# * :db_mode: the mode of the database. Default is "development"
|
|
48
|
+
# * :activerecord_classes: an Array of the superclass of the models. The classes should be String value. Default is ["ActiveRecord::Base"]
|
|
49
|
+
#
|
|
50
|
+
# "ClassName|FieldName" uses GetText.sgettext. So you don't need to translate the left-side of "|".
|
|
51
|
+
# See <Documents for Translators for more details(http://www.yotabanana.com/hiki/ruby-gettext-translate.html)>.
|
|
42
52
|
def init(config)
|
|
43
53
|
if config
|
|
44
54
|
config.each{|k, v|
|
|
@@ -48,7 +58,7 @@ module GetText
|
|
|
48
58
|
@ar_re = /class.*(#{@config[:activerecord_classes].join("|")})/
|
|
49
59
|
end
|
|
50
60
|
|
|
51
|
-
def parse(file, targets = [])
|
|
61
|
+
def parse(file, targets = []) # :nodoc:
|
|
52
62
|
old_constants = constants
|
|
53
63
|
begin
|
|
54
64
|
eval(open(file).read)
|
|
@@ -83,7 +93,7 @@ module GetText
|
|
|
83
93
|
targets
|
|
84
94
|
end
|
|
85
95
|
|
|
86
|
-
def target?(file)
|
|
96
|
+
def target?(file) # :nodoc:
|
|
87
97
|
init(nil) unless @ar_re
|
|
88
98
|
data = IO.readlines(file)
|
|
89
99
|
data.each do |v|
|
|
@@ -91,7 +101,11 @@ module GetText
|
|
|
91
101
|
unless @db
|
|
92
102
|
require 'rubygems'
|
|
93
103
|
require 'active_record'
|
|
94
|
-
|
|
104
|
+
begin
|
|
105
|
+
yml = YAML.load(ERB.new(IO.read(@config[:db_yml])).result)
|
|
106
|
+
rescue
|
|
107
|
+
return false
|
|
108
|
+
end
|
|
95
109
|
ENV["RAILS_ENV"] = @config[:db_mode]
|
|
96
110
|
require_rails 'config/boot.rb'
|
|
97
111
|
require_rails 'config/environment.rb'
|
data/lib/gettext/parser/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/02/22 16:42:41 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
12
|
require 'erb'
|
|
@@ -19,18 +19,21 @@ module GetText
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
module_function
|
|
22
|
+
# Sets some preferences to parse ERB files.
|
|
23
|
+
# * config: a Hash of the config. It can takes some values below:
|
|
24
|
+
# * :extnames: An Array of target files extension. Default is [".rhtml"].
|
|
22
25
|
def init(config)
|
|
23
26
|
config.each{|k, v|
|
|
24
27
|
@config[k] = v
|
|
25
28
|
}
|
|
26
29
|
end
|
|
27
30
|
|
|
28
|
-
def parse(file, targets = [])
|
|
31
|
+
def parse(file, targets = []) # :nodoc:
|
|
29
32
|
erb = ERB.new(IO.readlines(file).join).src.split(/$/)
|
|
30
33
|
RubyParser.parse_lines(file, erb, targets)
|
|
31
34
|
end
|
|
32
35
|
|
|
33
|
-
def target?(file)
|
|
36
|
+
def target?(file) # :nodoc:
|
|
34
37
|
@config[:extnames].each do |v|
|
|
35
38
|
return true if File.extname(file) == v
|
|
36
39
|
end
|
data/lib/gettext/parser/glade.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: glade.rb,v 1.
|
|
9
|
+
$Id: glade.rb,v 1.4 2006/02/22 16:42:41 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
12
|
require 'cgi'
|
|
@@ -21,13 +21,13 @@ module GetText
|
|
|
21
21
|
TARGET2 = /(.*)<\/property>/
|
|
22
22
|
|
|
23
23
|
module_function
|
|
24
|
-
def parse(file, targets = [])
|
|
24
|
+
def parse(file, targets = []) # :nodoc:
|
|
25
25
|
lines = IO.readlines(file)
|
|
26
26
|
parse_lines(file, lines, targets)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
#from ary of lines.
|
|
30
|
-
def parse_lines(file, lines, targets)
|
|
30
|
+
def parse_lines(file, lines, targets) # :nodoc:
|
|
31
31
|
cnt = 0
|
|
32
32
|
target = false
|
|
33
33
|
line_no = 0
|
|
@@ -65,7 +65,7 @@ module GetText
|
|
|
65
65
|
XML_RE = /<\?xml/
|
|
66
66
|
GLADE_RE = /glade-2.0.dtd/
|
|
67
67
|
|
|
68
|
-
def target?(file)
|
|
68
|
+
def target?(file) # :nodoc:
|
|
69
69
|
data = IO.readlines(file)
|
|
70
70
|
if XML_RE =~ data[0]
|
|
71
71
|
if GLADE_RE =~ data[1]
|
|
@@ -81,7 +81,7 @@ module GetText
|
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
def add_target(val, file, line_no, targets)
|
|
84
|
+
def add_target(val, file, line_no, targets) # :nodoc:
|
|
85
85
|
return unless val.size > 0
|
|
86
86
|
assoc_data = targets.assoc(val)
|
|
87
87
|
val = CGI.unescapeHTML(val)
|
data/lib/gettext/parser/ruby.rb
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
You may redistribute it and/or modify it under the same
|
|
10
10
|
license terms as Ruby.
|
|
11
11
|
|
|
12
|
-
$Id: ruby.rb,v 1.
|
|
12
|
+
$Id: ruby.rb,v 1.6 2006/02/22 16:42:41 mutoh Exp $
|
|
13
13
|
=end
|
|
14
14
|
|
|
15
15
|
require 'irb/ruby-lex.rb'
|
|
16
16
|
require 'stringio'
|
|
17
17
|
|
|
18
|
-
class RubyLexX < RubyLex
|
|
18
|
+
class RubyLexX < RubyLex # :nodoc: all
|
|
19
19
|
|
|
20
20
|
def initialize
|
|
21
21
|
super
|
|
@@ -124,15 +124,15 @@ end
|
|
|
124
124
|
module GetText
|
|
125
125
|
module RubyParser
|
|
126
126
|
ID = ['gettext', '_', 'N_', 'sgettext', 's_']
|
|
127
|
-
PLURAL_ID = ['ngettext', 'n_']
|
|
127
|
+
PLURAL_ID = ['ngettext', 'n_', 'Nn_']
|
|
128
128
|
|
|
129
129
|
module_function
|
|
130
|
-
def parse(file, targets = [])
|
|
130
|
+
def parse(file, targets = []) # :nodoc:
|
|
131
131
|
lines = IO.readlines(file)
|
|
132
132
|
parse_lines(file, lines, targets)
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
def parse_lines(file_name, lines, targets)
|
|
135
|
+
def parse_lines(file_name, lines, targets) # :nodoc:
|
|
136
136
|
file = StringIO.new(lines.join + "\n")
|
|
137
137
|
rl = RubyLexX.new
|
|
138
138
|
rl.set_input(file)
|
|
@@ -188,7 +188,7 @@ module GetText
|
|
|
188
188
|
targets
|
|
189
189
|
end
|
|
190
190
|
|
|
191
|
-
def target?(file)
|
|
191
|
+
def target?(file) # :nodoc:
|
|
192
192
|
true # always true, as default parser.
|
|
193
193
|
end
|
|
194
194
|
|
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..ida44e3c5e28', 'src/poparser.ry', 90
|
|
24
24
|
include GetText
|
|
25
25
|
GetText.bindtextdomain("rgettext")
|
|
26
26
|
|
|
@@ -32,10 +32,11 @@ module_eval <<'..end src/poparser.ry modeval..id827ea1cb71', 'src/poparser.ry',
|
|
|
32
32
|
ret
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
def parse(str, data)
|
|
35
|
+
def parse(str, data, ignore_fuzzy = true)
|
|
36
36
|
@comments = []
|
|
37
37
|
@data = data
|
|
38
38
|
@fuzzy = false
|
|
39
|
+
$ignore_fuzzy = ignore_fuzzy
|
|
39
40
|
str.strip!
|
|
40
41
|
@q = []
|
|
41
42
|
until str.empty? do
|
|
@@ -92,7 +93,7 @@ module_eval <<'..end src/poparser.ry modeval..id827ea1cb71', 'src/poparser.ry',
|
|
|
92
93
|
|
|
93
94
|
def on_message(msgid, msgstr)
|
|
94
95
|
@data[msgid] = msgstr
|
|
95
|
-
|
|
96
|
+
|
|
96
97
|
@data.set_comment(msgid, @comments.join("\n"))
|
|
97
98
|
@comments.clear
|
|
98
99
|
end
|
|
@@ -102,7 +103,7 @@ module_eval <<'..end src/poparser.ry modeval..id827ea1cb71', 'src/poparser.ry',
|
|
|
102
103
|
@comments << comment
|
|
103
104
|
end
|
|
104
105
|
|
|
105
|
-
..end src/poparser.ry modeval..
|
|
106
|
+
..end src/poparser.ry modeval..ida44e3c5e28
|
|
106
107
|
|
|
107
108
|
##### racc 1.4.4 generates ###
|
|
108
109
|
|
|
@@ -217,7 +218,7 @@ Racc_debug_parser = true
|
|
|
217
218
|
|
|
218
219
|
module_eval <<'.,.,', 'src/poparser.ry', 36
|
|
219
220
|
def _reduce_4( val, _values, result )
|
|
220
|
-
if @fuzzy
|
|
221
|
+
if @fuzzy and $ignore_fuzzy
|
|
221
222
|
if val[1] != ""
|
|
222
223
|
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
223
224
|
$stderr.print " msgid '#{val[1]}'\n"
|
|
@@ -235,7 +236,7 @@ module_eval <<'.,.,', 'src/poparser.ry', 36
|
|
|
235
236
|
|
|
236
237
|
module_eval <<'.,.,', 'src/poparser.ry', 51
|
|
237
238
|
def _reduce_5( val, _values, result )
|
|
238
|
-
if @fuzzy
|
|
239
|
+
if @fuzzy and $ignore_fuzzy
|
|
239
240
|
if val[1] != ""
|
|
240
241
|
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
241
242
|
$stderr.print "msgid = '#{val[1]}\n"
|
data/lib/gettext/rails.rb
CHANGED
|
@@ -1,28 +1,53 @@
|
|
|
1
1
|
=begin
|
|
2
2
|
gettext/rails.rb - GetText for "Ruby on Rails"
|
|
3
3
|
|
|
4
|
-
Copyright (C) 2005 Masao Mutoh
|
|
4
|
+
Copyright (C) 2005,2006 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: rails.rb,v 1.
|
|
9
|
+
$Id: rails.rb,v 1.17 2006/02/23 14:53:59 mutoh Exp $
|
|
10
10
|
=end
|
|
11
11
|
|
|
12
|
-
require 'gettext'
|
|
13
12
|
require 'gettext/cgi'
|
|
14
13
|
require 'active_record'
|
|
15
14
|
require 'active_support'
|
|
16
15
|
|
|
17
|
-
module GetText
|
|
16
|
+
module GetText #:nodoc:
|
|
17
|
+
# = GetText for Ruby on Rails
|
|
18
|
+
# GetText::Rails supports Ruby on Rails.
|
|
19
|
+
# You add only 2 lines in your controller, all of the controller/view/models are
|
|
20
|
+
# targeted the textdomain.
|
|
21
|
+
#
|
|
22
|
+
# See <Ruby-GetText-Package HOWTO for Ruby on Rails (http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html>.
|
|
18
23
|
module Rails
|
|
19
24
|
include GetText
|
|
25
|
+
extend GetText
|
|
20
26
|
|
|
21
|
-
Rails = ::Rails
|
|
27
|
+
Rails = ::Rails #:nodoc:
|
|
22
28
|
|
|
23
|
-
alias :_bindtextdomain :bindtextdomain
|
|
29
|
+
alias :_bindtextdomain :bindtextdomain #:nodoc:
|
|
24
30
|
|
|
31
|
+
# Bind a textdomain(#{path}/#{locale}/LC_MESSAGES/#{domainname}.mo) to your program.
|
|
32
|
+
# Notes the textdomain scope becomes all of the controllers/views/models in your app.
|
|
33
|
+
# This is different from normal GetText.bindtextomain.
|
|
34
|
+
#
|
|
35
|
+
# Usually, you don't call this directly in your rails application.
|
|
36
|
+
# Call init_gettext in ActionController::Base instead.
|
|
37
|
+
#
|
|
38
|
+
# On the other hand, you need to call this in helpers/plugins.
|
|
39
|
+
#
|
|
40
|
+
# * domainname: the textdomain name.
|
|
41
|
+
# * locale: the locale value such as "ja-JP". When the value is nil,
|
|
42
|
+
# * charset: the charset. Generally UTF-8 is recommanded.
|
|
43
|
+
# * with_model: false if you want to ignore model support.
|
|
44
|
+
#
|
|
45
|
+
# locale is searched the order by this value > "lang" value of QUERY_STRING >
|
|
46
|
+
# "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
|
|
47
|
+
# And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
|
|
48
|
+
#
|
|
25
49
|
def bindtextdomain(domainname, _cgi = nil, locale = nil, charset = nil, with_model = true)
|
|
50
|
+
Locale.clear # IMPORTANT! current locale should be nil once(default is used).
|
|
26
51
|
set_cgi(_cgi) if _cgi
|
|
27
52
|
@gettext_container_domainname = domainname
|
|
28
53
|
path = File.join(RAILS_ROOT, "locale")
|
|
@@ -31,20 +56,20 @@ module GetText
|
|
|
31
56
|
bindtextdomain_to(ActiveRecord::Base, domainname) if with_model
|
|
32
57
|
end
|
|
33
58
|
|
|
34
|
-
def bindtextdomain_to(klass, domainname)
|
|
59
|
+
def bindtextdomain_to(klass, domainname) #:nodoc:
|
|
35
60
|
klass.class_eval {
|
|
36
61
|
textdomain(domainname)
|
|
37
62
|
|
|
38
|
-
def self.human_attribute_name(attribute_key_name)
|
|
63
|
+
def self.human_attribute_name(attribute_key_name) #:nodoc:
|
|
39
64
|
s_("#{self}|#{attribute_key_name.humanize}")
|
|
40
65
|
end
|
|
41
|
-
def self.human_attribute_table_name_for_error(table_name)
|
|
66
|
+
def self.human_attribute_table_name_for_error(table_name) #:nodoc:
|
|
42
67
|
_(table_name.gsub(/_/, " "))
|
|
43
68
|
end
|
|
44
69
|
}
|
|
45
70
|
end
|
|
46
71
|
|
|
47
|
-
def callersrc
|
|
72
|
+
def callersrc #:nodoc:
|
|
48
73
|
@gettext_container_domainname = nil unless defined? @gettext_container_domainname
|
|
49
74
|
@gettext_container_domainname
|
|
50
75
|
end
|
|
@@ -52,7 +77,7 @@ module GetText
|
|
|
52
77
|
end
|
|
53
78
|
|
|
54
79
|
|
|
55
|
-
module ActionController
|
|
80
|
+
module ActionController #:nodoc:
|
|
56
81
|
class Base
|
|
57
82
|
helper GetText::Rails
|
|
58
83
|
include GetText::Rails
|
|
@@ -62,13 +87,22 @@ module ActionController
|
|
|
62
87
|
@@gettext_content_type = nil
|
|
63
88
|
|
|
64
89
|
prepend_before_filter :init_gettext
|
|
65
|
-
|
|
66
|
-
|
|
90
|
+
after_filter :init_content_type
|
|
91
|
+
|
|
92
|
+
def init_gettext_main #:nodoc:
|
|
67
93
|
bindtextdomain(@@gettext_domainname, request.cgi) #You need to pass CGI object first.
|
|
68
|
-
@headers["Content-Type"] = "#{@@gettext_content_type}; charset=#{GetText.output_charset}"
|
|
69
94
|
end
|
|
70
95
|
|
|
71
|
-
def
|
|
96
|
+
def init_content_type #:nodoc:
|
|
97
|
+
if @headers["Content-Type"] and /javascript/ =~ @headers["Content-Type"]
|
|
98
|
+
@headers["Content-Type"] = "text/javascript; charset=#{GetText.output_charset}"
|
|
99
|
+
elsif ! @headers["Content-Type"]
|
|
100
|
+
@headers["Content-Type"] = "#{@@gettext_content_type}; charset=#{GetText.output_charset}"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def init_gettext # :nodoc:
|
|
72
106
|
init_gettext_main if @@gettext_domainname
|
|
73
107
|
ActiveRecord::Errors.class_eval{
|
|
74
108
|
# You need to call bindtextdomain here because ActiveRecord::Errors doesn't know
|
|
@@ -77,6 +111,21 @@ module ActionController
|
|
|
77
111
|
}
|
|
78
112
|
end
|
|
79
113
|
|
|
114
|
+
# Bind a 'textdomain' to all of the controllers/views/models. Call this instead of GetText.bindtextdomain.
|
|
115
|
+
# * textdomain: the textdomain
|
|
116
|
+
# * charset: the output charset. Default is "UTF-8"
|
|
117
|
+
# * content_type: the content type. Default is "text/html"
|
|
118
|
+
#
|
|
119
|
+
# If you want to separate the textdomain each controllers, you need to call this function in the each controllers.
|
|
120
|
+
#
|
|
121
|
+
# app/controller/blog_controller.rb:
|
|
122
|
+
# require 'gettext/rails'
|
|
123
|
+
#
|
|
124
|
+
# class BlogController < ApplicationController
|
|
125
|
+
# init_gettext "blog"
|
|
126
|
+
# :
|
|
127
|
+
# :
|
|
128
|
+
# end
|
|
80
129
|
def self.init_gettext(domainname, charset = "UTF-8", content_type = "text/html")
|
|
81
130
|
GetText.output_charset = charset
|
|
82
131
|
@@gettext_domainname = domainname
|
|
@@ -84,7 +133,7 @@ module ActionController
|
|
|
84
133
|
end
|
|
85
134
|
end
|
|
86
135
|
|
|
87
|
-
class TestRequest < AbstractRequest
|
|
136
|
+
class TestRequest < AbstractRequest #:nodoc:
|
|
88
137
|
@cgi = nil
|
|
89
138
|
def cgi
|
|
90
139
|
@cgi = CGI.new unless @cgi
|
|
@@ -93,18 +142,38 @@ module ActionController
|
|
|
93
142
|
end
|
|
94
143
|
end
|
|
95
144
|
|
|
96
|
-
module ActiveRecord
|
|
145
|
+
module ActiveRecord #:nodoc:
|
|
97
146
|
class Base
|
|
98
|
-
include GetText::Rails
|
|
99
|
-
extend GetText::Rails
|
|
100
|
-
|
|
147
|
+
include GetText::Rails # Important
|
|
148
|
+
extend GetText::Rails # Important
|
|
149
|
+
|
|
150
|
+
@@error_message_title = nil
|
|
151
|
+
@@error_message_explanation = nil
|
|
152
|
+
|
|
153
|
+
# Sets a your own title of error message dialog.
|
|
154
|
+
def self.set_error_message_title(single_msg, plural_msg)
|
|
155
|
+
@@error_message_title = [single_msg, plural_msg]
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Sets a your own explanation of the error message dialog.
|
|
159
|
+
def self.set_error_message_explanation(single_msg, plural_msg)
|
|
160
|
+
@@error_message_explanation = [single_msg, plural_msg]
|
|
161
|
+
end
|
|
101
162
|
|
|
102
|
-
|
|
163
|
+
def error_message_title #:nodoc:
|
|
164
|
+
@@error_message_title
|
|
165
|
+
end
|
|
166
|
+
def error_message_explanation #:nodoc:
|
|
167
|
+
@@error_message_explanation
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class Errors #:nodoc:
|
|
103
172
|
include GetText
|
|
104
173
|
extend GetText
|
|
105
174
|
|
|
106
|
-
RE_FIELD_NAME = /%\{fn\}/
|
|
107
|
-
|
|
175
|
+
RE_FIELD_NAME = /%\{fn\}/ #:nodoc:
|
|
176
|
+
|
|
108
177
|
# You need to define this here, because this values will be updated by application.
|
|
109
178
|
default_error_messages.update(
|
|
110
179
|
:inclusion => N_("%{fn} is not included in the list"),
|
|
@@ -120,22 +189,20 @@ module ActiveRecord
|
|
|
120
189
|
:taken => N_("%{fn} has already been taken"),
|
|
121
190
|
:not_a_number => N_("%{fn} is not a number")
|
|
122
191
|
)
|
|
123
|
-
|
|
124
192
|
@@default_error_messages_d = {
|
|
125
193
|
:too_long => default_error_messages[:too_long],
|
|
126
194
|
:too_short => default_error_messages[:too_short],
|
|
127
195
|
:wrong_length => default_error_messages[:wrong_length]
|
|
128
196
|
}
|
|
129
197
|
|
|
130
|
-
def self.convert_validates_messages_of_validates_length_of
|
|
198
|
+
def self.convert_validates_messages_of_validates_length_of #:nodoc:
|
|
131
199
|
default_error_messages[:too_long] = _(@@default_error_messages_d[:too_long])
|
|
132
200
|
default_error_messages[:too_short] = _(@@default_error_messages_d[:too_short])
|
|
133
201
|
default_error_messages[:wrong_length] = _(@@default_error_messages_d[:wrong_length])
|
|
134
202
|
end
|
|
135
203
|
|
|
136
|
-
def full_messages
|
|
204
|
+
def full_messages #:nodoc:
|
|
137
205
|
full_messages = []
|
|
138
|
-
|
|
139
206
|
@errors.each_key do |attr|
|
|
140
207
|
@errors[attr].each do |msg|
|
|
141
208
|
next if msg.nil?
|
|
@@ -152,8 +219,8 @@ module ActiveRecord
|
|
|
152
219
|
end
|
|
153
220
|
end
|
|
154
221
|
|
|
155
|
-
module Validations
|
|
156
|
-
module ClassMethods
|
|
222
|
+
module Validations #:nodoc:
|
|
223
|
+
module ClassMethods #:nodoc:
|
|
157
224
|
alias :_validates_length_of :validates_length_of
|
|
158
225
|
def validates_length_of(*attrs)
|
|
159
226
|
ActiveRecord::Errors.convert_validates_messages_of_validates_length_of
|
|
@@ -164,33 +231,44 @@ module ActiveRecord
|
|
|
164
231
|
end
|
|
165
232
|
|
|
166
233
|
|
|
167
|
-
module ActionView
|
|
168
|
-
module Helpers
|
|
169
|
-
module ActiveRecordHelper
|
|
234
|
+
module ActionView #:nodoc:
|
|
235
|
+
module Helpers #:nodoc:
|
|
236
|
+
module ActiveRecordHelper #:nodoc: all
|
|
170
237
|
module L10n
|
|
171
238
|
# Separate namespace for textdomain
|
|
172
239
|
include GetText
|
|
173
240
|
extend GetText
|
|
241
|
+
|
|
242
|
+
@error_message_title = Nn_("%{num} error prohibited this %{record} from being saved",
|
|
243
|
+
"%{num} errors prohibited this %{record} from being saved")
|
|
244
|
+
@error_message_explanation = Nn_("There was a problem with the following field:",
|
|
245
|
+
"There were problems with the following fields:")
|
|
246
|
+
|
|
174
247
|
module_function
|
|
248
|
+
def render_error_message(object, klass, record, count, options)
|
|
249
|
+
message_title = object.error_message_title || @error_message_title
|
|
250
|
+
message_explanation = object.error_message_explanation || @error_message_explanation
|
|
251
|
+
|
|
252
|
+
klass.content_tag("div",
|
|
253
|
+
klass.content_tag(
|
|
254
|
+
options[:header_tag] || "h2",
|
|
255
|
+
n_(message_title, count) % {:num => count, :record => record}
|
|
256
|
+
) +
|
|
257
|
+
klass.content_tag("p", n_(message_explanation, count) % {:num => count}) +
|
|
258
|
+
klass.content_tag("ul", object.errors.full_messages.collect { |msg| klass.content_tag("li", msg) }),
|
|
259
|
+
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
|
260
|
+
)
|
|
261
|
+
end
|
|
262
|
+
|
|
175
263
|
def error_messages_for(object, object_name, klass, options = {})
|
|
176
264
|
textdomain("rails")
|
|
177
265
|
|
|
178
266
|
options = options.symbolize_keys
|
|
179
|
-
|
|
267
|
+
|
|
180
268
|
unless object.errors.empty?
|
|
181
269
|
count = object.errors.count
|
|
182
270
|
record = ActiveRecord::Base.human_attribute_table_name_for_error(object_name)
|
|
183
|
-
|
|
184
|
-
klass.content_tag(
|
|
185
|
-
options[:header_tag] || "h2",
|
|
186
|
-
n_("%{num} error prohibited this %{record} from being saved",
|
|
187
|
-
"%{num} errors prohibited this %{record} from being saved", count) %
|
|
188
|
-
{:num => count, :record => record}) +
|
|
189
|
-
klass.content_tag("p", n_("There were problems with the following field:",
|
|
190
|
-
"There were problems with the following fields:", count)) +
|
|
191
|
-
klass.content_tag("ul", object.errors.full_messages.collect { |msg| klass.content_tag("li", msg) }),
|
|
192
|
-
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
|
193
|
-
)
|
|
271
|
+
render_error_message(object, klass, record, count, options)
|
|
194
272
|
end
|
|
195
273
|
end
|
|
196
274
|
end
|