Merge pull request #18930 from MegaphoneJon/financial-156
[civicrm-core.git] / CRM / Utils / String.php
index e0cac9a763ba167433a6c45677831032d4f5e4cf..7c0897436508acb9f83c494f343981706c3b235c 100644 (file)
@@ -939,16 +939,15 @@ class CRM_Utils_String {
    * @return string
    */
   public static function pluralize($str) {
-    switch (substr($str, -1)) {
-      case 's':
-        return $str . 'es';
-
-      case 'y':
-        return substr($str, 0, -1) . 'ies';
-
-      default:
-        return $str . 's';
+    $lastLetter = substr($str, -1);
+    $lastTwo = substr($str, -2);
+    if ($lastLetter == 's' || $lastLetter == 'x' || $lastTwo == 'ch') {
+      return $str . 'es';
+    }
+    if ($lastLetter == 'y' && !in_array($lastTwo, ['ay', 'ey', 'iy', 'oy', 'uy'])) {
+      return substr($str, 0, -1) . 'ies';
     }
+    return $str . 's';
   }
 
   /**