Localisation
Acter app is supported with flutter localizations and it is already setup and defined in pubspec.yaml
.
Add new locale in the application
- Firstly go the
l10.dart
file and add the locale you want to support in the application.
class ApplicationLocalizations {
static final supportedLocales = [const Locale('en'), const Locale('de')];
}
- Create an
.arb
extension file in l10 directory. Here you can add your locale strings with key-value pairs as in JSON format. For example
{
"language": "English",
"all": "all",
"noMessages": "No Conversations yet",
"loading": "loading",
}
- Save the file and rebuild the project. Verify that the localization file has been successfully generated in your project build files. The generated path from root directory is
dart_tool/flutter_gen/app_localizations_en.dart
, in case the locale is english.
Add new localized text in the application
- Navigate to
app_en.arb
file. - Add a new key-value pair containing the string. For Example:
{
"language": "English",
"all": "all",
"noMessages": "No Conversations yet",
"loading": "loading",
"news": "news"
}
- To support this text in deutsch. We also need to update
app_de.arb
.
{
"language": "Deutsch",
"all": "alle",
"noMessages": "Noch keine Gespräche",
"loading": "Wird geladen",
"news": "Nachrichten",
}
- Save the file and rebuild the project. You can use your new localized string in your dart files.
Text(AppLocalizations.of(context)!.news);