chipairon-i18n-active_record 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a21451f4f0606b0ece514ef310c4b6b1f173f15d
4
- data.tar.gz: 0db34961a29760d60c8c440e4792b3eed056d1d9
3
+ metadata.gz: 798056b0e6fbacf7b98182202e34af8e23e16585
4
+ data.tar.gz: cc430df424903e741138ef98d78c95224738a4cc
5
5
  SHA512:
6
- metadata.gz: 4b17dbb4cbacaa33ad46af65a66bc0a4ef1b0c1f6e9f67d0044f7549d9a39ddc4b0c402de96b6c2f54b2a482f6b3065cc20cf7d0888b26a663a4bc8b05234f14
7
- data.tar.gz: aa4e52a831e4f7ccd2a38f18d71e16ffb37fa49f1cfdd4c795b4258c671ee794c933009c68878810e14898f888ab34c0244f71d0b8cacc2de46b7845c7c06ef9
6
+ metadata.gz: 5f8daec77a6c348cd500bd0dd63c5df0b9a36f079fd753bae1ba6e3f41a6eff07765432a9c3c16199316b697e79a4e34f951124acf7bdd64b2f154c17b70fa29
7
+ data.tar.gz: deb3bcf0c44a4d7bfc479d11537eb3417a3b34424131addafed1d6c98e3dfe0fe789b3e28ca1f8d78a11626b6d6784413974aa779cc6d5808ceb4676799091cd
@@ -1,6 +1,6 @@
1
1
  module I18n
2
2
  module ActiveRecord
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
6
6
 
@@ -41,23 +41,23 @@ module I18n
41
41
  key = normalize_flat_keys(locale, key, scope, separator)
42
42
  interpolations = options.keys - I18n::RESERVED_KEYS
43
43
 
44
- # if already memoized, then a record already exists.
45
- if @memoized_lookup and @memoized_lookup[locale.to_sym].keys.include? key.to_sym
46
- return
47
- end
48
-
49
- if I18n::available_locales.any?
50
- I18n::available_locales.each do |a_locale|
51
- store_if_not_exists(a_locale, key, interpolations, count)
44
+ unless ActiveRecord::Translation.locale(locale).lookup(key).exists?
45
+ if I18n::available_locales.any?
46
+ I18n::available_locales.each do |a_locale|
47
+ store_if_not_exists(a_locale, key, interpolations, count)
48
+ end
49
+ else
50
+ store_if_not_exists(locale, key, interpolations, count)
52
51
  end
53
- else
54
- store_if_not_exists(locale, key, interpolations, count)
52
+ # if memoization is included, this refreshes the hash to get new values just stored
53
+ try(:reload!)
55
54
  end
56
55
  end
57
56
 
58
57
  def store_default_translation(locale, key, interpolations)
59
58
  translation = ActiveRecord::Translation.new :locale => locale.to_s, :key => key
60
59
  translation.interpolations = interpolations
60
+ translation.value = get_value_from_simple_backend(locale, key)
61
61
  translation.save
62
62
  end
63
63
 
@@ -85,6 +85,18 @@ module I18n
85
85
  end
86
86
  plurals
87
87
  end
88
+
89
+ private
90
+ # Check if this backend is chainning with simple
91
+ # then try to get value from its hash.
92
+ def get_value_from_simple_backend(locale, key)
93
+ if I18n.backend.class == Chain &&
94
+ I18n.backend.backends.last.class == Simple
95
+ I18n.backend.backends.last.send(:lookup, locale, key)
96
+ else
97
+ nil
98
+ end
99
+ end
88
100
  end
89
101
  end
90
102
  end
@@ -41,6 +41,7 @@ module I18n
41
41
  key = normalize_flat_keys(locale, key, scope, separator)
42
42
  interpolations = options.keys - I18n::RESERVED_KEYS
43
43
 
44
+ <<<<<<< HEAD
44
45
  # if already memoized, then a record already exists.
45
46
  if @memoized_lookup and @memoized_lookup[locale.to_sym].keys.include? key.to_sym
46
47
  return
@@ -52,24 +53,22 @@ module I18n
52
53
  end
53
54
  else
54
55
  store_if_not_exists(locale, key, interpolations, count)
55
- end
56
- end
57
-
58
- def store_if_not_exists(locale, key, interpolations, count)
59
- unless ActiveRecord::Translation.locale(locale).lookup(key).exists?
60
- <<<<<<< HEAD
61
- keys = count ? I18n.t('i18n.plural.keys', :locale => locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key]
62
56
  =======
57
+ unless ActiveRecord::Translation.locale(locale).lookup(key).exists?
63
58
  interpolations = options.keys - I18n::RESERVED_KEYS
64
- keys = count ? get_plurals(locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key]
65
- >>>>>>> e4d6427a8d4550e773199bef8410dcbe5f175f62
59
+ keys = count ? I18n.t('i18n.plural.keys', :locale => locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key]
66
60
  keys.each { |key| store_default_translation(locale, key, interpolations) }
61
+
62
+ # if memoization is included, this refreshes the hash to get new values just stored
63
+ try(:reload!)
64
+ >>>>>>> 5dfbeffc11eed8fb7cf0313fa6288d34417bf38d
67
65
  end
68
66
  end
69
67
 
70
68
  def store_default_translation(locale, key, interpolations)
71
69
  translation = ActiveRecord::Translation.new :locale => locale.to_s, :key => key
72
70
  translation.interpolations = interpolations
71
+ translation.value = get_value_from_simple_backend(locale, key)
73
72
  translation.save
74
73
  end
75
74
 
@@ -80,6 +79,15 @@ module I18n
80
79
  end
81
80
 
82
81
  private
82
+ <<<<<<< HEAD
83
+
84
+ def store_if_not_exists(locale, key, interpolations, count)
85
+ unless ActiveRecord::Translation.locale(locale).lookup(key).exists?
86
+ keys = count ? get_plurals(locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key]
87
+ keys.each { |key| store_default_translation(locale, key, interpolations) }
88
+ end
89
+ end
90
+
83
91
  # get plural rules or use English rules as default:
84
92
  def get_plurals(locale)
85
93
  plurals = I18n.t('i18n.plural.keys', :locale => locale)
@@ -88,6 +96,17 @@ module I18n
88
96
  plurals = [:zero, :one, :other]
89
97
  end
90
98
  plurals
99
+ =======
100
+ # Check if this backend is chainning with simple
101
+ # then try to get value from its hash.
102
+ def get_value_from_simple_backend(locale, key)
103
+ if I18n.backend.class == Chain &&
104
+ I18n.backend.backends.last.class == Simple
105
+ I18n.backend.backends.last.send(:lookup, locale, key)
106
+ else
107
+ nil
108
+ end
109
+ >>>>>>> 5dfbeffc11eed8fb7cf0313fa6288d34417bf38d
91
110
  end
92
111
  end
93
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chipairon-i18n-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2013-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n