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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4702ca87d86eb911ba7bb1a625d3db8c9837120
4
- data.tar.gz: 035751e1098ef51b85d91d85edcc4279691386e1
3
+ metadata.gz: 82f11d7fde969b3ef11eee86da2995a54d9f5c2c
4
+ data.tar.gz: fb23e1d54a386e6b856323cd1f222d9e0766b39d
5
5
  SHA512:
6
- metadata.gz: 0ef662d17a2c8d1ae4e02a31b0e55892357835aaaa6bf8deecae803b21d835015b88b5c13c970f64b2310430e4d11cf6ee074ef364dd8ef76b5e199b041eaf62
7
- data.tar.gz: a1ea9dc58acb19f24fd1f22ddcc8cbcb86351ac1b6a5c89baae0ac51599cf91a130fd0194621dd8e40a4019537173b44c60c590f6e46c51d5a7dc462749ab62c
6
+ metadata.gz: b135f6d2c44c8e36c4856b60c287788d63b753dfe0991765062d4b416dfb587ef2b9e3e6ebae0b89fe9640017e4c57ecf78e6b566b4a871dbc5d14c1caea56fc
7
+ data.tar.gz: 49a3c2fc3b68f94298355a22ffe4547e3b8693ee2cf3f91faa2707e87bbfcc6e3ef259c25aab9363a8dfad0beec81627ebf06cfc543ea0f02fd7d78c63c33604
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module ActiveRecord
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -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 = Translation.locale(locale).lookup(key)
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
- chop_range = (lookup_key.size + FLATTEN_SEPARATOR.size)..-1
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
@@ -1,4 +1,4 @@
1
- require 'test_helper'
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.0
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-03-21 00:00:00.000000000 Z
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.6.7
82
+ rubygems_version: 2.5.2
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: I18n ActiveRecord backend