Posted over 10 years ago. Visible to the public. Repeats.

Organize large I18n dictionary files in Rails 3+

If you're suffering from a huge de.yml or similiar file, cry no more. Rails lets you freely organize your dictionary files in config/locales.

My organization works like this:

  • config/locales/ modified Rails boilerplate Archive
  • config/locales/ modified Faker boilerplate Archive
  • config/locales/ model names, attribute names, assignable_value labels
  • config/locales/ text in the GUI
  • config/locales/ if you organize your CSS with BEM you can use this instead of (or together with) views.<locale>.yml for text in the GUI
  • config/locales/de.yml various one liners that don't really fit anywhere else yet. extract lines to separate files as you see clusters of translations emerging.

Note that Rails really doesn't care if the name of the locale (e.g. de or en) appears in the file. Since the root node of each YAML tree is the locale code, it can just merge all files together.

At least in Rails 4+ you need to restart your server if you add files to config/locale.

Using subfolders

You can also use subfolders, but then you need to say in your application.rb:

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

Rails 2 compatibility

I only tested this with Rails 3. Note that the functionality above might not even be delivered by Rails itself, but by the i18n gem. You might need to update that instead.

Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Henning Koch
Last edit:
almost 6 years ago
by Judith Roth
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more