Skip to content

Instantly share code, notes, and snippets.

@mezza
Created June 23, 2022 15:19
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 mezza/ddef7deb8819cfde5734282c0e1211bd to your computer and use it in GitHub Desktop.
Save mezza/ddef7deb8819cfde5734282c0e1211bd to your computer and use it in GitHub Desktop.
Extract all expanded i18n keys and values
# Execute following in rails console after invoking i18n.t() on a known key to load the translations
def flatten_hash(hash)
hash.each_with_object({}) do |(k, v), h|
if v.is_a? Hash
flatten_hash(v).map do |h_k, h_v|
h["#{k}.#{h_k}".to_sym] = h_v
end
else
h[k] = v
end
end
end
flatten_hash(I18n.backend.translations[:en])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment