r18n-core 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/README.rdoc +6 -0
- data/lib/r18n-core/i18n.rb +1 -1
- data/lib/r18n-core/translated.rb +2 -4
- data/lib/r18n-core/translation.rb +5 -0
- data/lib/r18n-core/utils.rb +9 -0
- data/lib/r18n-core/version.rb +1 -1
- data/lib/r18n-core/yaml_loader.rb +8 -9
- data/spec/translation_spec.rb +5 -0
- metadata +2 -2
data/ChangeLog
CHANGED
data/README.rdoc
CHANGED
@@ -210,6 +210,12 @@ For untranslated strings you can set default value:
|
|
210
210
|
|
211
211
|
t.not.exists | 'default' #=> "default"
|
212
212
|
|
213
|
+
You can get translation keys, to analyze translation:
|
214
|
+
|
215
|
+
t.counties._keys.each do |county|
|
216
|
+
puts t.counties[county]
|
217
|
+
end
|
218
|
+
|
213
219
|
R18n already has translation for common words for most supported locales.
|
214
220
|
See <tt>base/</tt> in dir in gem.
|
215
221
|
|
data/lib/r18n-core/i18n.rb
CHANGED
@@ -256,7 +256,7 @@ module R18n
|
|
256
256
|
# Translation can contain variable part. Just set is as <tt>%1</tt>,
|
257
257
|
# <tt>%2</tt>, etc in translations file and set values as methods params.
|
258
258
|
def method_missing(name, *params)
|
259
|
-
@translation
|
259
|
+
@translation.send(name, *params)
|
260
260
|
end
|
261
261
|
|
262
262
|
# Return translation with special +name+.
|
data/lib/r18n-core/translated.rb
CHANGED
@@ -110,11 +110,9 @@ module R18n
|
|
110
110
|
# translation :desciption, :type => 'markdown'
|
111
111
|
def translation(name, options = {})
|
112
112
|
if options[:methods]
|
113
|
-
@unlocalized_getters[name] =
|
114
|
-
options[:methods].map { |l, i| [l.to_s, i.to_s] } ]
|
113
|
+
@unlocalized_getters[name] = R18n::Utils.hash_map(options[:methods]) { |l, i| [ l.to_s, i.to_s ] }
|
115
114
|
unless options[:no_write]
|
116
|
-
@unlocalized_setters[name] =
|
117
|
-
options[:methods].map { |l, i| [l.to_s, i.to_s + '='] } ]
|
115
|
+
@unlocalized_setters[name] =R18n::Utils.hash_map(options[:methods]) { |l, i| [ l.to_s, i.to_s + '=' ] }
|
118
116
|
end
|
119
117
|
end
|
120
118
|
|
data/lib/r18n-core/utils.rb
CHANGED
@@ -33,5 +33,14 @@ module R18n
|
|
33
33
|
def self.escape_html(content)
|
34
34
|
content.to_s.gsub(/[><&]/) { |s| HTML_ENTRIES[s] }
|
35
35
|
end
|
36
|
+
|
37
|
+
def self.hash_map(hash)
|
38
|
+
result = {}
|
39
|
+
hash.each_pair do |key, val|
|
40
|
+
new_key, new_value = yield key, val
|
41
|
+
result[new_key] = new_value
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
36
45
|
end
|
37
46
|
end
|
data/lib/r18n-core/version.rb
CHANGED
@@ -65,15 +65,14 @@ module R18n
|
|
65
65
|
end
|
66
66
|
|
67
67
|
# Wrap YAML private types to Typed.
|
68
|
-
def transform(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
}]
|
68
|
+
def transform(a_hash)
|
69
|
+
R18n::Utils.hash_map(a_hash) do |key, value|
|
70
|
+
[key, case value
|
71
|
+
when ::YAML::PrivateType then Typed.new(value.type_id, value.value)
|
72
|
+
when Hash then transform(value)
|
73
|
+
else value
|
74
|
+
end]
|
75
|
+
end
|
77
76
|
end
|
78
77
|
end
|
79
78
|
end
|
data/spec/translation_spec.rb
CHANGED
@@ -35,6 +35,11 @@ describe R18n::Translation do
|
|
35
35
|
i18n.not.untranslated_path.should == 'not'
|
36
36
|
i18n.not.translated_path.should == ''
|
37
37
|
end
|
38
|
+
|
39
|
+
it "should return translation keys" do
|
40
|
+
i18n = R18n::I18n.new('en', [DIR, TWO])
|
41
|
+
i18n.in._keys.should =~ ['another', 'two']
|
42
|
+
end
|
38
43
|
|
39
44
|
it "should return string with locale info" do
|
40
45
|
i18n = R18n::I18n.new(['no-LC', '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: 0.4.
|
4
|
+
version: 0.4.2
|
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-
|
12
|
+
date: 2010-02-19 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|