class TidyI18n::DictionaryConverter
Attributes
dictionary[RW]
locale[RW]
Public Class Methods
new(dictionary, locale)
click to toggle source
# File lib/tidy_i18n/dictionary_converter.rb, line 10 def initialize(dictionary, locale) self.dictionary = dictionary self.locale = locale end
Public Instance Methods
converted_dictionary()
click to toggle source
# File lib/tidy_i18n/dictionary_converter.rb, line 15 def converted_dictionary convert_dictionary(dictionary, []) end
Private Instance Methods
convert_dictionary(dictionary, path)
click to toggle source
# File lib/tidy_i18n/dictionary_converter.rb, line 21 def convert_dictionary(dictionary, path) dictionary.each_with_object({}) do |(key, value), new_dictionary| new_dictionary[key] = convert_value(value, path + [key]) end end
convert_value(value, path)
click to toggle source
# File lib/tidy_i18n/dictionary_converter.rb, line 27 def convert_value(value, path) case value.class.name when "String" locale.convert(value) when "Hash" convert_dictionary(value, path) when "Array" value.collect { |v| convert_value(v, path) } when "Fixnum", "FalseClass", "TrueClass", "NilClass", "Symbol", "Integer" value else raise InvalidTranslationValue.new("#{path.join('.')} #{value.class.name} #{value.inspect}") end end