translate method
Implementation
String translate(String uid, {String? lang}) {
if (isConnected) {
if (lang != null || defaultLang != null) {
List<dynamic> translationsFound = translations
.where((translation) => translation['uid'] == uid)
.toList();
if (translationsFound.length == 1) {
List<dynamic> translationsTexts = translationsFound
.first['translation_set']
.where((translation) => doesContain(
translation['lang'], lang == null ? defaultLang! : lang))
.toList();
if (translationsTexts.length == 1) {
return translationsTexts.first['default'];
} else {
return translationsFound.first['translation_set'].first['default'];
}
} else {
throw Exception("UID $uid couldn't be found!");
}
} else {
throw Exception(
"lang is mandatory for translate() if no default lang have been provided");
}
} else {
throw Exception("not connected to API");
}
}