localizeAllVersions function
Map<String?, String>
localizeAllVersions(
- Object? key,
- Translations<
dynamic, Map< translations, {StringLocale, StringTranslated> , Map<dynamic, StringTranslated> , dynamic> - String? locale,
Use the localizeAllVersions method to return a Map of all translated strings,
where modifiers are the keys. In special, the unversioned text is indexed with a null key.
If locale is not provided (it's null), the method will use the default locale
in DefaultLocale.locale (which may be set with DefaultLocale.set.
If both locale and DefaultLocale.locale are not provided, it defaults to 'en_US'.
This function is visible only from the i18_exception_core package.
The i18_exception package uses a different function with the same name.
Implementation
Map<String?, String> localizeAllVersions(
Object? key,
Translations translations, {
String? locale,
}) {
locale = locale?.toLowerCase();
String total = localize(key, translations, locale: locale);
if (!total.startsWith(_splitter1)) {
return {null: total};
}
List<String> parts = total.split(_splitter1);
if (parts.isEmpty) return {null: key.toString()};
Map<String?, String> all = {null: parts[1]};
for (int i = 2; i < parts.length; i++) {
var part = parts[i];
List<String> par = part.split(_splitter2);
String version = par[0];
String text = (par.length == 2) ? par[1] : "";
if (version.isEmpty)
throw TranslationsException("Invalid text version for '$part' "
"(key: '$key', "
"locale: '${_effectiveLocale(locale)}').");
all[version] = text;
}
return all;
}