Class: Translatomatic::CLI::Main

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/cli/main.rb

Overview

Main command line interface

Instance Method Summary collapse

Instance Method Details

#display(file, *keys) ⇒ void

This method returns an undefined value.

Display values from a resource bundle

Parameters:

  • file (String)

    Path to resource file

  • keys (Array<String>)

    Optional list of locales



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/translatomatic/cli/main.rb', line 32

def display(file, *keys)
  run do
    source = Translatomatic::ResourceFile.load(file)
    keys = source.properties.keys if keys.empty?
    display_keys(source, keys)

    # TODO: if locales not specified, determine the list of locales from
    # all the files in the resource bundle.
    locales = parse_list(options[:locales])
    locales << Translatomatic::Locale.default.to_s if locales.empty?
    locales.each do |tag|
      locale = locale(tag)
      next if locale == source.locale
      display_properties(source, keys, locale)
    end
  end
end

#servicesvoid

This method returns an undefined value.

List available translator services



70
71
72
# File 'lib/translatomatic/cli/main.rb', line 70

def services
  run { puts Translatomatic::Translator.list }
end

#strings(*files) ⇒ void

This method returns an undefined value.

Extract strings from non-resource files

Parameters:

  • files (Array<String>)

    List of paths to files



55
56
57
58
59
60
61
62
63
64
# File 'lib/translatomatic/cli/main.rb', line 55

def strings(*files)
  run do
    strings = []
    files.each do |file|
      extractor = Translatomatic::Extractor::Base.new(file)
      strings << extractor.extract
    end
    puts strings.join("\n")
  end
end

#versionvoid

This method returns an undefined value.

Display version number



78
79
80
# File 'lib/translatomatic/cli/main.rb', line 78

def version
  puts "Translatomatic v#{Translatomatic::VERSION}"
end