Skip to content

Instantly share code, notes, and snippets.

@bastengao
Created March 19, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastengao/fcdbdb090d56cc724e3158d2857dc6d8 to your computer and use it in GitHub Desktop.
Save bastengao/fcdbdb090d56cc724e3158d2857dc6d8 to your computer and use it in GitHub Desktop.
# 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