Class: CopyTunerClient::TranslationLog
- Inherits:
-
Object
- Object
- CopyTunerClient::TranslationLog
- Defined in:
- lib/copy_tuner_client/translation_log.rb
Class Method Summary collapse
- .add(key, result) ⇒ Object
- .clear ⇒ Object
- .initialized? ⇒ Boolean
- .install_hook ⇒ Object
- .translations ⇒ Object
Class Method Details
.add(key, result) ⇒ Object
15 16 17 |
# File 'lib/copy_tuner_client/translation_log.rb', line 15 def self.add(key, result) translations[key] = result if initialized? && !translations.key?(key) end |
.clear ⇒ Object
7 8 9 |
# File 'lib/copy_tuner_client/translation_log.rb', line 7 def self.clear Thread.current[:translations] = {} end |
.initialized? ⇒ Boolean
11 12 13 |
# File 'lib/copy_tuner_client/translation_log.rb', line 11 def self.initialized? !Thread.current[:translations].nil? end |
.install_hook ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/copy_tuner_client/translation_log.rb', line 19 def self.install_hook I18n.class_eval do class << self def translate_with_copy_tuner_hook(key = nil, **) scope = [:scope] scope = scope.dup if scope.is_a?(Array) || scope.is_a?(String) result = translate_without_copy_tuner_hook(key, **) if key.is_a?(Array) key.zip(result).each { |k, v| CopyTunerClient::TranslationLog.add(I18n.normalize_keys(nil, k, scope).compact.join('.'), v) unless v.is_a?(Array) } else CopyTunerClient::TranslationLog.add(I18n.normalize_keys(nil, key, scope).compact.join('.'), result) unless result.is_a?(Array) end result end if CopyTunerClient.configuration.enable_middleware? alias_method :translate_without_copy_tuner_hook, :translate alias_method :translate, :translate_with_copy_tuner_hook alias :t :translate end end end end |
.translations ⇒ Object
3 4 5 |
# File 'lib/copy_tuner_client/translation_log.rb', line 3 def self.translations Thread.current[:translations] end |