i18n_translation_spawner 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/i18n_translation_spawner.rb +9 -21
- metadata +3 -3
@@ -21,14 +21,6 @@ module I18n
|
|
21
21
|
|
22
22
|
lambda_accessor :translation_for_key, :file_path_decoder
|
23
23
|
|
24
|
-
#def translation_for_key(key, locale)
|
25
|
-
#if key_translations_handler.respond_to?(:call)
|
26
|
-
#key_translations_handler.call(key, locale, self)
|
27
|
-
#else
|
28
|
-
#default_translation_for_key(key, locale)
|
29
|
-
#end
|
30
|
-
#end
|
31
|
-
|
32
24
|
def translation(key, locale)
|
33
25
|
if translations_handler.respond_to?(:call)
|
34
26
|
translations_handler.call(key, locale, self)
|
@@ -37,22 +29,18 @@ module I18n
|
|
37
29
|
end
|
38
30
|
end
|
39
31
|
|
40
|
-
#def decode_file_path(key, locale)
|
41
|
-
#if file_path_decoder.respond_to?(:call)
|
42
|
-
#file_path_decoder.call(key, locale, self)
|
43
|
-
#else
|
44
|
-
#default_decode_file_path(key, locale)
|
45
|
-
#end
|
46
|
-
#end
|
47
|
-
|
48
32
|
def spawn_translation_key(key, locale, options, exception)
|
49
33
|
I18n.available_locales.reject { |l| skip_locales.map(&:to_s).include?(l.to_s) }.each do |_locale|
|
50
34
|
begin
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
35
|
+
begin
|
36
|
+
I18n.translate(key, options.merge({:locale => _locale, :raise => true}))
|
37
|
+
rescue I18n::MissingTranslationData
|
38
|
+
file_path_decoder(key, _locale).tap do |path|
|
39
|
+
translations_hash = YAML::load_file(path)
|
40
|
+
hash_to_merge = "#{_locale.to_s}.#{key}".to_hash(translation(key, _locale.to_s)).deep_stringify_keys!
|
41
|
+
translations_hash = translations_hash.deep_merge(hash_to_merge).to_ordered_hash
|
42
|
+
File.open(path, 'w') { |f| f.write(YAML.unescape(translations_hash.ya2yaml.sub(/---\s*/, ''))) }
|
43
|
+
end
|
56
44
|
end
|
57
45
|
rescue CannotDecodeTranslationFilePath
|
58
46
|
if cannot_decode_translation_file_path_handler.respond_to?(:call)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_translation_spawner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "B\xC5\x82a\xC5\xBCej --Stevo-- Kosmowski"
|