Module: I18n::Tasks::Command::OptionParsers::Locale::ListParser

Extended by:
Validator
Defined in:
lib/i18n/tasks/command/option_parsers/locale.rb

Constant Summary

Constants included from Validator

Validator::VALID_LOCALE_RE

Class Method Summary collapse

Methods included from Validator

validate!

Class Method Details

.call(vals, context) ⇒ Object

Parameters:

  • context (#base_locale, #locales)


40
41
42
43
44
45
46
47
48
# File 'lib/i18n/tasks/command/option_parsers/locale.rb', line 40

def call(vals, context)
  if vals == %w[all] || vals.blank?
    context.locales
  else
    move_base_locale_to_front!(vals.map { |v| v == 'base' ? context.base_locale : v }, context.base_locale)
  end.tap do |locales|
    locales.each { |locale| validate! locale }
  end
end

.move_base_locale_to_front!(locales, base_locale) ⇒ Object



50
51
52
53
54
55
# File 'lib/i18n/tasks/command/option_parsers/locale.rb', line 50

def move_base_locale_to_front!(locales, base_locale)
  if (pos = locales.index(base_locale)) && pos.positive?
    locales[pos], locales[0] = locales[0], locales[pos]
  end
  locales
end