Class: Translatomatic::CLI
- Inherits:
-
Thor
- Object
- Thor
- Translatomatic::CLI
- Includes:
- Util
- Defined in:
- lib/translatomatic/cli.rb
Instance Method Summary collapse
- #display(file, *keys) ⇒ Object
- #list ⇒ Object
- #strings(*files) ⇒ Object
- #translate(file, *locales) ⇒ Object
- #version ⇒ Object
Methods included from Util
Instance Method Details
#display(file, *keys) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/translatomatic/cli.rb', line 68 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 = ([:locales] || "").split(',').flatten.compact locales << Translatomatic::Locale.default.to_s if locales.empty? locales.each do |locale| display_properties(source, locale) end end end |
#list ⇒ Object
97 98 99 |
# File 'lib/translatomatic/cli.rb', line 97 def list run { puts Translatomatic::Translator.list } end |
#strings(*files) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/translatomatic/cli.rb', line 85 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 |
#translate(file, *locales) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/translatomatic/cli.rb', line 28 def translate(file, *locales) run do log.info("Dry run: files will not be translated or written") if [:dry_run] raise "One or more locales required" if locales.empty? config.logger.level = Logger::DEBUG if [:debug] # load source file raise "File not found: #{file}" unless File.exist?(file) source = Translatomatic::ResourceFile.load(file, [:source_locale]) raise "Unsupported file type #{file}" unless source # set up database Translatomatic::Database.new() # select translator translator = select_translator() log.info("Using translator #{translator.name}") log.debug("Locales: #{locales}, Properties: #{source.properties.length}") # set up converter translation_count = calculate_translation_count(source, locales) = .merge( translator: translator, listener: progress_updater(translation_count) ) converter = Translatomatic::Converter.new() # convert source to locale(s) locales.each { |i| converter.translate(source, i) } log.info converter.stats config.logger.finish share_translations(converter) if [:share] end end |
#version ⇒ Object
102 103 104 |
# File 'lib/translatomatic/cli.rb', line 102 def version puts "Translatomatic version #{Translatomatic::VERSION}" end |