flutterdarttranslationflutter-intl

Check if flutter-intl translation exists and use it


I use flutter-intl to translate my app. I use protocol-buffers to communicate with other users. In the protocol buffer is an enum, e.g. blue, red, yellow. Now I want to translate the value of the enum and fallback to the enum variant name, if the translation does not exist. I think something like this:

String enumValStr = enumVal.toString();
AppLocalizations.of(context)!.translate(enumValStr, enumValStr);

The first would be the String I want to translate, the second a fallback. Is there such a method?


Solution

  • I decided to use a simple switch-case. This way nobody removes a needed translation without the build passing, also flutter-lints complains if an item is missing.