Class: GettextSimpleRails::CacheHandler
- Inherits:
-
Object
- Object
- GettextSimpleRails::CacheHandler
- Defined in:
- lib/gettext_simple_rails/cache_handler.rb
Instance Method Summary collapse
- #cache_file_too_old? ⇒ Boolean
- #newest_po_file ⇒ Object
- #static_cache_file_path ⇒ Object
- #write_static_translation_file ⇒ Object
Instance Method Details
#cache_file_too_old? ⇒ Boolean
24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 ⇒ Object
20 21 22 |
# 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 ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |