plural static method

Implementation

static String? plural(
    TranslationMetadata meta, String path, Map<String, Object> param) {
  final node = meta.overrides[path];
  if (node == null) {
    return null;
  }
  if (node is! PluralNode) {
    print('Overridden $path is not a PluralNode but a ${node.runtimeType}.');
    return null;
  }

  final PluralResolver resolver;
  if (node.pluralType == PluralType.cardinal) {
    resolver = meta.cardinalResolver ??
        PluralResolvers.cardinal(meta.locale.languageCode);
  } else {
    resolver = meta.ordinalResolver ??
        PluralResolvers.ordinal(meta.locale.languageCode);
  }

  final quantities = node.quantities.cast<Quantity, StringTextNode>();

  return resolver(
    param[node.paramName] as num,
    zero: quantities[Quantity.zero]?.content.applyParamsAndLinks(meta, param),
    one: quantities[Quantity.one]?.content.applyParamsAndLinks(meta, param),
    two: quantities[Quantity.two]?.content.applyParamsAndLinks(meta, param),
    few: quantities[Quantity.few]?.content.applyParamsAndLinks(meta, param),
    many: quantities[Quantity.many]?.content.applyParamsAndLinks(meta, param),
    other:
        quantities[Quantity.other]?.content.applyParamsAndLinks(meta, param),
  );
}