我正在使用 Localizely 的 Flutter Intl 插件来本地化我的应用程序。我为我想要的语言生成了 arb 文件并开始介绍翻译。
例如:
{
"documentsSection": "All the documents",
"favouritesSection": "Favourites",
"newsSection": "News",
"settingsSection": "Settings"
}
Run Code Online (Sandbox Code Playgroud)
每次我想本地化我使用的文本时:
S.of(context).favouritesSection;
Run Code Online (Sandbox Code Playgroud)
它完美地工作。
但是,当我有这样的列表时:
List<Strings> sectionTitles = ["documentsSection","favouritesSection","newsSection","settingsSection"]
Run Code Online (Sandbox Code Playgroud)
我在这样一个 itemBuilder 循环中:
itemBuilder: (context, index) {
String sectionName = sectionTitles[index];
return Text(
S.of(context).sectionName,
),
},
Run Code Online (Sandbox Code Playgroud)
显然这不起作用,因为“sectionName”不是 arb 文件中的键。但我认为代码表达了我想要实现的目标。可能有人可以帮助我。提前致谢。