-
-
Notifications
You must be signed in to change notification settings - Fork 47
Localization guide
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 :-)
Let's assume we would like to add a French localization
- Copy https://github.com/nt4f04uNd/sweyer/blob/master/lib/localization/arb/intl_en.arb
- Change its name to
intl_fr.arb
- 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'),
];
.....
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:
-
"key"
- is the key associated with a string -
"string"
- the actual string value that the user will see -
"@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.
There are a few special string formats:
- placeholder
- plural
- gender
- select
They use ICU syntax.
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.
This string means:
- Accept a variable "count"
- Make a "plural" string
- For "=1" case use string "{count} track"
- For "other" cases use string "{count} tracks"
- Etc.
- In-depth .arb format documentation - https://localizely.com/flutter-arb/
- ICU message editor - https://localizely.com/icu-message-editor/