setPluralResolver method

void setPluralResolver({
  1. String? language,
  2. E? locale,
  3. PluralResolver? cardinalResolver,
  4. PluralResolver? ordinalResolver,
})

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,
    );
  }
}