module GettextSimpleRails
Constants
- VERSION
Public Class Methods
const_missing(name)
click to toggle source
# File lib/gettext_simple_rails.rb, line 5 def self.const_missing(name) require "#{::File.dirname(__FILE__)}/gettext_simple_rails/#{::StringCases.camel_to_snake(name)}" raise LoadError, "Still not loaded: '#{name}'." unless ::GettextSimpleRails.const_defined?(name) return ::GettextSimpleRails.const_get(name) end
init()
click to toggle source
# File lib/gettext_simple_rails.rb, line 39 def self.init require "gettext_simple" gettext_simple = GettextSimple.new(:i18n => true) gettext_simple.load_dir("#{Rails.root}/config/locales_gettext") gettext_simple.register_kernel_methods injector = GettextSimpleRails::I18nInjector.new cache_handler = GettextSimpleRails::CacheHandler.new if cache_handler.cache_file_too_old? puts "[GettextSimpleRails] Cache file too old - regenerating." cache_handler.write_static_translation_file end injector.inject_from_static_translation_file(:path => cache_handler.static_cache_file_path) end
translation_dir()
click to toggle source
# File lib/gettext_simple_rails.rb, line 11 def self.translation_dir return "#{Rails.root}/lib/gettext_simple_rails" end
write_recursive_translations(fp, translations, pre_path = [], args = {})
click to toggle source
# File lib/gettext_simple_rails.rb, line 15 def self.write_recursive_translations(fp, translations, pre_path = [], args = {}) if translations.is_a?(Hash) translations.each do |key, val| newpath = pre_path + [key] write_recursive_translations(fp, val, newpath, :comment => "Default value: #{val}") end elsif translations.is_a?(Array) translations.each do |val| newpath = pre_path + [val] write_recursive_translations(fp, val, newpath) end elsif translations.is_a?(String) || translations.is_a?(Fixnum) if args[:comment] args[:comment].to_s.each_line do |line| fp.puts " #. #{line}" end end fp.puts " _('#{pre_path.join(".")}')" else raise "Unknownt class: '#{translations.class.name}'." end end