Class: BabelTrain::I18n

Inherits:
Object
  • Object
show all
Includes:
I18n::Backend::Base
Defined in:
lib/babel_train/i18n.rb

Instance Method Summary collapse

Constructor Details

#initializeI18n

Returns a new instance of I18n.



6
7
8
9
# File 'lib/babel_train/i18n.rb', line 6

def initialize
  @translations = {}
  super
end

Instance Method Details

#available_localesObject



11
12
13
# File 'lib/babel_train/i18n.rb', line 11

def available_locales
  @translations.keys
end

#reload!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/babel_train/i18n.rb', line 15

def reload!
  base = Rails.root.join('config/locales')
  base_str = "#{base.to_s}/"
  Dir[base.join('**/*.yml')].each do |file_path|
    yaml_hash = YAML.load(File.read(file_path))
    path_parts = file_path.gsub(base_str, '').split('/')
    file_parts = path_parts.pop.split('.')
    file_parts.pop # Don't need the YML part, thank you
    language = file_parts.pop.to_sym
    value_base = (path_parts + file_parts).join('.')
    @translations[language] ||= {}
    @translations[language].merge! process_hash(yaml_hash, value_base)
  end
end