r18n-rails-api 0.4 → 0.4.1
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/lib/r18n-rails-api/loader.rb +16 -13
- data/spec/data/simple/en.yml +1 -0
- data/spec/loader_spec.rb +6 -3
- metadata +3 -3
@@ -33,8 +33,8 @@ module R18n
|
|
33
33
|
# R18n::I18n.new('en',
|
34
34
|
# R18n::Loader::Rails.new(I18n::Backend::ActiveRecord.new))
|
35
35
|
class Rails
|
36
|
-
|
37
|
-
|
36
|
+
PLURAL_KEYS = { :zero => 0, :one => 1, :few => 2, :many => 'n',
|
37
|
+
:other => 'other' }
|
38
38
|
|
39
39
|
# Create new loader for some +backend+ from Rails I18n. Backend must have
|
40
40
|
# +reload!+, +init_translations+ and +translations+ methods.
|
@@ -76,18 +76,21 @@ module R18n
|
|
76
76
|
protected
|
77
77
|
|
78
78
|
# Change pluralization and keys to R18n format.
|
79
|
-
def transform(
|
80
|
-
if
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
[
|
85
|
-
|
86
|
-
|
79
|
+
def transform(value)
|
80
|
+
if value.is_a? Hash
|
81
|
+
if value.empty?
|
82
|
+
value
|
83
|
+
elsif value.keys.inject(true) { |a, i| a and PLURAL_KEYS.include? i }
|
84
|
+
R18n::Typed.new('pl', Hash[value.map { |k, v|
|
85
|
+
[PLURAL_KEYS[k], transform(v)]
|
86
|
+
}])
|
87
|
+
else
|
88
|
+
Hash[value.map { |k, v| [k.to_s, transform(v)] }]
|
89
|
+
end
|
90
|
+
elsif value.is_a? ::YAML::PrivateType
|
91
|
+
Typed.new(value.type_id, value.value)
|
87
92
|
else
|
88
|
-
|
89
|
-
[key.to_s, (value.is_a?(Hash) ? transform(value) : value)]
|
90
|
-
}]
|
93
|
+
value
|
91
94
|
end
|
92
95
|
end
|
93
96
|
end
|
data/spec/data/simple/en.yml
CHANGED
data/spec/loader_spec.rb
CHANGED
@@ -16,9 +16,12 @@ describe R18n::Loader::Rails do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should change pluralization" do
|
19
|
-
@loader.load(EN).should == {
|
20
|
-
|
21
|
-
|
19
|
+
@loader.load(EN).should == {
|
20
|
+
'users' => R18n::Typed.new('pl', {
|
21
|
+
0 => 'Zero', 1 => 'One', 2 => 'Few', 'n' => 'Many', 'other' => 'Other'
|
22
|
+
}),
|
23
|
+
'typed' => R18n::Typed.new('type', 'value')
|
24
|
+
}
|
22
25
|
end
|
23
26
|
|
24
27
|
it "should reload translations on load_path changes" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-rails-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey "A.I." Sitnik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-11 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 0.4.1
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: i18n
|