r18n-core 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -5
- data/Rakefile +7 -6
- data/base/eo.yml +7 -0
- data/lib/r18n-core/i18n.rb +5 -3
- data/lib/r18n-core/locale.rb +6 -2
- data/lib/r18n-core/translation.rb +22 -2
- data/lib/r18n-core/version.rb +3 -0
- data/lib/r18n-core.rb +2 -1
- data/locales/en.yml +5 -5
- data/locales/en_US.yml +9 -0
- data/locales/eo.yml +34 -0
- data/spec/i18n_spec.rb +5 -1
- data/spec/locale_spec.rb +2 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/translation_spec.rb +8 -2
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -7,11 +7,12 @@ Use <tt>merb_r18n</tt> to localize Merb Web application and
|
|
7
7
|
|
8
8
|
== Features
|
9
9
|
|
10
|
-
*
|
10
|
+
* It has special support for countries with two official languages. If there
|
11
|
+
isn’t translation in user locale, it will be found in locales, which
|
11
12
|
user may know (not only in default locale). For example, many people in
|
12
13
|
Belarus can understand Russian, and locale has information about it.
|
13
|
-
* It can
|
14
|
-
|
14
|
+
* It can format numbers and time to the rules of the user locale, translate
|
15
|
+
month and week days name and give other locale information.
|
15
16
|
* It has translation for commons words, like “OK”, “Cancel”, etc.
|
16
17
|
* It storage translation in rich YAML format. You can put procedures and
|
17
18
|
pluralization (“1 comment”, “5 comments”) in your translation.
|
@@ -117,8 +118,8 @@ You can translate months and week days names in Time, Date and DateTime by
|
|
117
118
|
|
118
119
|
i18n.l Time.now, "%B" #=> "September"
|
119
120
|
|
120
|
-
R18n has some time formats for locales: <tt>:
|
121
|
-
<tt>:short_data</tt>, <tt>:long_data</tt>, <tt>:datetime</tt>,
|
121
|
+
R18n has some time formats for locales: <tt>:month</tt>, <tt>:time</tt>,
|
122
|
+
<tt>:date</tt>, <tt>:short_data</tt>, <tt>:long_data</tt>, <tt>:datetime</tt>,
|
122
123
|
<tt>:short_datetime</tt> and <tt>:long_datetime</tt>:
|
123
124
|
|
124
125
|
i18n.l Time.now, :date #=> "09/21/2008"
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
|
|
4
4
|
require 'spec/rake/spectask'
|
5
5
|
|
6
6
|
PKG_NAME = 'r18n-core'
|
7
|
-
|
7
|
+
require 'lib/r18n-core/version'
|
8
8
|
|
9
9
|
##############################################################################
|
10
10
|
# Tests
|
@@ -54,13 +54,14 @@ end
|
|
54
54
|
spec = Gem::Specification.new do |s|
|
55
55
|
s.platform = Gem::Platform::RUBY
|
56
56
|
s.name = PKG_NAME
|
57
|
-
s.version =
|
57
|
+
s.version = R18n::VERSION
|
58
58
|
s.summary = 'I18n tool to translate your Ruby application.'
|
59
59
|
s.description = <<-EOF
|
60
60
|
R18n is a i18n tool to translate your Ruby application.
|
61
|
-
It can
|
62
|
-
storage translation in
|
63
|
-
and has
|
61
|
+
It can format numbers and time to the rules of the user locale,
|
62
|
+
has translation for common words, storage translation in YAML format with
|
63
|
+
pluralization and procedures and has special support for countries
|
64
|
+
with two official languages.
|
64
65
|
EOF
|
65
66
|
|
66
67
|
s.files = FileList[
|
@@ -89,5 +90,5 @@ end
|
|
89
90
|
desc 'Install as a gem'
|
90
91
|
task :install => [:package] do
|
91
92
|
sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
|
92
|
-
sh %{#{sudo} gem install pkg/#{PKG_NAME}-#{
|
93
|
+
sh %{#{sudo} gem install pkg/#{PKG_NAME}-#{R18n::VERSION}}
|
93
94
|
end
|
data/base/eo.yml
ADDED
data/lib/r18n-core/i18n.rb
CHANGED
@@ -101,7 +101,7 @@ module R18n
|
|
101
101
|
# (it will load +fr+ for +fr_CA+ too).
|
102
102
|
#
|
103
103
|
# +Locales+ must be a locale code (RFC 3066) or array, ordered by priority.
|
104
|
-
def initialize(locales, translations_dir)
|
104
|
+
def initialize(locales, translations_dir = nil)
|
105
105
|
locales = locales.to_a if String == locales.class
|
106
106
|
|
107
107
|
@locales = locales.map do |locale|
|
@@ -130,8 +130,10 @@ module R18n
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
|
134
|
-
|
133
|
+
if not translations_dir.nil?
|
134
|
+
@translations_dir = File.expand_path(translations_dir)
|
135
|
+
@translation = Translation.load(locales, @translations_dir)
|
136
|
+
end
|
135
137
|
end
|
136
138
|
|
137
139
|
# Return Hash with titles (or code for translation without locale file) of
|
data/lib/r18n-core/locale.rb
CHANGED
@@ -133,10 +133,14 @@ module R18n
|
|
133
133
|
# names. In +time+ you can use Time, DateTime or Date object. In +format+
|
134
134
|
# you can use String with standart +strftime+ format (see
|
135
135
|
# <tt>Time.strftime</tt> docs) or Symbol with format from locale file
|
136
|
-
# (<tt>:
|
137
|
-
# <tt>:
|
136
|
+
# (<tt>:month</tt>, <tt>:time</tt>, <tt>:date</tt>, <tt>:short_data</tt>,
|
137
|
+
# <tt>:long_data</tt>, <tt>:datetime</tt>, <tt>:short_datetime</tt> or
|
138
|
+
# <tt>:long_datetime</tt>).
|
138
139
|
def strftime(time, format)
|
139
140
|
if Symbol == format.class
|
141
|
+
if :month == format
|
142
|
+
return @locale['months']['standalone'][time.month - 1]
|
143
|
+
end
|
140
144
|
format = @locale['formats'][format.to_s]
|
141
145
|
end
|
142
146
|
|
@@ -32,10 +32,13 @@ module R18n
|
|
32
32
|
# write <tt>%1</tt>, <tt>%2</tt>, etc and set it values as method arguments,
|
33
33
|
# when you will be get value.
|
34
34
|
#
|
35
|
+
# If in your system procedures in translations willn’t be secure (user can
|
36
|
+
# upoad or edit it) set <tt>R18n::Translation.call_proc</tt> to false.
|
37
|
+
#
|
35
38
|
# To get translation value use method with same name. If translation name
|
36
39
|
# is equal with Object methods (+new+, +to_s+, +methods+) use
|
37
40
|
# <tt>[name, params…]</tt>. If you want to get pluralizable value, just set
|
38
|
-
# value for pluralization in
|
41
|
+
# value for pluralization in first argument of method. See samples below.
|
39
42
|
#
|
40
43
|
# Translated strings will have +locale+ methods, which return Locale or it
|
41
44
|
# code, if locale file isn’t exists.
|
@@ -93,6 +96,8 @@ module R18n
|
|
93
96
|
class Translation
|
94
97
|
@@extension_translations = [
|
95
98
|
Pathname(__FILE__).dirname.expand_path + '../../base']
|
99
|
+
|
100
|
+
@@call_proc = true
|
96
101
|
|
97
102
|
# Get dirs with extension translations. If application translations with
|
98
103
|
# same locale isn’t exists, extension file willn’t be used.
|
@@ -135,6 +140,17 @@ module R18n
|
|
135
140
|
self.new(locales, translations)
|
136
141
|
end
|
137
142
|
|
143
|
+
# Is procedures in translations will be call. Set to false if user can
|
144
|
+
# upload or edit translations.
|
145
|
+
def self.call_proc=(call)
|
146
|
+
@@call_proc = call
|
147
|
+
end
|
148
|
+
|
149
|
+
# Is procedures in translations will be call
|
150
|
+
def self.call_proc
|
151
|
+
@@call_proc
|
152
|
+
end
|
153
|
+
|
138
154
|
# Create translation hash with messages in +translations+ for +locales+.
|
139
155
|
#
|
140
156
|
# This is internal a constructor. To load translation use
|
@@ -166,7 +182,11 @@ module R18n
|
|
166
182
|
if YAML::PrivateType == result.class
|
167
183
|
case result.type_id
|
168
184
|
when 'proc'
|
169
|
-
|
185
|
+
if @@call_proc
|
186
|
+
return eval("proc {#{result.value}}").call(*params)
|
187
|
+
else
|
188
|
+
return nil
|
189
|
+
end
|
170
190
|
when 'pl'
|
171
191
|
locale = @locales[i]
|
172
192
|
|
data/lib/r18n-core.rb
CHANGED
@@ -20,8 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
$KCODE = 'u'
|
21
21
|
|
22
22
|
require 'pathname'
|
23
|
-
dir = Pathname(__FILE__).dirname.expand_path + 'r18n-core'
|
24
23
|
|
24
|
+
dir = Pathname(__FILE__).dirname.expand_path + 'r18n-core'
|
25
|
+
require dir + 'version'
|
25
26
|
require dir + 'locale'
|
26
27
|
require dir + 'translated_string'
|
27
28
|
require dir + 'translation'
|
data/locales/en.yml
CHANGED
@@ -21,12 +21,12 @@ time:
|
|
21
21
|
|
22
22
|
formats:
|
23
23
|
time: "%H:%M"
|
24
|
-
date: "%m/%
|
25
|
-
short_date: "%
|
26
|
-
long_date: "%
|
27
|
-
datetime: "%a %
|
24
|
+
date: "%d/%m/%Y"
|
25
|
+
short_date: "%d %b"
|
26
|
+
long_date: "%d %B, %Y"
|
27
|
+
datetime: "%a %d %b %H:%M:%S %Z %Y"
|
28
28
|
short_datetime: "%d %b %H:%M"
|
29
|
-
long_datetime: "%
|
29
|
+
long_datetime: "%d %B, %Y %H:%M"
|
30
30
|
|
31
31
|
numbers:
|
32
32
|
separation: classic
|
data/locales/en_US.yml
CHANGED
@@ -3,3 +3,12 @@ include: en
|
|
3
3
|
code: en_US
|
4
4
|
title: English (US)
|
5
5
|
sublocales: [en]
|
6
|
+
|
7
|
+
formats:
|
8
|
+
time: "%H:%M"
|
9
|
+
date: "%m/%d/%Y"
|
10
|
+
short_date: "%b %d"
|
11
|
+
long_date: "%B %d, %Y"
|
12
|
+
datetime: "%a %b %d %H:%M:%S %Z %Y"
|
13
|
+
short_datetime: "%b %d %H:%M"
|
14
|
+
long_datetime: "%B %d, %Y %H:%M"
|
data/locales/eo.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
title: Esperanto
|
2
|
+
code: eo
|
3
|
+
sublocales: [en]
|
4
|
+
direction: ltr
|
5
|
+
|
6
|
+
pluralization: "n == 0 ? 0 : n == 1 ? 1 : 'n'"
|
7
|
+
|
8
|
+
week:
|
9
|
+
start: monday
|
10
|
+
days: [dimanĉo, lundo, mardo, merkredo, ĵaŭdo, vendredo, sabato]
|
11
|
+
abbrs: [dim, lun, mar, mer, ĵaŭ, ven, seb]
|
12
|
+
|
13
|
+
months:
|
14
|
+
names: [januaro, februaro, marto, aprilo, majo, junio, julio, aŭgusto, septembro, oktobro, novembro, decembro]
|
15
|
+
abbrs: [jan, feb, mar, apr, maj, jun, jul, aŭg, sep, okt, nov, dec]
|
16
|
+
standalone: [januaro, februaro, marto, aprilo, majo, junio, julio, aŭgusto, septembro, oktobro, novembro, decembro]
|
17
|
+
|
18
|
+
time:
|
19
|
+
am: AM
|
20
|
+
pm: PM
|
21
|
+
|
22
|
+
formats:
|
23
|
+
time: "%H:%M"
|
24
|
+
date: "%Y-%m-%d"
|
25
|
+
short_date: "%d %b"
|
26
|
+
long_date: "la %d-a de %B de %Y"
|
27
|
+
datetime: "%a, %d %b %Y, %H:%M:%S %Z"
|
28
|
+
short_datetime: "%d %b, %H:%M"
|
29
|
+
long_datetime: "la %d-a de %B de %Y, %H:%M"
|
30
|
+
|
31
|
+
numbers:
|
32
|
+
separation: classic
|
33
|
+
decimal_separator: "."
|
34
|
+
group_delimiter: " "
|
data/spec/i18n_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
describe R18n::I18n do
|
4
|
-
DIR = Pathname(__FILE__).dirname + 'translations/general'
|
5
4
|
|
6
5
|
it "should parse HTTP_ACCEPT_LANGUAGE" do
|
7
6
|
R18n::I18n.parse_http(nil).should == []
|
@@ -74,5 +73,10 @@ describe R18n::I18n do
|
|
74
73
|
|
75
74
|
i18n.l(Date.new(0)).should == '01.01.0000'
|
76
75
|
end
|
76
|
+
|
77
|
+
it "should loading without translations" do
|
78
|
+
i18n = R18n::I18n.new('ru')
|
79
|
+
i18n.l(Date.new(0)).should == '01.01.0000'
|
80
|
+
end
|
77
81
|
|
78
82
|
end
|
data/spec/locale_spec.rb
CHANGED
@@ -40,7 +40,7 @@ describe R18n::Locale do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should return all available locales" do
|
43
|
-
R18n::Locale.available.sort.should == ['en', 'en_US', 'ru']
|
43
|
+
R18n::Locale.available.sort.should == ['en', 'en_US', 'eo', 'ru']
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should return pluralization type by elements count" do
|
@@ -77,6 +77,7 @@ describe R18n::Locale do
|
|
77
77
|
locale.strftime(time, '%b %B').should == 'янв января'
|
78
78
|
locale.strftime(time, '%H:%M%p').should == '00:00 утра'
|
79
79
|
|
80
|
+
locale.strftime(time, :month).should == 'Январь'
|
80
81
|
locale.strftime(time, :datetime).should == 'Чтв, 01 янв 1970, 00:00:00 GMT'
|
81
82
|
end
|
82
83
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/translation_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
describe R18n::Translation do
|
4
|
-
DIR = Pathname(__FILE__).dirname + 'translations/general'
|
5
|
-
EXT = Pathname(__FILE__).dirname + 'translations/extension'
|
6
4
|
|
7
5
|
it "should return all available translations" do
|
8
6
|
R18n::Translation.available(DIR).sort.should == ['en', 'no_LC', 'ru']
|
@@ -63,6 +61,14 @@ describe R18n::Translation do
|
|
63
61
|
translation = R18n::Translation.load('en', DIR)
|
64
62
|
translation.sum(2, 3).should == 5
|
65
63
|
end
|
64
|
+
|
65
|
+
it "shouldn't call proc if it isn't secure" do
|
66
|
+
translation = R18n::Translation.load('en', DIR)
|
67
|
+
R18n::Translation.call_proc = false
|
68
|
+
R18n::Translation.call_proc.should be_false
|
69
|
+
translation.sum(2, 3).should be_nil
|
70
|
+
R18n::Translation.call_proc = true
|
71
|
+
end
|
66
72
|
|
67
73
|
it "should pluralize translation" do
|
68
74
|
translation = R18n::Translation.load('en', DIR)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey "A.I." Sitnik
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
12
|
+
date: 2008-11-23 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: R18n is a i18n tool to translate your Ruby application. It can
|
16
|
+
description: R18n is a i18n tool to translate your Ruby application. It can format numbers and time to the rules of the user locale, has translation for common words, storage translation in YAML format with pluralization and procedures and has special support for countries with two official languages.
|
17
17
|
email: andrey@sitnik.ru
|
18
18
|
executables: []
|
19
19
|
|
@@ -24,15 +24,18 @@ extra_rdoc_files:
|
|
24
24
|
- LICENSE
|
25
25
|
files:
|
26
26
|
- base/ru.yml
|
27
|
+
- base/eo.yml
|
27
28
|
- base/en.yml
|
28
29
|
- lib/r18n-core.rb
|
29
30
|
- lib/r18n-core
|
30
31
|
- lib/r18n-core/translation.rb
|
31
32
|
- lib/r18n-core/translated_string.rb
|
32
33
|
- lib/r18n-core/locale.rb
|
34
|
+
- lib/r18n-core/version.rb
|
33
35
|
- lib/r18n-core/i18n.rb
|
34
36
|
- locales/en_US.yml
|
35
37
|
- locales/ru.yml
|
38
|
+
- locales/eo.yml
|
36
39
|
- locales/en.yml
|
37
40
|
- LICENSE
|
38
41
|
- Rakefile
|