Flutter .arb
Flutter .arb (Application Resource Bundle) file format is the Native format for Flutter applications. It not only stores the localization keys and values
but also the metadata about the key like description
and placeholders
. Flutter's message format is very similar to the
ICU Message Format,
but it does not store the parameter types in the actual ICU string but in the metadata.
{
"user_settings_password": "Password",
"user_greeting": "Hello, {user_name}!",
"@user_greeting": {
"placeholders": {
"user_name": {
"type": "String",
"example": "Peter"
}
}
},
"dogs_count": "{count, plural, one {I have {count} dogs.} other {I have {count} dogs.}}",
"@dogs_count": {
"placeholders": {
"count": {
"type": "int",
"format": "compactLong",
"example": "1"
}
}
}
}
As you can see in the above example, the message parameters don't contain the type information, but the metadata does.
Another important difference to the standard ICU Message format
is that the #
symbol in plural form isn't replaced with
the actual number, so you have to repeat the placeholder again ({count}
in the example above).
Metadata Import
When importing the .arb file, the metadata are stored in the Custom Values
field of the key.
e.g. For the user_greeting
key, the metadata will be stored this way:
{
"_flutterArbPlaceholders": {
"count": {
"type": "int",
"format": "compactLong",
"example": "1"
}
}
}
To see the imported metadata, open the Key Edit
dialog by clicking the key name in the Tolgee platform and go to
Custom Values
tab.
Read more about Custom Values here.
When exporting, Tolgee exports to the .arb file with this metadata when provided. The parameter types provided directly
in the ICU Message Format in Tolgee are ignored. For example, translation Today is {date, date}
, will be exported to
the .arb file as Today is {date}
. To provide the parameter type, you need to provide the metadata
in the Custom Values
.
The MessageFormat and placeholder conversion
Tolgee doesn't convert Flutter placeholders to ICU placeholders because the Flutter Message format is effectively a subset of ICU. When exporting to .arb, Tolgee discards the type information from the ICU Message Format, so it's a valid string for Flutter MessageFormat class.
Importing / Exporting in general
To read more about importing and exporting with Tolgee, continue to import section or export section.