Flutter ARB file (.arb)
What is an ARB file?
ARB stands for Application Resource Bundle. It is essentially a JSON file enhanced for localization, with an .arb extension. Since it is based on JSON, it just defines standardized ways of adding additional information to key-value pairs.
ARB files provide various capabilities, but here we will only mention those relevant to Flutter applications.
Sample ARB file
In the given example we have the following:
ARB file features
All localization file formats have some specific features. Here we will list those for the ARB file format, relevant for Flutter apps.
Placeholder
Placeholder is marked by curly brackets. Variable name inside {} must be a valid identifier, like {firstName}.
The simplest placeholder example:
The placeholder example with all possible parameters for DateTime and double types:
Placeholder’s type parameter can have one of the following values: String, Object, int, double, num, DateTime.
optionalParameters are available for int, double and num placeholder types, and depend on the format value:
Placeholders based on the DateTime type support a set of predefined format options, such as yMd, Hms, and similar. These format options are derived from DateFormat class constructors. In case none of these 41 format options works for you, you can use a custom date-time format by setting isCustomDateFormat to “true” and defining your custom format:
Plural
Plurals are defined with ICU syntax.
other is a mandatory case.
Gender
Genders are defined with ICU syntax.
other is a mandatory case.
Select
Custom selects are defined with ICU syntax.
other is a mandatory case.
Newline
Since an ARB file is based on the JSON format, a new line is indicated by the newline character n.Note that the actual display on the screen depends on the widget used.
Special chars
In rare situations, during the localization process, you may need to treat special characters such as { and } as regular text. This largely depends on the localization tool being used. When using the gen-l10n tool, you need to enclose the relevant section of the message in single quotes and enable the escaping mechanism.Note that other tools may not support this functionality or they might require a different approach.
HTML tags
In certain situations, it’s beneficial to use HTML tags in localization messages. This strategy prevents the message from being divided into smaller parts for styling purposes or other advantages. An example of such a message is shown below.