POEditor Integration For Flutter Application (Using Chopper)

Ivan Terekhin
1 min readFeb 8, 2020

--

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.

--

--

Ivan Terekhin
Ivan Terekhin

Written by Ivan Terekhin

Mobile developer (Android, iOS, Flutter), AI and GameDev enthusiast. https://www.indiehackers.com/jeuler

No responses yet