r18n-core 0.4.1 → 0.4.2

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 CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.4.2 (EMS)
2
+ * Fixes for Ruby 1.8.6 (by Akzhan Abdulin).
3
+ * Add method to get translation keys.
4
+
1
5
  == 0.4.1 (Lazy Boole)
2
6
  * Add passive filters.
3
7
  * Receive filter position as option Hash.
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
 
@@ -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[name, *params]
259
+ @translation.send(name, *params)
260
260
  end
261
261
 
262
262
  # Return translation with special +name+.
@@ -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] = Hash[
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] = Hash[
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
 
@@ -114,6 +114,11 @@ module R18n
114
114
  [@path, '', @path])
115
115
  end
116
116
 
117
+ # Return current translation keys.
118
+ def _keys
119
+ @data.keys
120
+ end
121
+
117
122
  # Return +default+.
118
123
  def |(default)
119
124
  default
@@ -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
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module R18n
3
- VERSION = '0.4.1' unless defined? R18n::VERSION
3
+ VERSION = '0.4.2' unless defined? R18n::VERSION
4
4
  end
@@ -65,15 +65,14 @@ module R18n
65
65
  end
66
66
 
67
67
  # Wrap YAML private types to Typed.
68
- def transform(hash)
69
- Hash[hash.map { |key, value|
70
- if value.is_a? ::YAML::PrivateType
71
- value = Typed.new(value.type_id, value.value)
72
- elsif value.is_a? Hash
73
- value = transform(value)
74
- end
75
- [key, value]
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
@@ -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.1
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-01-11 00:00:00 +03:00
12
+ date: 2010-02-19 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15