Class: Idiom::Yaml

Inherits:
Base
  • Object
show all
Defined in:
lib/idiom/yaml.rb

Overview

Usage:

Translator::Yaml.new().copy

Constant Summary

Constants included from Locales

Locales::CONFIG, Locales::LOCALES

Instance Attribute Summary

Attributes inherited from Base

#destination, #languages, #pass_through_vars, #source, #substitution_vars, #use_dirs

Instance Method Summary collapse

Methods inherited from Base

#all_keys, #before_translation, #clear_all_keys, #comment?, #copy_and_translate_line, #do_translate, #each_line, #generate, #initialize, #key_is_new?, #new_translation_message, #translate, #translate_new_key, #write_content

Methods included from ClassMethods

#find_and_translate_all, #source_files, #translate, #translate_file

Methods included from Processing

#post_process, #pre_process

Methods included from Locales

#locales, #non_us_locales

Methods included from Directories

#destination_file_or_directory, #ensure_destination_path_exists, #use_directories?

Constructor Details

This class inherits a constructor from Idiom::Base

Instance Method Details

#after_translationObject



12
13
14
# File 'lib/idiom/yaml.rb', line 12

def after_translation
system "cat #{destination_path} >> #{source} && rm #{destination_path}"
end

#destination_path(lang = nil) ⇒ Object



8
9
10
# File 'lib/idiom/yaml.rb', line 8

def destination_path(lang=nil)
  "#{source}.tmp"
end

#extensionObject



16
17
18
# File 'lib/idiom/yaml.rb', line 16

def extension
  "yml"
end

#format(key, value) ⇒ Object



24
25
26
# File 'lib/idiom/yaml.rb', line 24

def format(key, value)
  "#{key}: #{value}"
end

#key_and_value_from_line(line) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/idiom/yaml.rb', line 28

def key_and_value_from_line(line)
  if line =~ /^([^\:]+):(.*)/
    return $1, $2.strip
  else
    return nil, nil
  end
end

#parse(path) ⇒ Object



20
21
22
# File 'lib/idiom/yaml.rb', line 20

def parse(path)
YAML.load_file(path) || {}
end