Created
March 19, 2018 09:24
-
-
Save bastengao/fcdbdb090d56cc724e3158d2857dc6d8 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
# gem 'i18n_generators' | |
# rails g i18n_translation zh-CN | |
require 'yaml' | |
local = YAML.load_file(Rails.root.join('config/locales/translation_zh-CN.yml')) | |
models = local.dig('zh-CN', 'activerecord', 'models') | |
attributes = local.dig('zh-CN', 'activerecord', 'attributes') | |
models.each do |key, value| | |
puts key | |
next if key.include? "/" | |
file_name = Rails.root.join('config/locales/models/' + key + '.zh-CN.yml') | |
puts file_name | |
if File.exist? file_name | |
puts 'exists' | |
end | |
translation = { | |
'zh-CN' => { | |
'activerecord' => { | |
'models' => { | |
key => nil | |
}, | |
'attributes' => { | |
key => attributes[key].map { |key, value| [key, nil]}.to_h | |
} | |
} | |
} | |
} | |
File.open(file_name, 'w+') do |f| | |
YAML.dump(translation, f) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment