Skip to content

Instantly share code, notes, and snippets.

@amatsuda
Created October 2, 2010 18:26
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 amatsuda/607863 to your computer and use it in GitHub Desktop.
Save amatsuda/607863 to your computer and use it in GitHub Desktop.
#!/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