dvLanguageOf function
The language subtag of locale, lower-cased.
Both separators are accepted because both are in the wild: BCP 47 writes
fr-CA and Dart's Locale prints fr_CA.
Implementation
String dvLanguageOf(String locale) {
final String trimmed = locale.trim().toLowerCase();
for (int i = 0; i < trimmed.length; i += 1) {
final String c = trimmed[i];
if (c == '-' || c == '_') return trimmed.substring(0, i);
}
return trimmed;
}