translate method

FutureOr<Map<String, String>?> translate(
  1. Map<String, String> entries,
  2. IntlLocale fromLocale,
  3. IntlLocale toLocale, {
  4. bool confirm = true,
})

Translates entries to locale.

Implementation

FutureOr<Map<String, String>?> translate(
    Map<String, String> entries, IntlLocale fromLocale, IntlLocale toLocale,
    {bool confirm = true}) {
  if (fromLocale == toLocale) {
    return entries;
  }

  var fromLanguage = resolveLocaleName(fromLocale);
  var toLanguage = resolveLocaleName(toLocale);

  if (fromLanguage == toLanguage) {
    return entries;
  }

  var cachedTranslation = getCachedEntries(entries, fromLocale, toLocale);

  if (cachedTranslation != null) {
    return cachedTranslation.resolveMapped((cachedTranslation) =>
        _translateEntries(entries, cachedTranslation, fromLocale, toLocale,
            fromLanguage, toLanguage, confirm));
  } else {
    return _translateEntries(entries, null, fromLocale, toLocale,
        fromLanguage, toLanguage, confirm);
  }
}