selectTranslation static method
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
translationsis 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;
}