我正在尝试通过遵循documentation来本地化我的Flutter应用程序。
我试图实现的是,在动态构建小部件的同时,我希望转换来自我的模型的数据。这就是我到目前为止所尝试的
List.generate(services.length, (index) {
final Service service = services[index];
return Material(
borderRadius: BorderRadius.circular(10.0),
child: Text(
AppLocalizations.of(context).{{service.title}} // Here I wanted to translate the service title
),
);
}我如何在Flutter中实现这一点?或任何其它可能的方法来翻译动态内容。
发布于 2021-02-09 15:19:25
颤动本地化软件包不支持动态翻译。您可以尝试在您的应用程序中集成google translation API。但我坚信它应该是一个服务器端特性,Flutter客户端应该在你的模型中获得已经翻译好的消息。例如,要实现这一点,您可以将http-headers与您的设备区域设置结合使用,以便将客户端的语言告知服务器。
此外,根据this guide,您还需要对Intl消息使用参数。以下是在AppLocalizations中使用字符串参数的消息示例
String someLocalizedString(String argument) => Intl.message(
'Localized part - $argument',
name: 'someLocalizedString',
locale: localeName,
args: [argument],
);.arb文件中的以下字符串:
"someLocalizedString": "Localized part - {argument}",
"@someLocalizedString": {
"type": "text",
"placeholders": {
"argument": {}
}
}https://stackoverflow.com/questions/66114113
复制相似问题