class Translate::Log

Attributes

from_locale[RW]
keys[RW]
to_locale[RW]

Public Class Methods

new(from_locale, to_locale, keys) click to toggle source
# File lib/translate/log.rb, line 7
def initialize(from_locale, to_locale, keys)
  self.from_locale = from_locale
  self.to_locale = to_locale
  self.keys = keys
end

Public Instance Methods

read() click to toggle source
# File lib/translate/log.rb, line 19
def read
  file.read
end
write_to_file() click to toggle source
# File lib/translate/log.rb, line 13
def write_to_file
  current_texts = File.exists?(file_path) ? file.read : {}
  current_texts.merge!(from_texts)
  file.write(current_texts)
end

Private Instance Methods

file() click to toggle source
# File lib/translate/log.rb, line 24
def file
  @file ||= Translate::File.new(file_path)
end
file_path() click to toggle source
# File lib/translate/log.rb, line 35
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
from_texts() click to toggle source
# File lib/translate/log.rb, line 28
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