class Translatomatic::I18n

I18n initialisation and translation fallback handling

Constants

FALLBACK_LOCALE

Public Class Methods

l(object, options = {}) click to toggle source

Localises dates and numbers to local formatting @param object [Object] Object to localise

# File lib/translatomatic/i18n.rb, line 19
def l(object, options = {})
  ::I18n.l(object, options)
end
t(key, options = {}) click to toggle source

Get string translation @param key translation key

# File lib/translatomatic/i18n.rb, line 10
def t(key, options = {})
  tkey = "translatomatic.#{key}"
  raise "missing translation: #{tkey}" unless ::I18n.exists?(tkey)

  ::I18n.t(tkey, options.merge(locale: t_locale(options)))
end

Private Class Methods

init_i18n(root_path) click to toggle source
# File lib/translatomatic/i18n.rb, line 27
def init_i18n(root_path)
  locale_path = File.join(root_path, 'config', 'locales')
  ::I18n.load_path += Dir[File.join(locale_path, '**', '*.yml')]
end
t_locale(options) click to toggle source
# File lib/translatomatic/i18n.rb, line 32
def t_locale(options)
  locale = options[:locale] || Locale.default.to_s
  locale = FALLBACK_LOCALE unless ::I18n.locale_available?(locale)
  locale
end