Last active
December 23, 2016 04:24
-
-
Save GBH/de15af9cb51054c34b6ad947009584df to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'yaml' | |
en_hash = YAML::load_file(File.expand_path('../config/locales/en.yml', File.dirname(__FILE__))) | |
locales = %w(en de es fr nl pt-BR zh-CN zh-TW) | |
def fix_locale(locale_hash, en_hash) | |
result_hash = locale_hash | |
en_hash.each do |k, v| | |
# populating missing key/value | |
unless result_hash.has_key?(k) | |
result_hash[k] = v | |
end | |
# going deeper | |
if v.is_a?(Hash) | |
result_hash[k] = fix_locale(result_hash[k], v) | |
end | |
result_hash = result_hash.sort_by{|k, v| [v.is_a?(Hash).to_s, k]}.to_h | |
end | |
result_hash | |
end | |
locales.each do |locale| | |
locale_hash = YAML::load_file(File.expand_path("../config/locales/#{locale}.yml", File.dirname(__FILE__))) | |
result_hash = { } | |
result_hash[locale] = fix_locale(locale_hash[locale], en_hash['en']) | |
File.open(File.expand_path("../config/locales/#{locale}_fix.yml", File.dirname(__FILE__)), 'w') do |f| | |
f.write result_hash.to_yaml(line_width: 1000) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment