2

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?

Shady Mohamed Sherif
  • 15,003
  • 4
  • 45
  • 54
DCanalia
  • 21
  • 1
  • 2
  • In addition to "int", I recommend "attranslate" for a semi-automated synchronization of ARB or JSON-files: https://github.com/fkirc/attranslate Otherwise, it could become very tedious to synchronize ARB files manually. – Mike76 Nov 13 '20 at 20:21

3 Answers3

3

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

Rohan Taneja
  • 9,687
  • 3
  • 36
  • 48
1

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!

Zoran Luledzija
  • 336
  • 1
  • 9
0

Start by generating the strings files: 1. Extract all messages to arb file format, which is the template for translations (you can specify multiple files as input.

> flutter pub pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/first_file.dart lib/second_file.dart
  1. Generate translation files in arb format for each language in the form intl_messages_.arb
  2. Generate .dart files for the translations (specify one output for each translation):

    flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/l10n \ --no-use-deferred-loading lib/first_file.dart lib/second_file.dart lib/l10n/intl_messages_en.arb lib/l10n/intl_messages_.arb

Derek Lakin
  • 16,179
  • 36
  • 51