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 =
<<~GUIDE.freeze

  No locales directory found.

  i18n-linter-rb looks for a Rails locales directory by default:
    config/locales/

  If your translations live somewhere else, pass the path explicitly:

    i18n-linter-rb --path path/to/locales
    i18n-linter-rb --path path/to/locales --from en --to es,fr,pt

  You can also create an .i18n_linter.yml file in your project root:

    locales_path: path/to/locales
    source_locale: en
    target_locales: [es, fr]

GUIDE

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



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

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

Instance Method Details

#runObject



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