Sha256: 0147973fe32c2f689433f2286aa2de35f0ad9c8b300531e0f18be35d4ef7c81a

Contents?: true

Size: 1018 Bytes

Versions: 28

Compression:

Stored size: 1018 Bytes

Contents

require 'fileutils'

module Translate
  class Log
    attr_accessor :from_locale, :to_locale, :keys

    def initialize(from_locale, to_locale, keys)
      self.from_locale = from_locale
      self.to_locale = to_locale
      self.keys = keys
    end

    def write_to_file
      current_texts = File.exists?(file_path) ? file.read : {}
      current_texts.merge!(from_texts)
      file.write(current_texts)
    end

    def read
      file.read
    end

    private
    def file
      @file ||= Translate::File.new(file_path)
    end

    def from_texts
      Translate::File.deep_stringify_keys(Translate::Keys.to_deep_hash(keys.inject({}) do |hash, key|
        hash[key] = I18n.backend.send(:lookup, from_locale, key)
        hash
      end))
    end

    def file_path
      #make sure diff log dir exists
      translate_log_dir = File.join(RAILS_ROOT,  'log', 'translate')
      FileUtils.mkdir_p(translate_log_dir)
      File.join(translate_log_dir, "from_#{from_locale}_to_#{to_locale}.yml")
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
refinerycms-i18n-5.0.1 lib/translate/log.rb
refinerycms-i18n-5.0.0 lib/translate/log.rb
refinerycms-i18n-4.0.2 lib/translate/log.rb
refinerycms-i18n-4.0.1 lib/translate/log.rb
refinerycms-i18n-3.0.2 lib/translate/log.rb
refinerycms-i18n-4.0.0 lib/translate/log.rb
refinerycms-i18n-3.0.1 lib/translate/log.rb
refinerycms-i18n-3.0.0 lib/translate/log.rb
refinerycms-i18n-2.1.0 lib/translate/log.rb
refinerycms-i18n-2.0.2 lib/translate/log.rb
refinerycms-i18n-2.0.0 lib/translate/log.rb
refinerycms-i18n-1.0.0 lib/translate/log.rb
refinerycms-i18n-0.9.9.16 lib/translate/log.rb
refinerycms-i18n-0.9.9.15 lib/translate/log.rb
refinerycms-i18n-0.9.9.14 lib/translate/log.rb
refinerycms-i18n-0.9.9.13 lib/translate/log.rb
refinerycms-i18n-0.9.9.12 lib/translate/log.rb
refinerycms-i18n-0.9.9.10 lib/translate/log.rb
refinerycms-i18n-0.9.9.9 lib/translate/log.rb
refinerycms-i18n-0.9.9.8 lib/translate/log.rb