Skip to content

Localization guide

nt4f04uNd edited this page May 6, 2023 · 2 revisions

Populating the app with more languages is easy.

Please read the entire documentation - this will take no more than 10 minutes of your time, but will make the process much easier for you and me.

As well as help creating the best version of the translation :-)

Prepare

Let's assume we would like to add a French localization

  1. Copy https://github.com/nt4f04uNd/sweyer/blob/master/lib/localization/arb/intl_en.arb
  2. Change its name to intl_fr.arb
  3. Add the locale to supported locales in https://github.com/nt4f04uNd/sweyer/blob/master/lib/constants/config.dart
.....
static const List<Locale> supportedLocales = [
    Locale('en', 'US'),
    Locale('ru', 'RU'),
+   Locale('fr', 'FR'),
 ];
.....

Translate

Now translate the intl_fr.arb file you just created.

For localizing the .arb, you can use some specialized software, but it's also easy to do it just by hand in a code/text editor.

The .arb format looks like this:

"key": "string"
"@key": {
  "description": "Some string"
}

Here:

  1. "key" - is the key associated with a string
  2. "string" - the actual string value that the user will see
  3. "@key" - optional section that contins key metadata, for example a description

The only thing you need to translate is the "string" part. Please leave everything else unchanged.

Translating plurals and other special strings

There are a few special string formats:

  • placeholder
  • plural
  • gender
  • select

They use ICU syntax.

Example

EN:

"tracksPlural": "{count, plural, =1{{count} track} other{{count} tracks}}"

RU:

"tracksPlural": "{count, plural, =0{{count} треков} =1{{count} трек} few{{count} трека} many{{count} треков} other{{count} трека}}",

You can see that Russian and English translations are different, so you need to come up with the one that matches your language.

The ICU message editor can help you understand what an output string will look like.

Explanation of the plural string

This string means:

  1. Accept a variable "count"
  2. Make a "plural" string
  3. For "=1" case use string "{count} track"
  4. For "other" cases use string "{count} tracks"
  5. Etc.

Links