translate static method

String translate(
  1. String word
)

Possibly translate the supplied word.

Implementation

static String translate(String word) {
  // If we have no means to determine the translation.
  // Keep testing. It could change.
  if (_appLocale?.languageCode == null) {
    //
    return word;
  }

  // Established the right translation.
  if (_localeSet) {
    if (_thisTranslation.isEmpty || !_thisTranslation.containsKey(word)) {
      // No translation available.
      return word;
    } else {
      // Translate.
      return _thisTranslation[word]!;
    }
  } else {
    // The Translations have possibly changed.
    if (_thisTranslation.isNotEmpty) {
      _thisTranslation.clear();
    }
  }

  // If a new Locale occurs this will be reset.
  _localeSet = true;

  var translations = _getTranslations(_appLocale);

  if (translations == null) {
    // If not the 'default' Locale, assign instead the backup.
    if (_appLocale != _prevLocale && _backupLocale != null) {
      //
      translations = _getTranslations(_backupLocale);
    }
  }

  String firstWord = word;

  if (translations != null) {
    // Record the translations to use.
    _thisTranslation.addAll(translations);

    if (translations.containsKey(firstWord)) {
      //
      firstWord = translations[firstWord]!;
    }
  }

  return firstWord;
}