assign method
Assign the Map of applyContent
which contains Locale with script code
only as a key and a String of country code as value.
If does not apply script code or applied country code into Locale, it throws ArgumentError. The same error will be thrown when the value of country code is invalid.
The country code will be modified if replaceExisted
is enabled and
the given Locale has been assigned already. By default, this option
is disabled.
Implementation
void assign(Map<Locale, String> applyContent, {bool replaceExisted = false}) {
final Map<Locale, String> cloneAC = Map.from(applyContent)
.map((key, value) => MapEntry(key, value.toUpperCase()));
if (cloneAC.keys.any((element) =>
element.countryCode != null || element.scriptCode == null)) {
throw ArgumentError(
"The Locale object must provide script code and do not apply country code.");
} else if (cloneAC.values.any(
(element) => !_countryCode.union(_customRegion).contains(element))) {
throw ArgumentError(
"At least one of the country codes is invalid and unable to resolved.");
}
if (!replaceExisted) {
cloneAC.removeWhere((key, _) => _localCountryMapper.containsKey(key));
}
_localCountryMapper.addAll(cloneAC);
}