normLocale function
Normalizes localeString
with targetSeparator
to have consistency around
the naming conventions usage in the CLI (and other tools)
Implementation
String normLocale(String localeString, [String targetSeparator = '_']) {
/// take only lang code and country code. (zh_Hant_HK, fr_FR, fr_CA)
localeString = localeString.trim().toLowerCase();
localeString = localeString.replaceAll('_', '-');
final parts = localeString.split('-');
return <String>[
parts[0].toLowerCase(),
if (parts.length > 2) parts[1].titleCase,
if (parts.length > 2) parts[2].toUpperCase(),
if (parts.length == 2) parts[1].toUpperCase(),
].join(targetSeparator);
// return .take(2).join(targetSeparator);
}