i18n_translation_spawner 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/i18n_translation_spawner.rb +14 -10
- metadata +3 -3
@@ -8,13 +8,17 @@ module I18n
|
|
8
8
|
class CannotDecodeTranslationFilePath < StandardError;
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
attr_accessor_with_default :default_translations, {}
|
14
|
-
attr_accessor :exception_handler, :key_translations_handler, :translations_handler, :file_path_decoder, :cannot_decode_translation_file_path_handler
|
11
|
+
attr_accessor :skip_locales, :removable_prefixes, :default_translations, :exception_handler, :key_translations_handler,
|
12
|
+
:translations_handler, :file_path_decoder, :cannot_decode_translation_file_path_handler
|
15
13
|
|
16
14
|
private
|
17
15
|
|
16
|
+
def initialize
|
17
|
+
@skip_locales = []
|
18
|
+
@removable_prefixes = []
|
19
|
+
@default_translations = {}
|
20
|
+
end
|
21
|
+
|
18
22
|
def translation_for_key(key, locale)
|
19
23
|
if key_translations_handler.respond_to?(:call)
|
20
24
|
key_translations_handler.call(key, locale, self)
|
@@ -46,11 +50,11 @@ module I18n
|
|
46
50
|
translations_hash = YAML::load_file(path)
|
47
51
|
hash_to_merge = "#{_locale.to_s}.#{key}".to_hash(translation(key, _locale.to_s)).deep_stringify_keys!
|
48
52
|
translations_hash = translations_hash.deep_merge(hash_to_merge).to_ordered_hash
|
49
|
-
File.open(path, 'w') { |f| f.write(YAML.unescape(translations_hash.ya2yaml.sub(/---\s*/,''))) }
|
53
|
+
File.open(path, 'w') { |f| f.write(YAML.unescape(translations_hash.ya2yaml.sub(/---\s*/, ''))) }
|
50
54
|
end
|
51
55
|
rescue CannotDecodeTranslationFilePath
|
52
56
|
if cannot_decode_translation_file_path_handler.respond_to?(:call)
|
53
|
-
cannot_decode_translation_file_path_handler.call(key,locale,options,exception)
|
57
|
+
cannot_decode_translation_file_path_handler.call(key, locale, options, exception)
|
54
58
|
else
|
55
59
|
Rails.logger.info "=== Cannot access translation file for #{key.to_s}"
|
56
60
|
return(options[:rescue_format] == :html ? exception.html_message : exception.message)
|
@@ -104,10 +108,10 @@ module I18n
|
|
104
108
|
|
105
109
|
def handle_exception(exception, locale, key, options)
|
106
110
|
case exception
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
+
when I18n::MissingTranslationData
|
112
|
+
spawn_translation_key(key, locale, options, exception)
|
113
|
+
else
|
114
|
+
raise exception
|
111
115
|
end
|
112
116
|
end
|
113
117
|
|
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: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 13
|
10
|
+
version: 0.0.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "B\xC5\x82a\xC5\xBCej --Stevo-- Kosmowski"
|