Class: Translatomatic::FileTranslator
- Inherits:
-
Object
- Object
- Translatomatic::FileTranslator
- Includes:
- Util
- Defined in:
- lib/translatomatic/file_translator.rb
Overview
Translates resource files from one language to another.
Instance Attribute Summary collapse
-
#translator ⇒ Translatomatic::Translator
readonly
Translator object.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ FileTranslator
constructor
Create a new FileTranslator instance.
-
#translate(file, to_locale) ⇒ Translatomatic::ResourceFile
Translate properties of file to the target locale.
-
#translate_to_file(source, to_locale) ⇒ ResourceFile
Translates a resource file and writes results to a target resource file.
Constructor Details
#initialize(options = {}) ⇒ FileTranslator
Create a new FileTranslator instance
10 11 12 13 14 |
# File 'lib/translatomatic/file_translator.rb', line 10 def initialize( = {}) @dry_run = [:dry_run] @in_place = [:in_place] @translator = Translator.new() end |
Instance Attribute Details
#translator ⇒ Translatomatic::Translator (readonly)
Returns Translator object.
5 6 7 |
# File 'lib/translatomatic/file_translator.rb', line 5 def translator @translator end |
Instance Method Details
#translate(file, to_locale) ⇒ Translatomatic::ResourceFile
Translate properties of file to the target locale. Does not write changes to disk.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/translatomatic/file_translator.rb', line 21 def translate(file, to_locale) file = resource_file(file) to_locale = build_locale(to_locale) # do nothing if target language is the same as source language return file if file.locale.language == to_locale.language texts = texts_from_file(file) unless @dry_run collection = @translator.translate(texts, to_locale) update_properties(file, to_locale, collection) end file end |
#translate_to_file(source, to_locale) ⇒ ResourceFile
Translates a resource file and writes results to a target resource file. The path of the target resource file is automagically determined.
42 43 44 45 46 47 |
# File 'lib/translatomatic/file_translator.rb', line 42 def translate_to_file(source, to_locale) target = translation_target_file(source, to_locale) return source unless target translate(target, to_locale) save_resource_file(target) end |