Module: GettextSimpleRails

Defined in:
lib/gettext_simple_rails.rb,
lib/gettext_simple_rails/engine.rb,
lib/gettext_simple_rails/version.rb,
app/helpers/gettext_simple_rails/application_helper.rb,
app/controllers/gettext_simple_rails/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper Classes: ApplicationController, Engine, I18nInjector, ModelInspector, Translators

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object

Raises:

  • (LoadError)


5
6
7
8
9
# 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

.translation_dirObject



11
12
13
# 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 = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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