localizePlural function

String localizePlural(
  1. Object? modifier,
  2. Object? key,
  3. Translations<dynamic, Map<StringLocale, StringTranslated>, Map<dynamic, StringTranslated>, dynamic> translations,
  4. {String? locale}
)

Returns the translated version for the plural modifier. After getting the version, substring %d will be replaced with the modifier.

Note: This will try to get the most specific plural modifier. For example, .two is more specific than .many.

If no applicable modifier can be found, it will default to the unversioned string. For example, this: "a".zero("b").four("c:") will default to "a" for 1, 2, 3, or more than 5 elements.

The modifier should usually be an integer. But in case it's not, it will be converted into an integer. The rules are:

  1. If the modifier is an int, its absolute value will be used. Note: absolute value means a negative value will become positive.

  2. If the modifier is a double, its absolute value will be used, like so:

  • 1.0 will be 1.
  • Values below 1.0 will become 0.
  • Values larger than 1.0 will be rounded up.
  1. A String will be converted to int or, if that fails, to a double. Conversion is done like so:
  • First, it will discard other chars than numbers, dot and the minus sign, by converting them to spaces.
  • Then it will convert to int using int.tryParse.
  • Then it will convert to double using double.tryParse.
  • If all fails, it will be zero.
  1. Other objects will be converted to a string (using the toString method), and then the above rules will apply.

Implementation

String localizePlural(
  Object? modifier,
  Object? key,
  Translations translations, {
  String? locale,
}) =>
    core.localizePlural(modifier, key, translations, locale: locale ?? I18n.localeStr);