Class: Asciidoctor::I18n::Translator
- Inherits:
-
Object
- Object
- Asciidoctor::I18n::Translator
- Defined in:
- lib/asciidoctor/i18n/translator.rb
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Translator
constructor
A new instance of Translator.
- #save ⇒ Object
- #translate(source) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Translator
Returns a new instance of Translator.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/asciidoctor/i18n/translator.rb', line 11 def initialize(attributes) @attributes = attributes unless old_po raise ArgumentError, 'missing attributes: language' unless language raise ArgumentError, 'missing attributes: po-directory' unless po_directory end @new_po = create_new_po @old_po = load_old_po end |
Instance Method Details
#save ⇒ Object
34 35 36 37 38 |
# File 'lib/asciidoctor/i18n/translator.rb', line 34 def save return if no_update? FileUtils.mkdir_p(po_directory) File.write(po_path, @new_po.to_s(max_line_width: -1)) end |
#translate(source) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/asciidoctor/i18n/translator.rb', line 22 def translate(source) return source if no_translations? if source.is_a?(String) translate_string(source) elsif source.is_a?(Array) translate_lines(source) else raise ArgumentError, "invalid argument for #translate method: #{source.inspect}" end end |