Created
April 2, 2015 02:05
-
-
Save msroot/47df17ccee8f4210cc5d to your computer and use it in GitHub Desktop.
Import YAML translations to I18n::Backend::ActiveRecord::Translation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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