Created
October 2, 2010 18:26
-
-
Save amatsuda/607863 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# taken from tolk | |
PLURALIZATION_KEYS = ['zero', 'one', 'two', 'few', 'many', 'other'] | |
def pluralization_data?(data) | |
keys = data.keys.map(&:to_s) | |
keys.all? {|k| PLURALIZATION_KEYS.include?(k) } | |
end | |
def flat_hash(data, prefix = '', result = {}) | |
data.each do |key, value| | |
current_prefix = prefix.present? ? "#{prefix}.#{key}" : key | |
if !value.is_a?(Hash) | |
result[current_prefix] = value.respond_to?(:stringify_keys) ? value.stringify_keys : value | |
elsif pluralization_data?(value) | |
result[current_prefix] = value.respond_to?(:stringify_keys) ? value.stringify_keys : value | |
else | |
flat_hash(value, current_prefix, result) | |
end | |
end | |
result.stringify_keys | |
end | |
I18n.locale = :en | |
I18n.t :hoge | |
translations = flat_hash I18n.backend.instance_variable_get('@translations')[:en] | |
I18n.locale = :ja | |
translations.each do |key, value| | |
# trash | |
next if key == 'hello' | |
# useless for Japanese | |
next if key =~ /^number.human.decimal_units/ | |
p key | |
I18n.t key, :raise => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment