ARB Gen is a powerful Dart package tailored for Flutter projects, streamlining the translation and localization processes through ARB (Application Resource Bundle) files. This package automates the generation of translated ARB files, providing a seamless experience for developers and allowing them to concentrate on the translation aspect. Key features include automatic translation from a base language to multiple target languages, effortless integration with Flutter projects, and a flexible configuration setup that accommodates customization through a configuration file or command line arguments. ARB Gen also supports dynamic updates, allowing Flutter apps to receive new translations without requiring manual intervention. Developers can easily install the package by adding a dependency to their pubspec.yaml file and running flutter pub get. With straightforward usage steps and clear integration instructions, ARB Gen enhances the localization workflow, making it efficient and developer-friendly.
- Automatic Translation: Translate your content from a base language to multiple target languages with ease.
- Integration with Flutter: Easily integrate the generated translations into your Flutter project.
- Flexible Configuration: Customize the translation process with a configuration file or command line arguments.
- Dynamic Updates: Dynamically update your Flutter app with new translations without manual intervention.
Add the following dependency to your pubspec.yaml
file:
dev_dependencies:
arb_gen:
Then, run:
flutter pub get
Create a configuration file arb.gen/config.json. Here's an example configuration file:
{
"translateTo": ["fr", "es"],
"ignored": ["appName"],
"pathToFile": "arb.gen/content.json",
"outputFolder": "lib/l10n/",
"arbName": "localization",
"baseLanguage": "en",
"translater": null,
"apiKey":null,
"allAtOnce": true
}
Note: by default we prefer google translator, this aproach dont need any API-key,
if field translater
it'lll the same as 'google' .
Output directory for all generated .arb files. Defaults to 'lib/l10n'.
Property | Type | Description |
---|---|---|
translateTo | List | Codes of languages for which localization is required. |
preferredLanguage | String? | Preferred language code; if null , it defaults to the first language in translateTo . |
baseLanguage | String? | Code of the original language used in the base file. |
ignored | List | Keys from the card that don't need to be transferred. Usually, these are custom keys (e.g., the application name). |
outputClass | String? | Name of the output class for localization. Defaults to class $L{} . |
lDirName | String | Path to the local service folder. Defaults to /lib/$outPutFolder . |
arbName | String | Name for .arb files; follows the pattern arbName_languageCode.arb . |
translater | ['deepl', 'yandex', 'google', 'azure', 'microsoft', 'openAI'] | The name of the service to be translated. Defaults to Google Translator |
apiKey | String? | API key for the translation service. Not required for Google Translator. |
allAtOnce | bool? | Flag to generate all translations at once. Defaults to true . |
pathToFile | String | Path to the original .arb/.json file. Defaults to 'arb.gen/content.json'. |
Run the following command to execute the translation process:
dart run arb_gen
If allAtOnce is set to false in your configuration, follow these steps to integrate the generated translations into your Flutter project:
flutter:
generate: true
dependencies:
flutter_localizations:
sdk: flutter
intl:
arb-dir: lib/l10n
template-arb-file: localization_en.arb
output-localization-file: app_localizations.dart
Run the following command to fetch the dependencies and generate the localized files:
flutter pub get
Manually move the generated ARB files from the specified output folder (lib/l10n/ by default) to your project's localization folder.
mv generated_arb_files/* lib/l10n/
See the documentation on the website.
DE | FR | EN | ES |