Stringex::Localization::Backend::I18n

Constants

LOAD_PATH_BASE

Public Class Methods

default_locale() click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 16
def default_locale
  ::I18n.default_locale
end
default_locale=(new_locale) click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 20
def default_locale=(new_locale)
  ::I18n.default_locale = new_locale
end
ensure_locales_enforced_or_not() click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 59
def ensure_locales_enforced_or_not
  return unless ::I18n.respond_to?(:enforce_available_locales)
  # Allow users to have set this to false manually but default to true
  return if ::I18n.enforce_available_locales != nil
  ::I18n.enforce_available_locales = ::I18n.available_locales != []
end
i18n_translations_for(locale) click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 50
def i18n_translations_for(locale)
  ensure_locales_enforced_or_not
  ::I18n.translate("stringex", :locale => locale, :default => {})
end
initial_translation(scope, key, locale) click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 38
def initial_translation(scope, key, locale)
  translations[locale][scope][key.to_sym]
end
load_translations(locale = nil) click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 42
def load_translations(locale = nil)
  locale ||= self.locale
  path = Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")]
  ::I18n.load_path |= Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")]
  ::I18n.backend.load_translations
  reset_translations_cache
end
locale() click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 8
def locale
  @locale || ::I18n.locale
end
locale=(new_locale) click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 12
def locale=(new_locale)
  @locale = new_locale
end
reset_translations_cache() click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 55
def reset_translations_cache
  @translations = nil
end
store_translations(locale, scope, data) click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 28
def store_translations(locale, scope, data)
  ::I18n.backend.store_translations(locale, { :stringex => { scope => data } })
  reset_translations_cache
end
translations() click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 33
def translations
  # Set up hash like translations[:en][:transliterations]["é"]
  @translations ||= Hash.new { |hsh, locale| hsh[locale] = Hash.new({}).merge(i18n_translations_for(locale)) }
end
with_locale(new_locale, &block) click to toggle source
# File lib/stringex/localization/backend/i18n.rb, line 24
def with_locale(new_locale, &block)
  ::I18n.with_locale new_locale, &block
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.