首页 > 解决方案 > 国际化 Fluter by intl

问题描述

我学会了颤振。我使用 intl 依赖项构建了一个国际化应用程序(遵循

  1. 我很好地运行了第一个命令(没有错误消息):
flutter packages pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/main.dart

生成了 3 个文件:

在此处输入图像描述

  1. 我需要在运行下一个命令之前创建 intl_{locale}.arb 文件

  2. 下一个命令:

颤振包发布运行 intl_translation:generate_from_arb \ --output-dir=lib/l10n --no-use-deferred-loading \ lib/main.dart lib/l10n/intl_*.arb

尽管生成了相应的消息(messages_en.dart)文件,但它始终返回消息:

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.

如何在没有消息的情况下运行第二个命令,因为我认为它们是意外消息?

标签: dartflutterintl

解决方案


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

推荐阅读