【发布时间】:2020-12-07 13:14:29
【问题描述】:
我正在尝试遵循 https://flutter.dev/docs/development/accessibility-and-localization/internationalization#dart-tools 和 https://docs.google.com/document/d/10e0saTfAv32OZLRmONy866vnaw0I2jwL8zukykpgWBc/edit#heading=h.upcu5w85cvc2 中的国际化文档,但它没有生成任何文件。
基本上它说要在 pub spec.yaml 文件中制作这些模组:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.17.0-nullsafety.2
flutter:
generate: true
然后创建一个<project-root>/l10n.yaml 文件,其中包含:
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
最后用这样的东西创建app_en.arb:
{
"@@locale": "en",
"helloWorld": "Hello World!",
"@helloWorld": {
"description": "The conventional newborn programmer greeting"
}
}
从那里指南说将自动生成一个flutter_gen/gen_l10n/app_localizations.dart 文件。
除了什么都没有发生。我在 Android Studio 中工作并做了一个pub get,并尝试了一个flutter clean 和flutter build ios 以及我想不到的所有其他内容,但没有构建该文件。
有什么想法吗?
【问题讨论】:
-
对我来说,文件名和
.yaml配置名是i10n而不是l10n。 -
@ArieDov 这个名字确实是
l10n(小写L),而不是i10n。如果这对你有用,那意味着你把它和其他地方的名字搞砸了。 -
天啊,我刚刚注意到我的本地化文件没有在应用程序运行时自动生成,因为我在
lib/文件夹中创建了文件l10n.yaml。但它清楚地写着to the root directory of the Flutter project。我更改了位置,现在它按预期工作。
标签: flutter internationalization