Class: I18n::JS::FallbackLocales

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/js/fallback_locales.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fallbacks, locale) ⇒ FallbackLocales

Returns a new instance of FallbackLocales.



6
7
8
9
# File 'lib/i18n/js/fallback_locales.rb', line 6

def initialize(fallbacks, locale)
  @fallbacks = fallbacks
  @locale = locale
end

Instance Attribute Details

#fallbacksObject (readonly)

Returns the value of attribute fallbacks.



4
5
6
# File 'lib/i18n/js/fallback_locales.rb', line 4

def fallbacks
  @fallbacks
end

#localeObject (readonly)

Returns the value of attribute locale.



4
5
6
# File 'lib/i18n/js/fallback_locales.rb', line 4

def locale
  @locale
end

Instance Method Details

#eachObject



11
12
13
# File 'lib/i18n/js/fallback_locales.rb', line 11

def each
  locales.each { |locale| yield(locale) }
end

#localesArray<String, Symbol>

Returns An Array of locales to use as fallbacks for given locale.

Returns:

  • (Array<String, Symbol>)

    An Array of locales to use as fallbacks for given locale.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/i18n/js/fallback_locales.rb', line 17

def locales
  locales = case fallbacks
            when true
              default_fallbacks
            when :default_locale
              [::I18n.default_locale]
            when Symbol, String
              [fallbacks.to_sym]
            when Array
              ensure_valid_fallbacks_as_array!
              fallbacks
            when Hash
              Array(fallbacks[locale] || default_fallbacks)
            else
              fail ArgumentError, "fallbacks must be: true, :default_locale an Array or a Hash - given: #{fallbacks}"
            end

  locales.map! { |locale| locale.to_sym }
  locales
end