Wednesday, 1 April 2015

Import YAML translations to I18n::Backend::ActiveRecord::Translation

data = YAML::load(File.open("config/locales/en.yml"))
translations = {}
def process_hash(translations, current_key, hash)
hash.each do |new_key, value|
combined_key = [current_key, new_key].delete_if { |k| k == '' }.join(".")
if value.is_a?(Hash)
process_hash(translations, combined_key, value)
else
translations[combined_key] = value
end
end
end
process_hash(translations, '', data['en'])
translations.each do |k, v|
TRANSLATIONS_STORE.store_translations(:en, {
k => v
}, :escape => false)
end
view raw gistfile1.rb hosted with ❤ by GitHub

No comments:

Post a Comment