-
Notifications
You must be signed in to change notification settings - Fork 12
How to i18n
Because the ÉTS is a university in Canada we support both English and French languages.
For the internationalizing into the application, we decided to use the recommended way by the Flutter team, you can see more using this link.
The arb
files contain all the text used by the application and can be found under the lib/l10n
folder. These files are simple json
files.
To add a simple text, follow this format:
{
"message_title": "YOUR MESSAGE"
}
If your text can be personalized for example "Welcome NAME_OF_THE_USER", use this format:
{
"message_title": "YOUR MESSAGE {parameter}",
"@message_title": {
"placeholders": {
"parameter": {}
}
}
}
Nothing more simple! Just run:
flutter pub get
And that is all! Go check under .dart_tool/flutter_gen/gen_l10n/
if you see some dart classes.
To use the text you just add or one of the other text already translated, you need to use the AppIntl
class. You can find an example to get the value of title_dashboard
:
import 'package:flutter_gen/gen_l10n/app_localizations.dart'
class ExampleLocalizedWidget extends StatelessWidget {
@override
Widget build(BuildContext context) => Text(AppIntl.of(context).title_dashboard);
}
If you need to access the AppIntl
from the core
folder, you will need to bring AppIntl from the UI side, for an example you can check LoginViewModel
(here)
To use a field with a placeholder, you will see that your AppIntl.of(context)
will contain a definition for a function where you can pass one or many Object
parameter (that will be read as a string).
import 'package:flutter_gen/gen_l10n/app_localizations.dart'
class ExampleLocalizedWidget extends StatelessWidget {
@override
Widget build(BuildContext context) => Text(AppIntl.of(context).message_title('Here is my message'));
// When the app is set in english this will render as: YOUR MESSAGE Here is my message
}
Home | Installation | How To