selectTranslation static method

PTAlertTranslation? selectTranslation(
  1. List<PTAlertTranslation> translations,
  2. String language
)

Select the best translation from translations for language.

Picks the first entry whose PTAlertTranslation.language equals language, otherwise falls back to the first entry. The language tags come verbatim from the feed and may be inaccurate.

Parameters

  • translations: (List<PTAlertTranslation>) Translations to select from.
  • language: (String) Language tag to match, e.g. en.

Returns

  • (PTAlertTranslation?) The selected translation, or null when translations is empty.

Implementation

static PTAlertTranslation? selectTranslation(
  List<PTAlertTranslation> translations,
  String language,
) {
  if (translations.isEmpty) {
    return null;
  }

  for (final PTAlertTranslation translation in translations) {
    if (translation.language == language) {
      return translation;
    }
  }

  return translations.first;
}