FLUTTER: Localization of a multi-screen app

2,886

Solution 1

Are you trying to implement in-app localization? i.e. just changing the app's locale without it being affected by the phone's locale? Then you can refer to this blog: https://blog.geekyants.com/flutter-in-app-localization-438289682f0c

The result would look something like this:

In-App Localization

Solution 2

To extract intl messages via intl_translation into .arb file, you just need to call once extract_to_arb command with the relative paths of the files that contain those messages.

pub run intl_translation:extract_to_arb --output-dir=target/directory my_program.dart more_of_my_program.dart

Once you translate your extracted messages, you will need to generate .dart localization files via generate_from_arb command.

Quickly, you will notice that that becomes tedious, so a better solution would be to use Flutter Intl extension for VS Code or Flutter Intl plugin for Android Studio. Using them, you will only need to update your localization files (.arb files), and boilerplate code will be automatically generated.

Hope it helps!

Share:
2,886
DCanalia
Author by

DCanalia

Updated on November 22, 2022

Comments

  • DCanalia
    DCanalia over 1 year

    i'm creating a multi screen app on android using Flutter. I'm using intl to localize it, but i don't understand how to procede to create the arb file. Should i run the following commaand flutter pub pub run intl_translation:extract_to_arb --output-dir=lib\l10n lib\main.dart command for every "page/activity/fragment" of my app?

    • Mike76
      Mike76 over 3 years
      In addition to "int", I recommend "attranslate" for a semi-automated synchronization of ARB or JSON-files: github.com/fkirc/attranslate Otherwise, it could become very tedious to synchronize ARB files manually.