Sha256: e5ba1f1665c10fa3fdb9eba79f12b4f87ecdd5b8f1336f78495a8e8f562e9703

Contents?: true

Size: 944 Bytes

Versions: 26

Compression:

Stored size: 944 Bytes

Contents

require 'fileutils'
class Translate::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

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
refinerycms-i18n-0.9.8.12 lib/translate/log.rb
refinerycms-i18n-0.9.8.11 lib/translate/log.rb
refinerycms-0.9.7.15 vendor/plugins/translate/lib/translate/log.rb
refinerycms-0.9.7.14 vendor/plugins/translate/lib/translate/log.rb
refinerycms-i18n-0.9.8.8 lib/translate/log.rb
refinerycms-i18n-0.9.8.7 lib/translate/log.rb
refinerycms-i18n-0.9.8.6 lib/translate/log.rb
refinerycms-i18n-0.9.8.5 lib/translate/log.rb
refinerycms-i18n-0.9.8.4 lib/translate/log.rb
refinerycms-i18n-0.9.8.3 lib/translate/log.rb
refinerycms-i18n-0.9.8.2 lib/translate/log.rb
refinerycms-i18n-0.9.8.1 lib/translate/log.rb
refinerycms-i18n-0.9.8 lib/translate/log.rb
refinerycms-0.9.7.13 vendor/plugins/translate/lib/translate/log.rb
refinerycms-0.9.7.11 vendor/plugins/translate/lib/translate/log.rb
refinerycms-0.9.7.10 vendor/plugins/translate/lib/translate/log.rb
refinerycms-0.9.7.9 vendor/plugins/translate/lib/translate/log.rb
refinerycms-0.9.7.8 vendor/plugins/translate/lib/translate/log.rb
refinerycms-0.9.7.7 vendor/plugins/translate/lib/translate/log.rb
refinerycms-0.9.7.6 vendor/plugins/translate/lib/translate/log.rb