tryParse static method
Implementation
static Locale? tryParse(String source) {
if (source.isEmpty || source.trim().length != 5) return null;
List<String> codes = [];
if (source.contains("_")) {
codes = source.split("_");
} else if (source.contains("-")) {
codes = source.split("-");
}
if (codes.isEmpty || codes.length != 2) return null;
final lc = codes.first;
final cc = codes.last;
return Locale(lc, cc);
}