Sha256: adc7b5e7008c6456bbd67fe0b9c049ba956d7ae78fc087218a9ee2ce4980e776

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

module CopyTunerClient
  class TranslationLog
    def self.translations
      Thread.current[:translations]
    end

    def self.clear
      Thread.current[:translations] = {}
    end

    def self.initialized?
      !Thread.current[:translations].nil?
    end

    def self.add(key, result)
      translations[key] = result if initialized? && !translations.key?(key)
    end

    def self.install_hook
      I18n.class_eval do
        class << self
          def translate_with_copy_tuner_hook(key = nil, **options)
            scope = options[:scope]
            scope = scope.dup if scope.is_a?(Array) || scope.is_a?(String)
            result = translate_without_copy_tuner_hook(key, **options)

            if key.is_a?(Array)
              key.zip(result).each { |k, v| CopyTunerClient::TranslationLog.add(I18n.normalize_keys(nil, k, scope).join('.'), v) unless v.is_a?(Array) }
            else
              CopyTunerClient::TranslationLog.add(I18n.normalize_keys(nil, key, scope).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
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
copy_tuner_client-0.16.1 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.16.0 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.15.1 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.15.0 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.14.2 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.14.1 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.14.0 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.13.6 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.13.5 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.13.3 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.13.2 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.13.1 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.13.0 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.12.0 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.11.0 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.10.0 lib/copy_tuner_client/translation_log.rb
copy_tuner_client-0.9.0 lib/copy_tuner_client/translation_log.rb