🌍 Localization
We're using flutter_localizations
package which generates code automatically based on lib/src/localization/*.arb
language files.
Supporting new languages
To add another language to the app:
- add a
app_xx.arb
where xx is a two letter language code (eg. pl for Polish, es for Spanish). It must contain translated strings for all keys fromapp_en.arb
(except ones with a@
prefix, those are for added context for the translator), - add new supported Locale to
supportedLocales
list inlib/app.dart
(eg.Locale('pl', '')
for Polish,Locale('es', '')
for Spanish).
Using defined strings
After code generation all of the defined strings will be available for widgets from AppLocalizations.of(context)
.
Eg. to read an appTitle
field in the Text widget: Text(AppLocalizations.of(context)!.appTitle)
.
Testing with AppLocalizations
If a widget to test uses AppLocalizations
, you will have to wrap it with MaterialApp
and provide localizationsDelegates: AppLocalizations.delegate
like so:
const myWidget = MaterialApp(
localizationsDelegates: [
AppLocalizations.delegate,
],
home: TestWidget(),
);
- Flutter docs: link