r18n-core 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10 -0
- data/Rakefile +1 -1
- data/lib/r18n-core/filters.rb +6 -1
- data/lib/r18n-core/translated_string.rb +17 -4
- data/lib/r18n-core/translation.rb +21 -4
- data/lib/r18n-core/version.rb +1 -1
- data/lib/r18n-core/yaml_loader.rb +13 -8
- data/lib/r18n-core.rb +3 -1
- data/spec/filters_spec.rb +4 -2
- data/spec/translation_spec.rb +32 -0
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 1.1.0 (Leipzig)
|
2
|
+
* A lot of fixes in Rails I18n compatibility (thanks for Stephan Schubert).
|
3
|
+
* Return Untranslted, when user try to call another translation key on
|
4
|
+
already translated string.
|
5
|
+
* Add Translation#to_hash to get raw translation.
|
6
|
+
* Add Translation#inspect to easy debug.
|
7
|
+
* Return translation, when pluralization filter didn’t get count.
|
8
|
+
* Set R18n backend on Rails plugin init, to use it in console.
|
9
|
+
* Allow to use Fixnum in translation keys.
|
10
|
+
|
1
11
|
== 1.0.1 (Phuket Town)
|
2
12
|
* Fix translation reloading in Rails and Sinatra.
|
3
13
|
* Use global R18n settings for Sinatra extension.
|
data/Rakefile
CHANGED
data/lib/r18n-core/filters.rb
CHANGED
@@ -213,6 +213,10 @@ module R18n
|
|
213
213
|
eval("proc { #{content} }").call(*params)
|
214
214
|
end
|
215
215
|
|
216
|
+
# Class to mark unpluralized translation.
|
217
|
+
class UnpluralizetedTranslation < Translation
|
218
|
+
end
|
219
|
+
|
216
220
|
Filters.add('pl', :pluralization) do |content, config, param|
|
217
221
|
param = param.to_i if param.is_a? Float
|
218
222
|
if param.is_a? Numeric
|
@@ -220,7 +224,8 @@ module R18n
|
|
220
224
|
type = 'n' if not content.has_key? type
|
221
225
|
content[type]
|
222
226
|
else
|
223
|
-
|
227
|
+
UnpluralizetedTranslation.new(config[:locale], config[:path],
|
228
|
+
:locale => config[:locale], :translations => content)
|
224
229
|
end
|
225
230
|
end
|
226
231
|
|
@@ -29,10 +29,11 @@ module R18n
|
|
29
29
|
|
30
30
|
# Returns a new string object containing a copy of +str+, which translated
|
31
31
|
# for +path+ to +locale+
|
32
|
-
def initialize(str, locale, path)
|
32
|
+
def initialize(str, locale, path, filters = nil)
|
33
33
|
super(str)
|
34
|
-
@
|
35
|
-
@
|
34
|
+
@filters = filters
|
35
|
+
@locale = locale
|
36
|
+
@path = path
|
36
37
|
end
|
37
38
|
|
38
39
|
# Return self for translated string.
|
@@ -55,8 +56,20 @@ module R18n
|
|
55
56
|
if respond_to? :html_safe
|
56
57
|
html_safe
|
57
58
|
else
|
58
|
-
self
|
59
|
+
String.new(self)
|
59
60
|
end
|
60
61
|
end
|
62
|
+
|
63
|
+
# Return untranslated for deeper node `key`. It is in separated methods to
|
64
|
+
# be used in R18n I18n backend.
|
65
|
+
def get_untranslated(key)
|
66
|
+
translated = @path.empty? ? '' : "#{@path}."
|
67
|
+
Untranslated.new(translated, key, @locale, @filters)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Return untranslated, when user try to go deeper in translation.
|
71
|
+
def method_missing(name, *params)
|
72
|
+
get_untranslated(name.to_s)
|
73
|
+
end
|
61
74
|
end
|
62
75
|
end
|
@@ -94,7 +94,7 @@ module R18n
|
|
94
94
|
when String
|
95
95
|
c = { :locale => locale, :path => path }
|
96
96
|
v = @filters.process_string(:passive, value, c, [])
|
97
|
-
value = TranslatedString.new(v, locale, path)
|
97
|
+
value = TranslatedString.new(v, locale, path, @filters)
|
98
98
|
when Typed
|
99
99
|
value.locale = locale
|
100
100
|
value.path = path
|
@@ -115,9 +115,25 @@ module R18n
|
|
115
115
|
[@path, '', @path])
|
116
116
|
end
|
117
117
|
|
118
|
+
# Override inspect to easy debug.
|
119
|
+
def inspect
|
120
|
+
path = @path.empty? ? 'root' : "`#{@path}`"
|
121
|
+
"Translation #{path} for #{@locale.code} #{@data.inspect}"
|
122
|
+
end
|
123
|
+
|
118
124
|
# Return current translation keys.
|
125
|
+
#
|
126
|
+
# Deprecated. Use <tt>to_hash.keys</tt>.
|
119
127
|
def translation_keys
|
120
|
-
|
128
|
+
to_hash.keys
|
129
|
+
end
|
130
|
+
|
131
|
+
# Return hash of current translation node.
|
132
|
+
def to_hash
|
133
|
+
Utils.hash_map(@data) do |key, value|
|
134
|
+
value = value.to_hash if value.is_a? Translation
|
135
|
+
[key, value]
|
136
|
+
end
|
121
137
|
end
|
122
138
|
|
123
139
|
# Return +default+.
|
@@ -130,7 +146,8 @@ module R18n
|
|
130
146
|
# Translation can contain variable part. Just set is as <tt>%1</tt>,
|
131
147
|
# <tt>%2</tt>, etc in translations file and set values in next +params+.
|
132
148
|
def [](name, *params)
|
133
|
-
|
149
|
+
name = name.to_s if not name.is_a? String and not name.is_a? Fixnum
|
150
|
+
value = @data[name]
|
134
151
|
case value
|
135
152
|
when TranslatedString
|
136
153
|
@filters.process_string(:active, value, @path, params)
|
@@ -138,7 +155,7 @@ module R18n
|
|
138
155
|
@filters.process_typed(:active, value, params)
|
139
156
|
when nil
|
140
157
|
translated = @path.empty? ? '' : "#{@path}."
|
141
|
-
Untranslated.new(translated, name
|
158
|
+
Untranslated.new(translated, name, @locale, @filters)
|
142
159
|
else
|
143
160
|
value
|
144
161
|
end
|
data/lib/r18n-core/version.rb
CHANGED
@@ -89,14 +89,19 @@ module R18n
|
|
89
89
|
# Wrap YAML private types to Typed.
|
90
90
|
def transform(a_hash)
|
91
91
|
R18n::Utils.hash_map(a_hash) do |key, value|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
92
|
+
value = case value
|
93
|
+
when @private_type_class
|
94
|
+
v = value.value
|
95
|
+
if v.respond_to?(:force_encoding) and v.encoding != __ENCODING__
|
96
|
+
v = v.force_encoding(__ENCODING__)
|
97
|
+
end
|
98
|
+
Typed.new(value.type_id, v)
|
99
|
+
when Hash
|
100
|
+
transform(value)
|
101
|
+
else
|
102
|
+
value
|
103
|
+
end
|
104
|
+
[key, value]
|
100
105
|
end
|
101
106
|
end
|
102
107
|
end
|
data/lib/r18n-core.rb
CHANGED
@@ -29,9 +29,9 @@ require dir.join('locale').to_s
|
|
29
29
|
require dir.join('unsupported_locale').to_s
|
30
30
|
require dir.join('translated_string').to_s
|
31
31
|
require dir.join('untranslated').to_s
|
32
|
+
require dir.join('translation').to_s
|
32
33
|
require dir.join('filters').to_s
|
33
34
|
require dir.join('filter_list').to_s
|
34
|
-
require dir.join('translation').to_s
|
35
35
|
require dir.join('yaml_loader').to_s
|
36
36
|
require dir.join('i18n').to_s
|
37
37
|
require dir.join('helpers').to_s
|
@@ -84,6 +84,8 @@ module R18n
|
|
84
84
|
thread[:r18n_i18n] = thread[:r18n_setter] = @i18n = @setter = nil
|
85
85
|
clear_cache!
|
86
86
|
end
|
87
|
+
|
88
|
+
# Deprecated.
|
87
89
|
alias :reset :reset!
|
88
90
|
|
89
91
|
# Get the current thread.
|
data/spec/filters_spec.rb
CHANGED
@@ -153,8 +153,10 @@ describe R18n::Filters do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
it "shouldn't pluralize without first numeric parameter" do
|
156
|
-
@i18n.files.should
|
157
|
-
@i18n.files('').should
|
156
|
+
@i18n.files.should be_a(R18n::UnpluralizetedTranslation)
|
157
|
+
@i18n.files('').should be_a(R18n::UnpluralizetedTranslation)
|
158
|
+
@i18n.files[1].should == '1 file'
|
159
|
+
@i18n.files.n(5).should == '5 files'
|
158
160
|
end
|
159
161
|
|
160
162
|
it "should convert first float parameter to number" do
|
data/spec/translation_spec.rb
CHANGED
@@ -68,4 +68,36 @@ describe R18n::Translation do
|
|
68
68
|
translation.count(5).should == 'many'
|
69
69
|
end
|
70
70
|
|
71
|
+
it "should return hash of translations" do
|
72
|
+
i18n = R18n::I18n.new('en', DIR)
|
73
|
+
i18n.in.to_hash.should == {
|
74
|
+
'another' => { 'level' => 'Hierarchical' }
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return untranslated, when we go deeper string" do
|
79
|
+
en = R18n.locale('en')
|
80
|
+
translation = R18n::Translation.new(en, '',
|
81
|
+
:locale => en, :translations => { 'a' => 'A' })
|
82
|
+
|
83
|
+
translation.a.b.should be_a(R18n::Untranslated)
|
84
|
+
translation.a.b.translated_path.should == 'a.'
|
85
|
+
translation.a.b.untranslated_path.should == 'b'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should inspect translation" do
|
89
|
+
en = R18n.locale('en')
|
90
|
+
|
91
|
+
translation = R18n::Translation.new(en, 'a',
|
92
|
+
:locale => en, :translations => { 'a' => 'A' })
|
93
|
+
translation.inspect.should == 'Translation `a` for en {"a"=>"A"}'
|
94
|
+
|
95
|
+
translation = R18n::Translation.new(en, '',
|
96
|
+
:locale => en, :translations => { 'a' => 'A' })
|
97
|
+
translation.inspect.should == 'Translation root for en {"a"=>"A"}'
|
98
|
+
|
99
|
+
translation = R18n::Translation.new(en, '')
|
100
|
+
translation.inspect.should == 'Translation root for en {}'
|
101
|
+
end
|
102
|
+
|
71
103
|
end
|
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: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -297,7 +297,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
297
297
|
version: '0'
|
298
298
|
segments:
|
299
299
|
- 0
|
300
|
-
hash:
|
300
|
+
hash: 1266686224539252765
|
301
301
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
302
302
|
none: false
|
303
303
|
requirements:
|
@@ -306,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
306
306
|
version: '0'
|
307
307
|
segments:
|
308
308
|
- 0
|
309
|
-
hash:
|
309
|
+
hash: 1266686224539252765
|
310
310
|
requirements: []
|
311
311
|
rubyforge_project:
|
312
312
|
rubygems_version: 1.8.23
|