POEditor Integration For Flutter Application (Using Chopper)
So, you have something like flutter_translate( https://pub.dev/packages/flutter_translate) for your localization and now you have the following trouble — you want to use translations from online services, such as POEditor (nice thing) but without GitHub integration, just raw API (https://poeditor.com/docs/api).
I finished up by storing the values in SharedPreferences and falling back to assets resources.
This is how that looks:
final locale = Localizations.localeOf(context).languageCode;
if (localStorage.containsKey('$locale/$resourceId')) {
return localStorage.getString('$locale/$resourceId');
} else {
return translate(resourceId) ?? resourceId;
}
I’m taking the current locale and checking the storage (which is https://pub.dev/packages/shared_preferences). I found this method okay for my situation, maybe the DB is a more proper way of doing it, but the SharedPrefs method working just fine.
As for the setting up the WebService for the Localization files retrieval — I’m using Chopper ( https://pub.dev/packages/chopper). Please pay attention to the fact that you need to use POST queries and you need to FormUrlEncodedConverter() for your converter parameter during WebServer instance setup.