pluralize function

String pluralize(
  1. String word,
  2. int count
)

Simple English pluralization.

Implementation

String pluralize(String word, int count) {
  if (count == 1) return word;
  if (word.endsWith('s') ||
      word.endsWith('x') ||
      word.endsWith('z') ||
      word.endsWith('ch') ||
      word.endsWith('sh')) {
    return '${word}es';
  }
  if (word.endsWith('y') &&
      word.length > 1 &&
      !'aeiou'.contains(word[word.length - 2])) {
    return '${word.substring(0, word.length - 1)}ies';
  }
  if (word.endsWith('f')) {
    return '${word.substring(0, word.length - 1)}ves';
  }
  if (word.endsWith('fe')) {
    return '${word.substring(0, word.length - 2)}ves';
  }
  return '${word}s';
}