Sha256: 6db0ff9ab62d16d1ba5926ec345c9d57b24d2d857f78cc249a1a6b17d330a25c

Contents?: true

Size: 849 Bytes

Versions: 9

Compression:

Stored size: 849 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

9 entries across 9 versions & 1 rubygems

Version Path
translate-rails3-plus-0.0.11 lib/translate/log.rb
translate-rails3-plus-0.0.9 lib/translate/log.rb
translate-rails3-plus-0.0.8 lib/translate/log.rb
translate-rails3-plus-0.0.7 lib/translate/log.rb
translate-rails3-plus-0.0.6 lib/translate/log.rb
translate-rails3-plus-0.0.5 lib/translate/log.rb
translate-rails3-plus-0.0.4 lib/translate/log.rb
translate-rails3-plus-0.0.3 lib/translate/log.rb
translate-rails3-plus-0.0.1 lib/translate/log.rb