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

#convert(source, target) ⇒ void

This method returns an undefined value.

Convert a resource file from one format to another

Parameters:

  • source (String)

    An existing resource file

  • target (String)

    The name of a target resource file



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

def convert(source, target)
  run do
    converter = Translatomatic::Converter.new
    converter.convert(source, target)
  end
end

#display(file = nil, *keys) ⇒ void

This method returns an undefined value.

Display values from a resource bundle

Parameters:

  • file (String) (defaults to: nil)

    Path to resource file

  • keys (Array<String>)

    Optional list of locales



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

def display(file = nil, *keys)
  run do
    source_files = parse_list(file, conf.get(:source_files))
    locales = conf.get(:target_locales, for_file: file)
    source_files.each do |path|
      raise t('file.not_found', file: path) unless File.exist?(path)
      source = Translatomatic::ResourceFile.load(path)
      display_properties(source, keys)
      locales.each do |locale|
        path = source.locale_path(locale)
        next if path == source.path || !path.exist?
        resource = Translatomatic::ResourceFile.load(path)
        display_properties(resource, keys)
      end
    end
  end
end

#providersvoid

This method returns an undefined value.

List available translation providers



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

def providers
  run { display_providers }
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



52
53
54
55
56
57
58
59
60
61
# File 'lib/translatomatic/cli/main.rb', line 52

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



87
88
89
# File 'lib/translatomatic/cli/main.rb', line 87

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