i18n-active_record 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/i18n/active_record/version.rb +1 -1
- data/lib/i18n/backend/active_record.rb +10 -2
- data/test/active_record_test.rb +13 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82f11d7fde969b3ef11eee86da2995a54d9f5c2c
|
4
|
+
data.tar.gz: fb23e1d54a386e6b856323cd1f222d9e0766b39d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b135f6d2c44c8e36c4856b60c287788d63b753dfe0991765062d4b416dfb587ef2b9e3e6ebae0b89fe9640017e4c57ecf78e6b566b4a871dbc5d14c1caea56fc
|
7
|
+
data.tar.gz: 49a3c2fc3b68f94298355a22ffe4547e3b8693ee2cf3f91faa2707e87bbfcc6e3ef259c25aab9363a8dfad0beec81627ebf06cfc543ea0f02fd7d78c63c33604
|
@@ -49,7 +49,11 @@ module I18n
|
|
49
49
|
|
50
50
|
def lookup(locale, key, scope = [], options = {})
|
51
51
|
key = normalize_flat_keys(locale, key, scope, options[:separator])
|
52
|
-
result =
|
52
|
+
result = if key == '.'
|
53
|
+
Translation.locale(locale).all
|
54
|
+
else
|
55
|
+
Translation.locale(locale).lookup(key)
|
56
|
+
end
|
53
57
|
|
54
58
|
if result.empty?
|
55
59
|
nil
|
@@ -65,7 +69,11 @@ module I18n
|
|
65
69
|
|
66
70
|
def build_translation_hash_by_key(lookup_key, translation)
|
67
71
|
hash = {}
|
68
|
-
|
72
|
+
if lookup_key == '.'
|
73
|
+
chop_range = 0..-1
|
74
|
+
else
|
75
|
+
chop_range = (lookup_key.size + FLATTEN_SEPARATOR.size)..-1
|
76
|
+
end
|
69
77
|
translation_nested_keys = translation.key.slice(chop_range).split(FLATTEN_SEPARATOR)
|
70
78
|
translation_nested_keys.each.with_index.inject(hash) do |iterator, (key, index)|
|
71
79
|
iterator[key] = translation_nested_keys[index + 1] ? {} : translation.value
|
data/test/active_record_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './test_helper'
|
2
2
|
|
3
3
|
class I18nBackendActiveRecordTest < I18n::TestCase
|
4
4
|
def setup
|
@@ -88,4 +88,16 @@ class I18nBackendActiveRecordTest < I18n::TestCase
|
|
88
88
|
expected_hash = { 'bar' => { 'fizz' => { 'buzz' => 'translation' } } }
|
89
89
|
assert_equal I18n.backend.send(:build_translation_hash_by_key, 'foo', translation), expected_hash
|
90
90
|
end
|
91
|
+
|
92
|
+
test "returning all keys via ." do
|
93
|
+
expected_hash = {:foo => { :bar => 'bar', :baz => 'baz' }}
|
94
|
+
assert_equal expected_hash, I18n.t('.')
|
95
|
+
end
|
96
|
+
|
97
|
+
test "returning all keys via . when there are no keys" do
|
98
|
+
I18n.t('.') # Fixes test flakiness by loading available locales
|
99
|
+
I18n::Backend::ActiveRecord::Translation.destroy_all
|
100
|
+
|
101
|
+
assert_equal "translation missing: en.no key", I18n.t('.')
|
102
|
+
end
|
91
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Fuchs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project: "[none]"
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.5.2
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: I18n ActiveRecord backend
|