json - 如何在颤振中使用 l10n 本地化翻译从 JSON 文件填充的列表?
问题描述
我有很长的项目列表,这些项目使用 JSON 文件中写入的数据填充。我在 JSON 中有一组类别,然后在我的应用程序中将它们制成一个列表。
"categories": [
{ "id" : 1, "name" : "Category number 1" , "icon" : "assets/icons/risk.png"},
{ "id" : 2, "name" : "Some random Cat Name For Testing That is Long" , "icon" : "assets/icons/risk.png"},
{ "id" : 3, "name" : "Cat3" , "icon" : "assets/icons/risk.png", "details": ""},
{ "id" : 4, "name" : "Cat4" , "icon" : "assets/icons/risk.png"},
{ "id" : 4, "name" : "Cat4" , "icon" : "assets/icons/risk.png"},
{ "id" : 4, "name" : "Cat4" , "icon" : "assets/icons/risk.png"},
{ "id" : 4, "name" : "Cat4" , "icon" : "assets/icons/risk.png"},
{ "id" : 4, "name" : "Cat4" , "icon" : "assets/icons/risk.png"},
{ "id" : 4, "name" : "Cat4" , "icon" : "assets/icons/risk.png"},
...(列表继续这样)。
数据通过以下方式加载到应用程序中:
void getData() async{
final read = await rootBundle.loadString('assets/strings/risk_categories.json');
final data = await json.decode(read);
setState(() {
if(data != null){
_items = data["categories"];
_description = data["description"].toString();
}
});
}
我的问题是,我怎样才能使这些数据容易受到语言变化的影响。我尝试将它以相同的格式放在 .arb 文件中,但它坚持将字符串作为值并且不会接受我的数组。有没有办法在 arb 或其他东西中搜索相同的值?我在这里错过了什么吗?
谢谢您的帮助!
解决方案
推荐阅读
- python - TypeError 的 Python PWManager 问题:“NoneType”类型的对象没有 len()
- c# - 尝试从实时数据库绑定数据以获取列表视图
- swift - Swift:促销产品(使用 RevenueCat)- 缓存 defermentBlock
- angular - 将 id 从组件传递到 service.ts Angular
- authentication - 为什么说 JWT 代币是无状态的
- css - 引导样式未正确应用于应用程序中的所有元素
- git - Github:增量发送 git 对象(或分批发送)
- java - 为什么 IntelliJ 不让我测试这个特定的方法?
- reactjs - 有没有办法将 React 组件视为字符串?
- python - AttributeError:“dict”对象没有属性“data”