Class: Langulator::Loader
- Inherits:
-
Object
- Object
- Langulator::Loader
- Defined in:
- lib/langulator/loader.rb
Instance Attribute Summary collapse
-
#alternates ⇒ Object
readonly
Returns the value of attribute alternates.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
Instance Method Summary collapse
- #destination_translations ⇒ Object
-
#initialize(options = {}) ⇒ Loader
constructor
A new instance of Loader.
- #load_translations(language) ⇒ Object
- #paths ⇒ Object
- #read_translations(path, language) ⇒ Object
- #source_translations ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Loader
Returns a new instance of Loader.
5 6 7 8 9 |
# File 'lib/langulator/loader.rb', line 5 def initialize( = {}) @base_path = [:base_path] @origin = [:origin] @alternates = [:alternates] end |
Instance Attribute Details
#alternates ⇒ Object (readonly)
Returns the value of attribute alternates.
4 5 6 |
# File 'lib/langulator/loader.rb', line 4 def alternates @alternates end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
4 5 6 |
# File 'lib/langulator/loader.rb', line 4 def base_path @base_path end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
4 5 6 |
# File 'lib/langulator/loader.rb', line 4 def origin @origin end |
Instance Method Details
#destination_translations ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/langulator/loader.rb', line 19 def destination_translations translations = {} alternates.each do |language| translations[language] = load_translations(language) end translations end |
#load_translations(language) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/langulator/loader.rb', line 27 def load_translations(language) translations = {} paths.each do |path| translations[path] = read_translations(path, language) end translations end |
#paths ⇒ Object
11 12 13 |
# File 'lib/langulator/loader.rb', line 11 def paths @paths ||= Dir.glob("#{base_path}#{origin}.yml").map {|file| file.gsub("#{origin}.yml", '') }.sort end |
#read_translations(path, language) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/langulator/loader.rb', line 35 def read_translations(path, language) file = "#{path}#{language}.yml" if File.exists?(file) YAML.load(File.read(file)) else {} end end |
#source_translations ⇒ Object
15 16 17 |
# File 'lib/langulator/loader.rb', line 15 def source_translations translations = load_translations(origin) end |