CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • ChainMessagesLoader
  • Date
  • FrozenDate
  • FrozenTime
  • I18n
  • MessagesFileLoader
  • Number
  • PluralRules
  • Time
  • TranslatorRegistry

Traits

  • DateFormatTrait
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\I18n;
 16: 
 17: /**
 18:  * Utility class used to determine the plural number to be used for a variable
 19:  * base on the locale
 20:  */
 21: class PluralRules
 22: {
 23:     /**
 24:      * A map of locale => plurals group used to determine
 25:      * which plural rules apply to the language
 26:      *
 27:      * @var array
 28:      */
 29:     protected static $_rulesMap = [
 30:         'af' => 1,
 31:         'am' => 2,
 32:         'ar' => 13,
 33:         'az' => 1,
 34:         'be' => 3,
 35:         'bg' => 1,
 36:         'bh' => 2,
 37:         'bn' => 1,
 38:         'bo' => 0,
 39:         'bs' => 3,
 40:         'ca' => 1,
 41:         'cs' => 4,
 42:         'cy' => 14,
 43:         'da' => 1,
 44:         'de' => 1,
 45:         'dz' => 0,
 46:         'el' => 1,
 47:         'en' => 1,
 48:         'eo' => 1,
 49:         'es' => 1,
 50:         'et' => 1,
 51:         'eu' => 1,
 52:         'fa' => 1,
 53:         'fi' => 1,
 54:         'fil' => 2,
 55:         'fo' => 1,
 56:         'fr' => 2,
 57:         'fur' => 1,
 58:         'fy' => 1,
 59:         'ga' => 5,
 60:         'gl' => 1,
 61:         'gu' => 1,
 62:         'gun' => 2,
 63:         'ha' => 1,
 64:         'he' => 1,
 65:         'hi' => 2,
 66:         'hr' => 3,
 67:         'hu' => 1,
 68:         'id' => 0,
 69:         'is' => 15,
 70:         'it' => 1,
 71:         'ja' => 0,
 72:         'jv' => 0,
 73:         'ka' => 0,
 74:         'km' => 0,
 75:         'kn' => 0,
 76:         'ko' => 0,
 77:         'ku' => 1,
 78:         'lb' => 1,
 79:         'ln' => 2,
 80:         'lt' => 6,
 81:         'lv' => 10,
 82:         'mg' => 2,
 83:         'mk' => 8,
 84:         'ml' => 1,
 85:         'mn' => 1,
 86:         'mr' => 1,
 87:         'ms' => 0,
 88:         'mt' => 9,
 89:         'nah' => 1,
 90:         'nb' => 1,
 91:         'ne' => 1,
 92:         'nl' => 1,
 93:         'nn' => 1,
 94:         'no' => 1,
 95:         'nso' => 2,
 96:         'om' => 1,
 97:         'or' => 1,
 98:         'pa' => 1,
 99:         'pap' => 1,
100:         'pl' => 11,
101:         'ps' => 1,
102:         'pt_pt' => 2,
103:         'pt' => 1,
104:         'ro' => 12,
105:         'ru' => 3,
106:         'sk' => 4,
107:         'sl' => 7,
108:         'so' => 1,
109:         'sq' => 1,
110:         'sr' => 3,
111:         'sv' => 1,
112:         'sw' => 1,
113:         'ta' => 1,
114:         'te' => 1,
115:         'th' => 0,
116:         'ti' => 2,
117:         'tk' => 1,
118:         'tr' => 1,
119:         'uk' => 3,
120:         'ur' => 1,
121:         'vi' => 0,
122:         'wa' => 2,
123:         'zh' => 0,
124:         'zu' => 1,
125:     ];
126: 
127:     /**
128:      * Returns the plural form number for the passed locale corresponding
129:      * to the countable provided in $n.
130:      *
131:      * @param string $locale The locale to get the rule calculated for.
132:      * @param int|float $n The number to apply the rules to.
133:      * @return int The plural rule number that should be used.
134:      * @link http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
135:      * @link https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules
136:      */
137:     public static function calculate($locale, $n)
138:     {
139:         $locale = strtolower($locale);
140: 
141:         if (!isset(static::$_rulesMap[$locale])) {
142:             $locale = explode('_', $locale)[0];
143:         }
144: 
145:         if (!isset(static::$_rulesMap[$locale])) {
146:             return 0;
147:         }
148: 
149:         switch (static::$_rulesMap[$locale]) {
150:             case 0:
151:                 return 0;
152:             case 1:
153:                 return $n == 1 ? 0 : 1;
154:             case 2:
155:                 return $n > 1 ? 1 : 0;
156:             case 3:
157:                 return $n % 10 == 1 && $n % 100 != 11 ? 0 :
158:                     (($n % 10 >= 2 && $n % 10 <= 4) && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
159:             case 4:
160:                 return $n == 1 ? 0 :
161:                     ($n >= 2 && $n <= 4 ? 1 : 2);
162:             case 5:
163:                 return $n == 1 ? 0 :
164:                     ($n == 2 ? 1 : ($n < 7 ? 2 : ($n < 11 ? 3 : 4)));
165:             case 6:
166:                 return $n % 10 == 1 && $n % 100 != 11 ? 0 :
167:                     ($n % 10 >= 2 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
168:             case 7:
169:                 return $n % 100 == 1 ? 1 :
170:                     ($n % 100 == 2 ? 2 : ($n % 100 == 3 || $n % 100 == 4 ? 3 : 0));
171:             case 8:
172:                 return $n % 10 == 1 ? 0 : ($n % 10 == 2 ? 1 : 2);
173:             case 9:
174:                 return $n == 1 ? 0 :
175:                     ($n == 0 || ($n % 100 > 0 && $n % 100 <= 10) ? 1 :
176:                     ($n % 100 > 10 && $n % 100 < 20 ? 2 : 3));
177:             case 10:
178:                 return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n != 0 ? 1 : 2);
179:             case 11:
180:                 return $n == 1 ? 0 :
181:                     ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
182:             case 12:
183:                 return $n == 1 ? 0 :
184:                     ($n == 0 || $n % 100 > 0 && $n % 100 < 20 ? 1 : 2);
185:             case 13:
186:                 return $n == 0 ? 0 :
187:                     ($n == 1 ? 1 :
188:                     ($n == 2 ? 2 :
189:                     ($n % 100 >= 3 && $n % 100 <= 10 ? 3 :
190:                     ($n % 100 >= 11 ? 4 : 5))));
191:             case 14:
192:                 return $n == 1 ? 0 :
193:                     ($n == 2 ? 1 :
194:                     ($n != 8 && $n != 11 ? 2 : 3));
195:             case 15:
196:                 return ($n % 10 != 1 || $n % 100 == 11) ? 1 : 0;
197:         }
198:     }
199: }
200: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs