lookupByLanguageCode static method
Resolve country by language code.
Implementation
static Country? lookupByLanguageCode(String languageCode) {
final normalized = languageCode.trim().replaceAll('_', '-');
if (normalized.isEmpty) {
return null;
}
final segments = normalized.split('-');
if (segments.length > 1) {
final regionCode = segments.last.toUpperCase();
final regionCountry = CountryData.getCountryByCode(regionCode);
if (regionCountry != null) {
return regionCountry;
}
}
final language = segments.first.toLowerCase();
final mappedCountryCode = _languageToCountryCode[language];
if (mappedCountryCode == null) {
return null;
}
return CountryData.getCountryByCode(mappedCountryCode);
}