Skip to content

Instantly share code, notes, and snippets.

@johnbintz
Created May 17, 2013 14:44
Show Gist options
  • Save johnbintz/5599504 to your computer and use it in GitHub Desktop.
Save johnbintz/5599504 to your computer and use it in GitHub Desktop.
Autogenerate and autosort missing i18n translation keys for a Rails application while running Cucumber features
# Put this in features/support/hooks.rb and add i18n-missing_translations and i18n_yaml_sorter to your Gemfile
require 'i18n/missing_translations'
require 'i18n_yaml_sorter'
at_exit do
require 'yaml'
data = YAML.load_file('config/locales/en.yml')
data.deep_merge!(I18n.missing_translations)
output = StringIO.new(YAML.dump(data))
File.open('config/locales/en.yml', 'wb') { |fh| fh.puts I18nYamlSorter::Sorter.new(output).sort }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment