SymfonyComponentTranslationPluralizationRules

Returns the plural rules for a given locale.

Defined (1)

The class is defined in the following location(s).

/vendor/symfony/translation/PluralizationRules.php  
  1. class PluralizationRules 
  2. private static $rules = array(); 
  3.  
  4. /** 
  5. * Returns the plural position to use for the given locale and number. 
  6. * @param int $number The number 
  7. * @param string $locale The locale 
  8. * @return int The plural position 
  9. */ 
  10. public static function get($number, $locale) 
  11. if ('pt_BR' === $locale) { 
  12. // temporary set a locale for brazilian 
  13. $locale = 'xbr'; 
  14.  
  15. if (strlen($locale) > 3) { 
  16. $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); 
  17.  
  18. if (isset(self::$rules[$locale])) { 
  19. $return = call_user_func(self::$rules[$locale], $number); 
  20.  
  21. if (!is_int($return) || $return < 0) { 
  22. return 0; 
  23.  
  24. return $return; 
  25.  
  26. /** 
  27. * The plural rules are derived from code of the Zend Framework (2010-09-25),  
  28. * which is subject to the new BSD license (http://framework.zend.com/license/new-bsd). 
  29. * Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 
  30. */ 
  31. switch ($locale) { 
  32. case 'az': 
  33. case 'bo': 
  34. case 'dz': 
  35. case 'id': 
  36. case 'ja': 
  37. case 'jv': 
  38. case 'ka': 
  39. case 'km': 
  40. case 'kn': 
  41. case 'ko': 
  42. case 'ms': 
  43. case 'th': 
  44. case 'tr': 
  45. case 'vi': 
  46. case 'zh': 
  47. return 0; 
  48. break; 
  49.  
  50. case 'af': 
  51. case 'bn': 
  52. case 'bg': 
  53. case 'ca': 
  54. case 'da': 
  55. case 'de': 
  56. case 'el': 
  57. case 'en': 
  58. case 'eo': 
  59. case 'es': 
  60. case 'et': 
  61. case 'eu': 
  62. case 'fa': 
  63. case 'fi': 
  64. case 'fo': 
  65. case 'fur': 
  66. case 'fy': 
  67. case 'gl': 
  68. case 'gu': 
  69. case 'ha': 
  70. case 'he': 
  71. case 'hu': 
  72. case 'is': 
  73. case 'it': 
  74. case 'ku': 
  75. case 'lb': 
  76. case 'ml': 
  77. case 'mn': 
  78. case 'mr': 
  79. case 'nah': 
  80. case 'nb': 
  81. case 'ne': 
  82. case 'nl': 
  83. case 'nn': 
  84. case 'no': 
  85. case 'om': 
  86. case 'or': 
  87. case 'pa': 
  88. case 'pap': 
  89. case 'ps': 
  90. case 'pt': 
  91. case 'so': 
  92. case 'sq': 
  93. case 'sv': 
  94. case 'sw': 
  95. case 'ta': 
  96. case 'te': 
  97. case 'tk': 
  98. case 'ur': 
  99. case 'zu': 
  100. return ($number == 1) ? 0 : 1; 
  101.  
  102. case 'am': 
  103. case 'bh': 
  104. case 'fil': 
  105. case 'fr': 
  106. case 'gun': 
  107. case 'hi': 
  108. case 'hy': 
  109. case 'ln': 
  110. case 'mg': 
  111. case 'nso': 
  112. case 'xbr': 
  113. case 'ti': 
  114. case 'wa': 
  115. return (($number == 0) || ($number == 1)) ? 0 : 1; 
  116.  
  117. case 'be': 
  118. case 'bs': 
  119. case 'hr': 
  120. case 'ru': 
  121. case 'sr': 
  122. case 'uk': 
  123. return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); 
  124.  
  125. case 'cs': 
  126. case 'sk': 
  127. return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2); 
  128.  
  129. case 'ga': 
  130. return ($number == 1) ? 0 : (($number == 2) ? 1 : 2); 
  131.  
  132. case 'lt': 
  133. return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); 
  134.  
  135. case 'sl': 
  136. return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3)); 
  137.  
  138. case 'mk': 
  139. return ($number % 10 == 1) ? 0 : 1; 
  140.  
  141. case 'mt': 
  142. return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)); 
  143.  
  144. case 'lv': 
  145. return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2); 
  146.  
  147. case 'pl': 
  148. return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2); 
  149.  
  150. case 'cy': 
  151. return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3)); 
  152.  
  153. case 'ro': 
  154. return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2); 
  155.  
  156. case 'ar': 
  157. return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))); 
  158.  
  159. default: 
  160. return 0; 
  161.  
  162. /** 
  163. * Overrides the default plural rule for a given locale. 
  164. * @param callable $rule A PHP callable 
  165. * @param string $locale The locale 
  166. */ 
  167. public static function set(callable $rule, $locale) 
  168. if ('pt_BR' === $locale) { 
  169. // temporary set a locale for brazilian 
  170. $locale = 'xbr'; 
  171.  
  172. if (strlen($locale) > 3) { 
  173. $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); 
  174.  
  175. self::$rules[$locale] = $rule;