localizeAllVersions function

Map<String?, String> localizeAllVersions(
  1. String key,
  2. ITranslations translations, {
  3. String? locale,
})

Returns a map of all translated strings, where modifiers are the keys. In special, the unversioned text is indexed with a null key.

Implementation

Map<String?, String> localizeAllVersions(
  String key,
  ITranslations 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};

  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;
}