Skip to content

Instantly share code, notes, and snippets.

@msroot
Created April 2, 2015 02:05
Show Gist options
  • Save msroot/47df17ccee8f4210cc5d to your computer and use it in GitHub Desktop.
Save msroot/47df17ccee8f4210cc5d to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment