Class: FastGettext::TranslationRepository::Yaml

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

Overview

Responsibility:

- find and store yaml files
- provide access to translations in yaml files

Instance Attribute Summary

Attributes inherited from Base

#name, #options

Instance Method Summary collapse

Methods inherited from Base

#[]

Constructor Details

#initialize(name, options = {}) ⇒ Yaml

Returns a new instance of Yaml.



12
13
14
15
# File 'lib/fast_gettext/translation_repository/yaml.rb', line 12

def initialize(name, options = {})
  super
  reload
end

Instance Method Details

#available_localesObject



17
18
19
# File 'lib/fast_gettext/translation_repository/yaml.rb', line 17

def available_locales
  @files.keys
end

#plural(*keys) ⇒ Object



21
22
23
24
25
# File 'lib/fast_gettext/translation_repository/yaml.rb', line 21

def plural(*keys)
  ['one', 'other', 'plural2', 'plural3'].map do |name|
    self[yaml_dot_notation(keys.first, name)]
  end
end

#pluralisation_ruleObject



27
28
29
30
31
32
33
# File 'lib/fast_gettext/translation_repository/yaml.rb', line 27

def pluralisation_rule
  return unless rule = self['pluralisation_rule']

  ->(n) do # rubocop:disable Lint/UnusedBlockArgument n can be used from pluralisation_rule code
    eval(rule) # rubocop:disable Security/Eval TODO remove eval
  end
end

#reloadObject



35
36
37
38
# File 'lib/fast_gettext/translation_repository/yaml.rb', line 35

def reload
  find_and_store_files(@options)
  super
end