Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internationalization Fluter by intl

Tags:

flutter

dart

intl

I've learned flutter. I built an internationalized app using the intl dependency (follow this)

  1. I run 1st command well (no error message):
flutter packages pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/main.dart

3 files were generated:

enter image description here

  1. I need to create intl_{locale}.arb file before run next command.

  2. Next command:

flutter packages pub run intl_translation:generate_from_arb
--output-dir=lib/l10n --no-use-deferred-loading
lib/main.dart lib/l10n/intl_*.arb

It always returns a message although the corresponding message (messages_en.dart) file is generated:

No @@locale or _locale field found in intl_en, assuming 'en' based on the file name.
No @@locale or _locale field found in intl_messages, assuming 'messages' based on the file name.

How can I run the 2nd command without the messages, because I think they are unexpected messages ?

like image 578
Mr Special Avatar asked Apr 03 '19 11:04

Mr Special


2 Answers

You should write in each file the following. Then flutter will automatically identify the language.

{
  "@@locale": "en",
  "title": "Flutter Example App",
  "@title": {
    "type": "text",
    "placeholders": {}
  }
}
like image 87
Gabriela Dias de Souza Avatar answered Oct 17 '22 06:10

Gabriela Dias de Souza


1.

flutter packages pub run intl_translation:generate_from_arb \ --output-dir=lib/l10n --no-use-deferred-loading \ lib/main.dart lib/l10n/intl_*.arb

should be changed to:

flutter pub pub run intl_translation:extract_to_arb --output-dir=lib/l10n ****lib/DemoLocalizations.dart****

(where ****lib/DemoLocalizations.dart**** should be update to the file where you created this file from the steps you created.

2.

you will have the strings generated. these need to copied to intl*.arb

3.

then you should run:

flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/l10n    --no-use-deferred-loading ****lib/DemoLocalizations.dart**** lib/l10n/intl_*.arb
like image 21
Durdu Avatar answered Oct 17 '22 07:10

Durdu