Created
May 12, 2017 15:37
-
-
Save maicher/91a0dd7e7cc43870373aa40c66b31c71 to your computer and use it in GitHub Desktop.
Script for generating translation hash. For passing I18n translations to frontend.
This file contains hidden or 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
def print_translations(hash, phrase_key, i = 0) | |
hash.each do |k, v| | |
if v.is_a?(Hash) | |
i.times { print ' ' } | |
print "#{k.to_s.camelize(:lower)}: {\n"; | |
print_translations(v, "#{phrase_key}.#{k}", i + 1) | |
i.times { print ' ' } | |
print "},\n" | |
else i.times { print ' ' } | |
print "#{k.to_s.camelize(:lower)}: t('#{phrase_key}.#{k}'),\n" | |
end | |
end | |
nil | |
end | |
# How to use: | |
print_translations(I18n.t('bookings.checkout'), 'bookings.checkout') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment