Sha256: ccdf0d57522fadf1c3ad9bc262771c0a9594210e7ef3b50cfcb7b8ec9a99b953
Contents?: true
Size: 1.29 KB
Versions: 7
Compression:
Stored size: 1.29 KB
Contents
class GettextSimpleRails::CacheHandler 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 def static_cache_file_path "#{Rails.root}/config/locales_gettext/static_translation_file.json" end 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 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 end
Version data entries
7 entries across 7 versions & 1 rubygems