Class: I18nLinterRb::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_linter_rb/cli.rb

Constant Summary collapse

DEFAULT_LOCALES_PATH =
"config/locales".freeze
DEFAULT_SOURCE_LOCALE =
"en".freeze
DEFAULT_TARGET_LOCALES =
%w[es].freeze
CONFIG_FILE_PATH =
".i18n_linter.yml".freeze
USAGE_GUIDE =
"\nNo locales directory found.\n\ni18n-linter-rb looks for a Rails locales directory by default:\n  config/locales/\n\nIf your translations live somewhere else, pass the path explicitly:\n\n  i18n-linter-rb --path path/to/locales\n  i18n-linter-rb --path path/to/locales --from en --to es,fr,pt\n\nYou can also create an .i18n_linter.yml file in your project root:\n\n  locales_path: path/to/locales\n  source_locale: en\n  target_locales: [es, fr]\n\n".freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli



31
32
33
34
# File 'lib/i18n_linter_rb/cli.rb', line 31

def initialize(argv)
  @argv = argv
  @options = {}
end

Instance Method Details

#run ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/i18n_linter_rb/cli.rb', line 36

def run
  parse_options
  return create_config_file if @options[:init]

  resolve_locales_path
  warn_about_manual_path

  source_path = File.join(@locales_path, "#{@options[:from]}.yml")
  missing = {}

  @options[:to].each do |target_locale|
    target_path = File.join(@locales_path, "#{target_locale}.yml")
    linter = Linter.new(source_locale: @options[:from], target_locale: target_locale)
    keys = linter.missing_keys_in_target(source_path, target_path)
    missing[target_locale] = keys unless keys.empty?
  end

  report(missing)
end