Using split locale files with Tolk

by tokumine

The vanilla method of storing view translations in an i18n’d Rails project is to maintain a huge locale yaml file. A step forwards is to maintain many yaml files split into folders mirroring your controller or view structure. Splitting is better for maintenance, however many tools and services, like DHH’s Tolk which can help with the actual translation of your site currently rely on your locale being in one place.

I wanted both. I’d like to maintain my base locale files in a nice split structure, whilst at the same time being able to use tools like Tolk to maintain my translations.

With your base locales arranged as described by the Rails Guides simply use the following rake task to generate an aggregated locale YAML file. To ensure no keys are overwritten, be sure to maintain your translations in their own namespaces.

Advertisements