'Flutter Internationalization: translate list items (in JSON?)
I have this widget in Flutter/Dart:
Widget _buildTimeRow() {
var keys = widget.place!.openingTime.keys.toList();
var length = widget.showFull! ? keys.length : min(keys.length, 5);
return Container(
child: Column(
children: List.generate(
length,
(int index) => Container(
child: Row(
children: <Widget>[
Container(
width: 100,
child: Text(keys[index],
style: TextStyle(
fontWeight: FontWeight.w500)),
),
Expanded(
child: Container(
child: Text(widget.place!.openingTime[keys[index]] ?? "",
overflow: TextOverflow.ellipsis)),
),
],
),
))));
}
The problem is that I can not translate the Text(keys[index] part.
I tried adding this:
if (keys[index] == 1) ...[ // 1, 2, 3, 4, 5, 6 and so on.
Text(Localized.of(context)!.trans(LocalizedKey.NewWord) ?? "",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
],
This does not work. How could I get it to work so that I can translate the outcome of the list items (in the index) to be translated?
Is this even possible?
Solution 1:[1]
I created a Library that might be able to help you. It doesn't translate but you can easily create multi-lingual UI with it by storing static text values(the same text on different languages).
Try translatable_text_field package
Hope this helps ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | NewToPi |
