localeValueFromMap function
Converts a dynamic map to a map of UiLanguages and their corresponding values.
Throws an UnimplementedError if the input is neither a String nor a Map.
map
The dynamic input to convert.
Implementation
Map<UiLanguage, String> localeValueFromMap(final dynamic map) {
if (map is String) {
return {};
} else if (map is Map) {
if (map.isEmpty) {
return {
for (final lang in LocalizationConfig.instance.supportedLanguages)
lang: '',
};
}
final localeMap = <UiLanguage, String>{};
for (final key in map.keys) {
final language = UiLanguage.byCode(key);
if (language == null) continue;
localeMap[language] = map[key];
}
return localeMap;
} else {
throw UnimplementedError('localeValueFromMap $map');
}
}