Sha256: ba42f9468531c9e8fd40f4f27ddb2a3704ff9c9cbe8581254fa724c2c7c59cde

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

require 'i18n_data'

module I18n
  module Backend
    class I18nDataBackend
      module Implementation
        include Base, Flatten

        def available_locales
          I18nData.languages.keys.map(&:to_sym)
        end

        def lookup(locale, key, scope = [], options = {})
          I18nData.countries(locale)[key]
        rescue I18nData::NoTranslationAvailable
          # rescue failed lookup to fall back to this extensions locale files.
        end
      end

      include Implementation
    end
  end
end

I18n.backend = I18n::Backend::Chain.new(I18n::Backend::I18nDataBackend.new, I18n.backend)

module I18nData
  private

  def self.normal_to_region_code(normal)
    country_mappings = {
      'DE-CH' => 'de',
      'FR-CH' => 'fr',
      'EN-AU' => 'en',
      'EN-GB' => 'en',
      'EN-US' => 'en',
      'EN-IN' => 'en',
      'EN-NZ' => 'en',
      'ES-CL' => 'es',
      'ES-EC' => 'es',
      'ES-MX' => 'es',
      'PT-BR' => 'pt',
      'SL-SI' => 'sl',
      'ZH-TW' => 'zh_TW',
      'ZH-CN' => 'zh_CN',
      'ZH' => 'zh_CN',
      'BN' => 'bn_IN'
    }
    country_mappings[normal] || normal
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
spree_i18n-5.3.0 config/initializers/country_names.rb
spree_i18n-5.2.0 config/initializers/country_names.rb
spree_i18n-5.1.0 config/initializers/country_names.rb
spree_i18n-5.0.1 config/initializers/country_names.rb
spree_i18n-5.0.0 config/initializers/country_names.rb
solidus_i18n-1.3.0 config/initializers/country_names.rb
solidus_i18n-1.2.0 config/initializers/country_names.rb
solidus_i18n-1.1.0 config/initializers/country_names.rb
solidus_i18n-1.0.0 config/initializers/country_names.rb