Created
December 18, 2017 02:22
-
-
Save alpaca-tc/fd39abc697cb841fad01e472c587891d 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 'csv' | |
translations = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } | |
headers = ['key', 'ja', 'en', '...'] | |
CSV.open('i18n.csv', 'r', col_sep: "\t", headers: true) do |csv| | |
csv.each do |row| | |
locales = csv.headers - ['key'] | |
locales.each do |locale| | |
keys = [locale, row['key'].split('.')].flatten.map(&:to_sym) | |
last_key = keys.pop | |
translations.dig(*keys)[last_key] = row[locale] | |
end | |
end | |
end | |
translations.each do |locale, _translations| | |
File.write("config/locales/#{locale}.yml", _translations.to_yaml) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment