Class: YamlTranslator::Locale
- Inherits:
-
Object
- Object
- YamlTranslator::Locale
- Defined in:
- lib/yaml-translator/locale.rb
Instance Attribute Summary collapse
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #flatten_hash ⇒ Object
-
#initialize(values, lang) ⇒ Locale
constructor
A new instance of Locale.
- #save(dir = Dir.pwd) ⇒ Object
- #save_to(dir) ⇒ Object
- #to_s ⇒ Object
- #translate(translator, options = {}) ⇒ Object
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
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
5 6 7 |
# File 'lib/yaml-translator/locale.rb', line 5 def lang @lang end |
#values ⇒ Object (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_hash ⇒ Object
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_s ⇒ Object
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, ={}) translator.translate(self, ) end |