Class: Translatomatic::CLI::Translate
- Defined in:
- lib/translatomatic/cli/translate.rb
Overview
Translation functions for the command line interface
Instance Method Summary collapse
-
#file(file, *locales) ⇒ void
Translate files to target locales.
-
#string(text, *locales) ⇒ void
Translate a string to target locales.
Instance Method Details
#file(file, *locales) ⇒ void
This method returns an undefined value.
Translate files to target locales
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/translatomatic/cli/translate.rb', line 52 def file(file, *locales) run do setup_translation(locales) # load source file raise t("cli.file_not_found", file: file) unless File.exist?(file) source = Translatomatic::ResourceFile.load(file, @source_locale) raise t("cli.file_unsupported", file: file) unless source # set up database Translatomatic::Database.new() log.debug(t("cli.locales_properties", locales: locales, properties: source.properties.length)) # set up converter translation_count = calculate_translation_count(source, @target_locales) = .merge( translator: @translators, listener: progress_updater(translation_count) ) converter = Translatomatic::Converter.new() # convert source to locale(s) and write files @target_locales.each do |i| to_locale = locale(i) next if to_locale.language == source.locale.language converter.translate_to_file(source, to_locale) end log.info converter.stats finish_log share_translations(converter) if cli_option(:share) end end |
#string(text, *locales) ⇒ void
This method returns an undefined value.
Translate a string to target locales
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/translatomatic/cli/translate.rb', line 24 def string(text, *locales) run do setup_translation(locales) puts "(%s) %s" % [@source_locale, text] @translators.each do |translator| puts t("cli.using_translator", name: translator.name) @target_locales.each do |target_locale| result = translator.translate([text], @source_locale, target_locale) puts " -> (%s) %s" % [target_locale, result] end puts end finish_log end end |