Module: Snails::Locales

Defined in:
lib/snails/app.rb

Class Method Summary collapse

Class Method Details

.load!(path, lang = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/snails/app.rb', line 46

def self.load!(path, lang = nil)
  I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
  I18n.load_path = Dir[File.join(path, '*.yml')]
  I18n.enforce_available_locales = false
  I18n.backend.load_translations
  I18n.locale = lang if lang
end

.registered(app) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/snails/app.rb', line 54

def self.registered(app)
  require 'i18n'
  require 'i18n/backend/fallbacks'

  cwd = Pathname.new(Dir.pwd)
  app.set :locale, :es
  app.set :locales_path, app.setting(:locales_path, cwd.join('config', 'locales'))

  app.helpers do
    def t(key); I18n.t(key); end
  end

  app.configure do
    Locales.load!(app.settings.locales_path)
  end

  app.before do
    I18n.locale = app.settings.locale
  end
end