Flutter .arb Localization
Lingo.dev supports Flutter's Application Resource Bundle (.arb) format, making it easy to manage translations for your Flutter apps across multiple platforms.
Setting Up
To use Lingo.dev with .arb files, configure your i18n.json
as follows:
{
"version": 1.2,
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"flutter": {
"include": ["lib/l10n/[locale].arb"]
}
}
}
TIP
Note the use of [locale]
in the path, which Lingo.dev will replace with the appropriate locale code.
How It Works
The .arb file is a JSON-based format that Flutter uses for localization. It supports both simple key-value pairs and more complex structures for pluralization and placeholders.
Here's an example of an .arb file structure:
{
"helloWorld": "Hello World!",
"@helloWorld": {
"description": "The conventional newborn programmer greeting"
},
"welcomeUser": "Welcome, {username}!",
"@welcomeUser": {
"description": "A welcome message",
"placeholders": {
"username": {
"type": "String",
"example": "John Doe"
}
}
},
"itemCount": "{count, plural, =0{No items} =1{1 item} other{{count} items}}",
"@itemCount": {
"description": "A message showing the number of items",
"placeholders": {
"count": {
"type": "num",
"format": "compact"
}
}
}
}
Localizing
To localize your .arb files, run:
npx lingo.dev@latest i18n
Lingo.dev will process your source .arb file and create or update the target language files.
Features
Simple Strings: Lingo.dev handles basic key-value translations.
Placeholders: The loader preserves placeholders like
{username}
in translated strings.Pluralization: Lingo.dev supports Flutter's plural syntax, ensuring correct translations for different quantity scenarios.
Metadata: The loader preserves metadata for each string, including descriptions and placeholder information.
Incremental Updates: Only new or changed strings are translated, saving time and processing power.
Pro Tips
Consistency: Use consistent naming conventions for your ARB keys across your project.
Context: Utilize the
description
field in your ARB files to provide context: Lingo.dev's AI takes this into account for more accurate translations.Placeholders: When using placeholders, provide examples in the ARB file. This helps Lingo.dev's AI understand the context better.
Testing: Use Flutter's built-in localization testing tools to ensure your translations work correctly in your app.
Multiple Files: If your project uses multiple .arb files, you can include them all in your
i18n.json
config:json"flutter": { "include": [ "lib/l10n/[locale].arb", "lib/l10n/[locale]_additional.arb" ] }
By leveraging these features and tips, you can maintain a robust, scalable localization setup for your Flutter projects using the .arb format, seamlessly integrating with your existing development workflow.
For more information on other localization formats supported by Lingo.dev, check out our documentation for other file types.