Mr Special
Mr Special

Reputation: 1676

Internationalization Flutter by 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 ?

Upvotes: 8

Views: 10911

Answers (3)

Gabriela Dias de Souza
Gabriela Dias de Souza

Reputation: 181

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": {}
  }
}

Upvotes: 18

Durdu
Durdu

Reputation: 4849

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

Upvotes: 2

Durdu
Durdu

Reputation: 4849

Between the steps you mentioned 1. and 2. you should copy the new strings to intl*.arb.

Upvotes: 0

Related Questions