Sha256: bca6311c5c7a2b01fab70093e88daf4323b0a80dd1cd68262f82f50ea0f2f76e

Contents?: true

Size: 814 Bytes

Versions: 11

Compression:

Stored size: 814 Bytes

Contents

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
    File.join(Rails.root, "config", "locales", "log", "from_#{from_locale}_to_#{to_locale}.yml")
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
translate-rails3-plus-0.0.15 lib/translate/log.rb
translate-rails3-plus-0.0.14 lib/translate/log.rb
translate-rails3-plus-0.0.13 lib/translate/log.rb
translate-rails3-plus-0.0.12 lib/translate/log.rb
translate-rails3-0.4.0 lib/translate/log.rb
translate-rails3-0.2.3 lib/translate/log.rb
translate-rails3-0.2.2 lib/translate/log.rb
translate-rails3-0.2.0 lib/translate/log.rb
translate-rails3-0.1.2 lib/translate/log.rb
translate-rails3-0.1.1 lib/translate/log.rb
translate-rails3-0.1.0 lib/translate/log.rb