Language.fromIsoCode constructor
Language.fromIsoCode(
- String isoCode
Finds a language in Languages.defaultLanguages by its code.
The codes are ISO 639-1 ('ko'), except that Chinese is split by script: 'zh_Hans' and 'zh_Hant'. The lookup ignores case, so 'ko' and 'KO' both find Korean.
Throws an ArgumentError if there is no such language. Note that ArgumentError is an Error, not an Exception.
Implementation
factory Language.fromIsoCode(String isoCode) {
final String lower = isoCode.toLowerCase();
for (final Language language in Languages.defaultLanguages) {
if (language.isoCode.toLowerCase() == lower) return language;
}
throw ArgumentError.value(isoCode, 'isoCode', 'Not a supported ISO code');
}