Sha256: 4aa4b3b85fd3e66e73fb38d0174aa9891b492165ed99d7657823db11596d643a

Contents?: true

Size: 1.23 KB

Versions: 33

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'i18n'
require 'active_support/core_ext/array/extract_options'
require 'action_view'

module Spree
  def self.i18n_available_locales
    I18n.available_locales.select do |locale|
      I18n.t('spree.i18n.this_file_language', locale: locale, fallback: false, default: nil)
    end
  end

  class TranslationHelperWrapper # :nodoc:
    include ActionView::Helpers::TranslationHelper
  end

  # This value is used as a count for the pluralization helpers related to I18n
  # ex: Spree::Order.model_name.human(count: Spree::I18N_GENERIC_PLURAL)
  # Related to Solidus issue #1164, this is needed to avoid problems with
  # some pluralization calculators
  I18N_GENERIC_PLURAL = 2.1

  class << self
    # Add spree namespace and delegate to Rails TranslationHelper for some nice
    # extra functionality. e.g return reasonable strings for missing translations

    def translate(key, options = {})
      Spree::Deprecation.warn <<-WARN.squish
        Spree.t & Spree.translate have been deprecated.
        Instead use I18n.t('spree.your_translation_key')
      WARN
      options[:scope] = [:spree, *options[:scope]]
      TranslationHelperWrapper.new.translate(key, options)
    end

    alias_method :t, :translate
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
solidus_core-2.8.0 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.4 lib/spree/i18n.rb
solidus_core_devise_token_auth-2.8.0.alpha.3 lib/spree/i18n.rb