ngettext method

String ngettext(
  1. String msgid,
  2. String msgidPlural,
  3. int count, {
  4. String? domain,
  5. String msgctxt = '',
})

Translates a plural string using the default textdomain

    gt.ngettext('One thing', 'Many things', numberOfThings)

@param msgid String to be translated when count is not plural @param msgidPlural String to be translated when count is plural @param count Number count for the plural @returns Translation or the original string if no translation was found

Implementation

String ngettext(
  String msgid,
  String msgidPlural,
  int count, {
  String? domain,
  String msgctxt = '',
}) {
  final translation = _getTranslation(domain ?? this.domain, msgctxt, msgid);

  final index = _pluralsFunc(count);

  if (translation == null || translation.msgstr.length <= index || translation.msgstr[index].isEmpty) {
    if (_locale != 'en') {
      _warn('No translation was found for '
          'msgid "$msgid" in msgctxt "$msgctxt" and domain "$domain"');
    }
    return (count > 1) ? msgidPlural : msgid;
  }

  return translation.msgstr[index];
}