Skip to content

Instantly share code, notes, and snippets.

@maicher
Created May 12, 2017 15:37
Show Gist options
  • Save maicher/91a0dd7e7cc43870373aa40c66b31c71 to your computer and use it in GitHub Desktop.
Save maicher/91a0dd7e7cc43870373aa40c66b31c71 to your computer and use it in GitHub Desktop.
Script for generating translation hash. For passing I18n translations to frontend.
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