Internationalization Flutter by intl
Asked Answered
A

3

8

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 ?

Anemoscope answered 3/4, 2019 at 11:12 Comment(4)
have you mentioned supportedLocales? supportedLocales: [ const Locale('en', 'US'), // English const Locale('he', 'IL'), // Hebrew // ... other locales the app supports ],Physical
yep, I mentioned them in main.dart. maybe they are message not errorAnemoscope
you need to obtain a set of files similare to these (en + es in this case): intl_es.arb intl_en.arb intl_messages.arb messages_all.dart messages_es.dart messages_en.dart messages_messages.dartPhysical
yep, already. I have the files, but I always see the message No @@locale or _locale field found in intl_messages, assuming 'messages' based on the file name. this is my question now.Anemoscope
M
18

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": {}
  }
}
Moses answered 1/10, 2019 at 13:41 Comment(0)
P
2

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
Physical answered 4/4, 2019 at 9:7 Comment(2)
it does not work. 1st: I updated: flutter pub pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/main_internationalization.dart --- there is only a file generated (intl_messages.arb) 2nd command did not run: flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/main_internationalization.dart lib/l10n/intl_*.arb return error: pastebin.com/90snxBhcAnemoscope
bro, I think that it's simply response message bcz I downloaded + ran the commands with the source code from the guideline (flutter.dev/docs/development/accessibility-and-localization/…). It returned the same messages.Anemoscope
P
0

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

Physical answered 3/4, 2019 at 12:26 Comment(2)
There is only a file intl_messages.arb file which generated after I run 1st command. the file's content is the same with guideline source code already. what do you mean ?Anemoscope
hmm, creating intl_{locale}.arb file is missing. I updated my question already. How can I run 2nd without error like: No @@locale or _locale field found in intl_en, assuming 'en' based on the file name. Thanks!!!Anemoscope

© 2022 - 2024 — McMap. All rights reserved.