Class: YamlTranslator::Locale

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml-translator/locale.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, lang) ⇒ Locale

Returns a new instance of Locale.



7
8
9
10
# File 'lib/yaml-translator/locale.rb', line 7

def initialize(values, lang)
  @lang = lang
  @values = values
end

Instance Attribute Details

#langObject (readonly)

Returns the value of attribute lang.



5
6
7
# File 'lib/yaml-translator/locale.rb', line 5

def lang
  @lang
end

#valuesObject (readonly)

Returns the value of attribute values.



5
6
7
# File 'lib/yaml-translator/locale.rb', line 5

def values
  @values
end

Class Method Details

.load_file(file) ⇒ Object



33
34
35
36
37
# File 'lib/yaml-translator/locale.rb', line 33

def load_file(file)
  lang = File.basename(file).gsub(/.(yml|yaml)/, '')
  yaml = YAML.load(File.open(file, &:read))
  self.new(yaml, lang)
end

Instance Method Details

#flatten_hashObject



24
25
26
# File 'lib/yaml-translator/locale.rb', line 24

def flatten_hash
  flatten(values)
end

#save(dir = Dir.pwd) ⇒ Object



16
17
18
# File 'lib/yaml-translator/locale.rb', line 16

def save(dir=Dir.pwd)
  write_file(File.join(dir, "#{lang}.yml"))
end

#save_to(dir) ⇒ Object



20
21
22
# File 'lib/yaml-translator/locale.rb', line 20

def save_to(dir)
  save(dir)
end

#to_sObject



28
29
30
# File 'lib/yaml-translator/locale.rb', line 28

def to_s
  YAML.dump(values)
end

#translate(translator, options = {}) ⇒ Object



12
13
14
# File 'lib/yaml-translator/locale.rb', line 12

def translate(translator, options={})
  translator.translate(self, options)
end