class GettextSimpleRails::CacheHandler

Public Instance Methods

cache_file_too_old?() click to toggle source
# File lib/gettext_simple_rails/cache_handler.rb, line 24
def cache_file_too_old?
  if !File.exists?(static_cache_file_path)
    return true
  elsif newest_po_file && File.mtime(static_cache_file_path) < File.mtime(newest_po_file)
    return true
  else
    return false
  end
end
newest_po_file() click to toggle source
# File lib/gettext_simple_rails/cache_handler.rb, line 2
def newest_po_file
  newest_time = nil
  newest_path = nil
  
  I18n.available_locales.each do |locale|
    default_path_file = "#{Rails.root}/config/locales_gettext/#{locale}/LC_MESSAGES/default.po"
    next unless File.exists?(default_path_file)
    time = File.mtime(default_path_file)
    
    if newest_time == nil || time > newest_time
      newest_time = time
      newest_path = default_path_file
    end
  end
  
  return newest_path
end
static_cache_file_path() click to toggle source
# File lib/gettext_simple_rails/cache_handler.rb, line 20
def static_cache_file_path
  "#{Rails.root}/config/locales_gettext/static_translation_file.json"
end
write_static_translation_file() click to toggle source
# File lib/gettext_simple_rails/cache_handler.rb, line 34
def write_static_translation_file
  require "gettext_simple"
  gs = GettextSimple.new(:i18n => true)
  gs.load_dir("#{Rails.root}/config/locales_gettext")
  gs.register_kernel_methods
  
  injector = GettextSimpleRails::I18nInjector.new(:store_in_hash => true)
  injector.inject_translator_translations(gs)
  
  File.open(static_cache_file_path, "w") do |fp|
    fp.write(injector.store_hash.to_json)
  end
end