[Flutter development] String resource with difference language support in Flutter

This is very short article about using string resource and handle app language based on device language. And this is just basic, no advantage technique here.

Here is the Official document from Flutter: Doc

First, open pubspec.yaml file and add the following lines:

In dependencies section:

In Flutter section:

In your Flutter project add l10n.yaml file to the root project.

Content of l10n.yaml file:

arb-dir: lib/l10n: Specify app language resource file (.arb)

template-arb-file: app_en.arb: The original language file

output-localization-file: app_localizations.dart: The name of autogenerated file after run flutter command

Then in ${FLUTTER_PROJECT}/lib/l10n, add the app_en.arb and app_vi.arb which are language resource for EN and VI language code. You can then add any language resource follow the rule: app_[Language code]. Find all supported language at this link

All prepare resources are done. Now, make the app use that resources:

In your main app class, specify app localizations as follow:

Now, your app can use strings resource based on device language.

For usage:

Now, you’ve done the implementation.

Thanks for reading. For more advantage, go to the official document at this link