class I18n::Backend::SideBySide
Constants
- LOCALE_PREFIX
- VERSION
Protected Instance Methods
load_file(filename)
click to toggle source
# File lib/i18n/backend/side_by_side.rb, line 12 def load_file(filename) type = File.extname(filename).tr('.', '').downcase raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true) data = send(:"load_#{type}", filename).first unless data.is_a?(Hash) raise InvalidLocaleData.new(filename, 'expects it to return a hash, but does not') end if data.first.first.to_s == LOCALE_PREFIX _process([], data.deep_symbolize_keys[LOCALE_PREFIX.to_sym]) else data.each { |locale, d| store_translations(locale, d || {}) } end end
Private Instance Methods
_contains_locales?(hash)
click to toggle source
# File lib/i18n/backend/side_by_side.rb, line 54 def _contains_locales?(hash) hash.first.first[0] == LOCALE_PREFIX end
_process(path, hash)
click to toggle source
# File lib/i18n/backend/side_by_side.rb, line 29 def _process(path, hash) if !hash.is_a?(Hash) ### TRANSLATION KEY WITHOUT SPECIFIED LANGUAGE - WILL BE APPLIED TO ALL LANGUAGES value = hash translations.keys.each do |locale| _store([locale] + path, value) end elsif _contains_locales?(hash) hash.each do |locale, value| _store([_strip_locale_prefix(locale)] + path, value) end else hash.each { |key, value| _process(path + [key], value) } end end
_store(path, value)
click to toggle source
# File lib/i18n/backend/side_by_side.rb, line 45 def _store(path, value) *keys, last_key = path target = keys.inject(translations) do |hash, key| hash[key] ||= {} hash[key] end target[last_key] = value end
_strip_locale_prefix(locale)
click to toggle source
# File lib/i18n/backend/side_by_side.rb, line 58 def _strip_locale_prefix(locale) locale[LOCALE_PREFIX.length..-1].to_sym end