Skip to content

Create a New Locale (Language)

Brian Scoles edited this page Dec 31, 2020 · 5 revisions

Locales are the backbone of i18n-migrations. Let's use Japanese (JP) as an example. To create a new locale:

1. Add a locale entry to .i18n-migrations.yml

Add your locale to the other_locales section. It should look like:

other_locales:
  ja:
    name: Japanese

If you are using CrowdTranslate, you don't need the google spreadsheet line.

2. Create a new locale file w/ default translations

$ i18n-migrate new_locale jp

This will use Google Translate to translate all terms in your main locale to your Japanese.

It's highly likely Google Translate will mess up template variables (e.g. %{name}). To detect these types of errors and automatically fix some of them, run

$ i18n-migrate validate jp

You can do this repeatedly.

3. (If using Google Spreadsheets) Add the Google Spreadsheet

Create a spreadsheet for the new language. It should have these column headers: key | en | jp if your main locale is en and your new locale is jp. Add a link to this spreadsheet to your i18n-migrations.yml file. It should look like this:

jp:
  name: Japanese
  google_spreadsheet: https://docs.google.com/spreadsheets/d/16uEAgHjazxodOYasbLTO3sViZugWcm57Y0123456789/edit

Set the sharing to "Anyone with the link can edit".

4. Push the new locale

$ dotenv -f ".env" i18n-migrate push -f jp

(the -f means it won't try to pull first)

This will push your changes up to either CrowdTranslate or Google Spreadsheets so others can see it.

After this is done, you will likely need to manually mark all the new terms as 'autotranslated' and 'needs review'. (This is a quirk with how Crowd Translate interprets brand-new locales). You can access the app's rails console and bulk-update all the new keys that way. e.g.:

Term.where(locale: Locale.find_by(name: "Japanese")).update_all(needs_review: true, autotranslated: true)
Clone this wiki locally