Created
June 23, 2022 15:19
-
-
Save mezza/ddef7deb8819cfde5734282c0e1211bd to your computer and use it in GitHub Desktop.
Extract all expanded i18n keys and values
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
# 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