Sha256: 51e4248179f0cc0d397b95209a9d4bf199395b693d299118ef1edd8a5b682202

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require "rails"
require "i18n"
require "exvo_globalize"

module ExvoGlobalize
  class Engine < Rails::Engine
    initializer "exvo_globalize.configure_i18n" do |app|
      # make pluralization rules available for both backends
      I18n::Backend::GlobalizeStore.send(:include, I18n::Backend::Pluralization)
      I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)

      # fallback for missing translations (will search for translations using I18n.default_locale if not found in requested locale)
      I18n::Backend::Chain.send(:include, I18n::Backend::Fallback)

      # caching layer
      I18n::Backend::GlobalizeStore.send(:include, I18n::Backend::Cache)
      I18n.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)

      # chained backends (fall back from first backend to the second if translation is not found in the first)
      # GlobalizeStore first (database backed), YAML files second (Simple backend, the default one)
      I18n.backend = I18n::Backend::Chain.new(I18n::Backend::GlobalizeStore.new, I18n.backend)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
exvo_globalize-0.3.1 lib/exvo_globalize/engine.rb
exvo_globalize-0.3.0 lib/exvo_globalize/engine.rb
exvo_globalize-0.2.1 lib/exvo_globalize/engine.rb
exvo_globalize-0.2.0 lib/exvo_globalize/engine.rb