Skip to content

Instantly share code, notes, and snippets.

@alpaca-tc
Created December 18, 2017 02:10
Show Gist options
  • Save alpaca-tc/3296144cc0f48781725a5904f2390734 to your computer and use it in GitHub Desktop.
Save alpaca-tc/3296144cc0f48781725a5904f2390734 to your computer and use it in GitHub Desktop.
require 'csv'
def to_chained_key(result, hash, prefix = nil)
hash.each do |key, value|
current_key = [prefix, key].compact.join('.')
if value.is_a?(Hash)
to_chained_key(result, value, current_key)
else
result[current_key] = value
end
end
result
end
I18n.t('raise exception') rescue nil # Load translations
translations = I18n.backend.instance_variable_get(:@translations)
result = to_chained_key({}, translations[:ja])
invalid_locales = {}
headers = ['key', 'ja', 'en', '...']
CSV.open('i18n.csv', 'w', col_sep: "\t", write_headers: true, headers: headers) do |csv|
result.each do |key, value|
case value
when String, TrueClass, FalseClass
csv << [key, value]
when NilClass
csv << [key, nil]
when Array
invalid_locales[key] = value
else
raise 'unsupported'
end
end
end
puts "下記は別途対応"
puts invalid_locales
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment