setPluralResolver method
void
setPluralResolver({
- String? language,
- E? locale,
- PluralResolver? cardinalResolver,
- PluralResolver? ordinalResolver,
Sets plural resolvers.
See https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
See https://github.com/slang-i18n/slang/blob/main/slang/lib/api/plural_resolver_map.dart
Either specify language
, or locale
. locale
has precedence.
Implementation
void setPluralResolver({
String? language,
E? locale,
PluralResolver? cardinalResolver,
PluralResolver? ordinalResolver,
}) {
final List<E> targetLocales;
if (locale != null) {
// take only this locale
targetLocales = [locale];
} else if (language != null) {
// map to language
targetLocales =
utils.locales.where((l) => l.languageCode == language).toList();
} else {
throw 'Either language or locale must be specified';
}
// update translation instances
for (final curr in targetLocales) {
final overrides = translationMap[curr]!.$meta.overrides;
translationMap[curr] = curr.build(
// keep old overrides
overrides: overrides.isNotEmpty ? overrides : null,
cardinalResolver: cardinalResolver,
ordinalResolver: ordinalResolver,
);
}
}