CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.3
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 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

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BakeTask
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeRoute
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbConfigTask
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • FileLog
  • FixtureTask
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • MootoolsEngineHelper
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginShortRoute
  • PluginTask
  • ProjectTask
  • PrototypeEngineHelper
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • Set
  • Shell
  • String
  • TemplateTask
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  1: <?php
  2: /**
  3:  * Internationalization
  4:  *
  5:  * PHP versions 4 and 5
  6:  *
  7:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9:  *
 10:  * Licensed under The MIT License
 11:  * Redistributions of files must retain the above copyright notice.
 12:  *
 13:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 14:  * @link          http://cakephp.org CakePHP(tm) Project
 15:  * @package       cake
 16:  * @subpackage    cake.cake.libs
 17:  * @since         CakePHP(tm) v 1.2.0.4116
 18:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 19:  */
 20: 
 21: /**
 22:  * Included libraries.
 23:  */
 24: App::import('Core', array('l10n', 'Multibyte'));
 25: 
 26: /**
 27:  * I18n handles translation of Text and time format strings.
 28:  *
 29:  * @package       cake
 30:  * @subpackage    cake.cake.libs
 31:  */
 32: class I18n extends Object {
 33: 
 34: /**
 35:  * Instance of the I10n class for localization
 36:  *
 37:  * @var I10n
 38:  * @access public
 39:  */
 40:     var $l10n = null;
 41: 
 42: /**
 43:  * Current domain of translation
 44:  *
 45:  * @var string
 46:  * @access public
 47:  */
 48:     var $domain = null;
 49: 
 50: /**
 51:  * Current category of translation
 52:  *
 53:  * @var string
 54:  * @access public
 55:  */
 56:     var $category = 'LC_MESSAGES';
 57: 
 58: /**
 59:  * Current language used for translations
 60:  *
 61:  * @var string
 62:  * @access private
 63:  */
 64:     var $__lang = null;
 65: 
 66: /**
 67:  * Translation strings for a specific domain read from the .mo or .po files
 68:  *
 69:  * @var array
 70:  * @access private
 71:  */
 72:     var $__domains = array();
 73: 
 74: /**
 75:  * Set to true when I18N::__bindTextDomain() is called for the first time.
 76:  * If a translation file is found it is set to false again
 77:  *
 78:  * @var boolean
 79:  * @access private
 80:  */
 81:     var $__noLocale = false;
 82: 
 83: /**
 84:  * Set to true when I18N::__bindTextDomain() is called for the first time.
 85:  * If a translation file is found it is set to false again
 86:  *
 87:  * @var array
 88:  * @access private
 89:  */
 90:     var $__categories = array(
 91:          'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES'
 92:     );
 93: 
 94: /**
 95:  * Return a static instance of the I18n class
 96:  *
 97:  * @return object I18n
 98:  * @access public
 99:  */
100:     function &getInstance() {
101:         static $instance = array();
102:         if (!$instance) {
103:             $instance[0] =& new I18n();
104:             $instance[0]->l10n =& new L10n();
105:         }
106:         return $instance[0];
107:     }
108: 
109: /**
110:  * Used by the translation functions in basics.php
111:  * Can also be used like I18n::translate(); but only if the App::import('I18n'); has been used to load the class.
112:  *
113:  * @param string $singular String to translate
114:  * @param string $plural Plural string (if any)
115:  * @param string $domain Domain The domain of the translation.  Domains are often used by plugin translations
116:  * @param string $category Category The integer value of the category to use.
117:  * @param integer $count Count Count is used with $plural to choose the correct plural form.
118:  * @return string translated string.
119:  * @access public
120:  */
121:     function translate($singular, $plural = null, $domain = null, $category = 6, $count = null) {
122:         $_this =& I18n::getInstance();
123:         
124:         if (strpos($singular, "\r\n") !== false) {
125:             $singular = str_replace("\r\n", "\n", $singular);
126:         }
127:         if ($plural !== null && strpos($plural, "\r\n") !== false) {
128:             $plural = str_replace("\r\n", "\n", $plural);
129:         }
130: 
131:         if (is_numeric($category)) {
132:             $_this->category = $_this->__categories[$category];
133:         }
134:         $language = Configure::read('Config.language');
135: 
136:         if (!empty($_SESSION['Config']['language'])) {
137:             $language = $_SESSION['Config']['language'];
138:         }
139: 
140:         if (($_this->__lang && $_this->__lang !== $language) || !$_this->__lang) {
141:             $lang = $_this->l10n->get($language);
142:             $_this->__lang = $lang;
143:         }
144: 
145:         if (is_null($domain)) {
146:             $domain = 'default';
147:         }
148: 
149:         $_this->domain = $domain . '_' . $_this->l10n->lang;
150: 
151:         if (!isset($_this->__domains[$domain][$_this->__lang])) {
152:             $_this->__domains[$domain][$_this->__lang] = Cache::read($_this->domain, '_cake_core_');
153:         }
154: 
155:         if (!isset($_this->__domains[$domain][$_this->__lang][$_this->category])) {
156:             $_this->__bindTextDomain($domain);
157:             Cache::write($_this->domain, $_this->__domains[$domain][$_this->__lang], '_cake_core_');
158:         }
159: 
160:         if ($_this->category == 'LC_TIME') {
161:             return $_this->__translateTime($singular,$domain);
162:         }
163: 
164:         if (!isset($count)) {
165:             $plurals = 0;
166:         } elseif (!empty($_this->__domains[$domain][$_this->__lang][$_this->category]["%plural-c"]) && $_this->__noLocale === false) {
167:             $header = $_this->__domains[$domain][$_this->__lang][$_this->category]["%plural-c"];
168:             $plurals = $_this->__pluralGuess($header, $count);
169:         } else {
170:             if ($count != 1) {
171:                 $plurals = 1;
172:             } else {
173:                 $plurals = 0;
174:             }
175:         }
176: 
177:         if (!empty($_this->__domains[$domain][$_this->__lang][$_this->category][$singular])) {
178:             if (($trans = $_this->__domains[$domain][$_this->__lang][$_this->category][$singular]) || ($plurals) && ($trans = $_this->__domains[$domain][$_this->__lang][$_this->category][$plural])) {
179:                 if (is_array($trans)) {
180:                     if (isset($trans[$plurals])) {
181:                         $trans = $trans[$plurals];
182:                     }
183:                 }
184:                 if (strlen($trans)) {
185:                     return $trans;
186:                 }
187:             }
188:         }
189: 
190:         if (!empty($plurals)) {
191:             return $plural;
192:         }
193:         return $singular;
194:     }
195: 
196: /**
197:  * Clears the domains internal data array.  Useful for testing i18n.
198:  *
199:  * @return void
200:  */
201:     function clear() {
202:         $self =& I18n::getInstance();
203:         $self->__domains = array();
204:     }
205: 
206: /**
207:  * Attempts to find the plural form of a string.
208:  *
209:  * @param string $header Type
210:  * @param integrer $n Number
211:  * @return integer plural match
212:  * @access private
213:  */
214:     function __pluralGuess($header, $n) {
215:         if (!is_string($header) || $header === "nplurals=1;plural=0;" || !isset($header[0])) {
216:             return 0;
217:         }
218: 
219:         if ($header === "nplurals=2;plural=n!=1;") {
220:             return $n != 1 ? 1 : 0;
221:         } elseif ($header === "nplurals=2;plural=n>1;") {
222:             return $n > 1 ? 1 : 0;
223:         }
224: 
225:         if (strpos($header, "plurals=3")) {
226:             if (strpos($header, "100!=11")) {
227:                 if (strpos($header, "10<=4")) {
228:                     return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
229:                 } elseif (strpos($header, "100<10")) {
230:                     return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
231:                 }
232:                 return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n != 0 ? 1 : 2);
233:             } elseif (strpos($header, "n==2")) {
234:                 return $n == 1 ? 0 : ($n == 2 ? 1 : 2);
235:             } elseif (strpos($header, "n==0")) {
236:                 return $n == 1 ? 0 : ($n == 0 || ($n % 100 > 0 && $n % 100 < 20) ? 1 : 2);
237:             } elseif (strpos($header, "n>=2")) {
238:                 return $n == 1 ? 0 : ($n >= 2 && $n <= 4 ? 1 : 2);
239:             } elseif (strpos($header, "10>=2")) {
240:                 return $n == 1 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
241:             }
242:             return $n % 10 == 1 ? 0 : ($n % 10 == 2 ? 1 : 2);
243:         } elseif (strpos($header, "plurals=4")) {
244:             if (strpos($header, "100==2")) {
245:                 return $n % 100 == 1 ? 0 : ($n % 100 == 2 ? 1 : ($n % 100 == 3 || $n % 100 == 4 ? 2 : 3));
246:             } elseif (strpos($header, "n>=3")) {
247:                 return $n == 1 ? 0 : ($n == 2 ? 1 : ($n == 0 || ($n >= 3 && $n <= 10) ? 2 : 3));
248:             } elseif (strpos($header, "100>=1")) {
249:                 return $n == 1 ? 0 : ($n == 0 || ($n % 100 >= 1 && $n % 100 <= 10) ? 1 : ($n % 100 >= 11 && $n % 100 <= 20 ? 2 : 3));
250:             }
251:         } elseif (strpos($header, "plurals=5")) {
252:             return $n == 1 ? 0 : ($n == 2 ? 1 : ($n >= 3 && $n <= 6 ? 2 : ($n >= 7 && $n <= 10 ? 3 : 4)));
253:         }
254:     }
255: 
256: /**
257:  * Binds the given domain to a file in the specified directory.
258:  *
259:  * @param string $domain Domain to bind
260:  * @return string Domain binded
261:  * @access private
262:  */
263:     function __bindTextDomain($domain) {
264:         $this->__noLocale = true;
265:         $core = true;
266:         $merge = array();
267:         $searchPaths = App::path('locales');
268:         $plugins = App::objects('plugin');
269: 
270:         if (!empty($plugins)) {
271:             foreach ($plugins as $plugin) {
272:                 $plugin = Inflector::underscore($plugin);
273:                 if ($plugin === $domain) {
274:                     $searchPaths[] = App::pluginPath($plugin) . DS . 'locale' . DS;
275:                     $searchPaths = array_reverse($searchPaths);
276:                     break;
277:                 }
278:             }
279:         }
280: 
281: 
282:         foreach ($searchPaths as $directory) {
283: 
284:             foreach ($this->l10n->languagePath as $lang) {
285:                 $file = $directory . $lang . DS . $this->category . DS . $domain;
286:                 $localeDef = $directory . $lang . DS . $this->category;
287: 
288:                 if ($core) {
289:                     $app = $directory . $lang . DS . $this->category . DS . 'core';
290: 
291:                     if (file_exists($fn = "$app.mo")) {
292:                         $this->__loadMo($fn, $domain);
293:                         $this->__noLocale = false;
294:                         $merge[$domain][$this->__lang][$this->category] = $this->__domains[$domain][$this->__lang][$this->category];
295:                         $core = null;
296:                     } elseif (file_exists($fn = "$app.po") && ($f = fopen($fn, "r"))) {
297:                         $this->__loadPo($f, $domain);
298:                         $this->__noLocale = false;
299:                         $merge[$domain][$this->__lang][$this->category] = $this->__domains[$domain][$this->__lang][$this->category];
300:                         $core = null;
301:                     }
302:                 }
303: 
304:                 if (file_exists($fn = "$file.mo")) {
305:                     $this->__loadMo($fn, $domain);
306:                     $this->__noLocale = false;
307:                     break 2;
308:                 } elseif (file_exists($fn = "$file.po") && ($f = fopen($fn, "r"))) {
309:                     $this->__loadPo($f, $domain);
310:                     $this->__noLocale = false;
311:                     break 2;
312:                 } elseif (is_file($localeDef) && ($f = fopen($localeDef, "r"))) {
313:                     $this->__loadLocaleDefinition($f, $domain);
314:                     $this->__noLocale = false;
315:                     return $domain;
316:                 }
317:             }
318:         }
319: 
320:         if (empty($this->__domains[$domain][$this->__lang][$this->category])) {
321:             $this->__domains[$domain][$this->__lang][$this->category] = array();
322:             return $domain;
323:         }
324:         
325:         if (isset($this->__domains[$domain][$this->__lang][$this->category][""])) {
326:             $head = $this->__domains[$domain][$this->__lang][$this->category][""];
327:             
328:             foreach (explode("\n", $head) as $line) {
329:                 $header = strtok($line,":");
330:                 $line = trim(strtok("\n"));
331:                 $this->__domains[$domain][$this->__lang][$this->category]["%po-header"][strtolower($header)] = $line;
332:             }
333: 
334:             if (isset($this->__domains[$domain][$this->__lang][$this->category]["%po-header"]["plural-forms"])) {
335:                 $switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->__domains[$domain][$this->__lang][$this->category]["%po-header"]["plural-forms"]);
336:                 $this->__domains[$domain][$this->__lang][$this->category]["%plural-c"] = $switch;
337:                 unset($this->__domains[$domain][$this->__lang][$this->category]["%po-header"]);
338:             }
339:             $this->__domains = Set::pushDiff($this->__domains, $merge);
340: 
341:             if (isset($this->__domains[$domain][$this->__lang][$this->category][null])) {
342:                 unset($this->__domains[$domain][$this->__lang][$this->category][null]);
343:             }
344:         }
345:         return $domain;
346:     }
347: 
348: /**
349:  * Loads the binary .mo file for translation and sets the values for this translation in the var I18n::__domains
350:  *
351:  * @param resource $file Binary .mo file to load
352:  * @param string $domain Domain where to load file in
353:  * @access private
354:  */
355:     function __loadMo($file, $domain) {
356:         $data = file_get_contents($file);
357: 
358:         if ($data) {
359:             $header = substr($data, 0, 20);
360:             $header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
361:             extract($header);
362: 
363:             if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) {
364:                 for ($n = 0; $n < $count; $n++) {
365:                     $r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
366:                     $msgid = substr($data, $r["offs"], $r["len"]);
367:                     unset($msgid_plural);
368: 
369:                     if (strpos($msgid, "\000")) {
370:                         list($msgid, $msgid_plural) = explode("\000", $msgid);
371:                     }
372:                     $r = unpack("L1len/L1offs", substr($data, $o_trn + $n * 8, 8));
373:                     $msgstr = substr($data, $r["offs"], $r["len"]);
374: 
375:                     if (strpos($msgstr, "\000")) {
376:                         $msgstr = explode("\000", $msgstr);
377:                     }
378:                     $this->__domains[$domain][$this->__lang][$this->category][$msgid] = $msgstr;
379: 
380:                     if (isset($msgid_plural)) {
381:                         $this->__domains[$domain][$this->__lang][$this->category][$msgid_plural] =& $this->__domains[$domain][$this->__lang][$this->category][$msgid];
382:                     }
383:                 }
384:             }
385:         }
386:     }
387: 
388: /**
389:  * Loads the text .po file for translation and sets the values for this translation in the var I18n::__domains
390:  *
391:  * @param resource $file Text .po file to load
392:  * @param string $domain Domain to load file in
393:  * @return array Binded domain elements
394:  * @access private
395:  */
396:     function __loadPo($file, $domain) {
397:         $type = 0;
398:         $translations = array();
399:         $translationKey = "";
400:         $plural = 0;
401:         $header = "";
402: 
403:         do {
404:             $line = trim(fgets($file));
405:             if ($line == "" || $line[0] == "#") {
406:                 continue;
407:             }
408:             if (preg_match("/msgid[[:space:]]+\"(.+)\"$/i", $line, $regs)) {
409:                 $type = 1;
410:                 $translationKey = stripcslashes($regs[1]);
411:             } elseif (preg_match("/msgid[[:space:]]+\"\"$/i", $line, $regs)) {
412:                 $type = 2;
413:                 $translationKey = "";
414:             } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && ($type == 1 || $type == 2 || $type == 3)) {
415:                 $type = 3;
416:                 $translationKey .= stripcslashes($regs[1]);
417:             } elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
418:                 $translations[$translationKey] = stripcslashes($regs[1]);
419:                 $type = 4;
420:             } elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
421:                 $type = 4;
422:                 $translations[$translationKey] = "";
423:             } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 4 && $translationKey) {
424:                 $translations[$translationKey] .= stripcslashes($regs[1]);
425:             } elseif (preg_match("/msgid_plural[[:space:]]+\".*\"$/i", $line, $regs)) {
426:                 $type = 6;
427:             } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 6 && $translationKey) {
428:                 $type = 6;
429:             } elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
430:                 $plural = $regs[1];
431:                 $translations[$translationKey][$plural] = stripcslashes($regs[2]);
432:                 $type = 7;
433:             } elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
434:                 $plural = $regs[1];
435:                 $translations[$translationKey][$plural] = "";
436:                 $type = 7;
437:             } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 7 && $translationKey) {
438:                 $translations[$translationKey][$plural] .= stripcslashes($regs[1]);
439:             } elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && $type == 2 && !$translationKey) {
440:                 $header .= stripcslashes($regs[1]);
441:                 $type = 5;
442:             } elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && !$translationKey) {
443:                 $header = "";
444:                 $type = 5;
445:             } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 5) {
446:                 $header .= stripcslashes($regs[1]);
447:             } else {
448:                 unset($translations[$translationKey]);
449:                 $type = 0;
450:                 $translationKey = "";
451:                 $plural = 0;
452:             }
453:         } while (!feof($file));
454:         fclose($file);
455:         $merge[""] = $header;
456:         return $this->__domains[$domain][$this->__lang][$this->category] = array_merge($merge ,$translations);
457:     }
458: 
459: /**
460:  * Parses a locale definition file following the POSIX standard
461:  *
462:  * @param resource $file file handler
463:  * @param string $domain Domain where locale definitions will be stored
464:  * @return void
465:  * @access private
466:  */
467:     function __loadLocaleDefinition($file, $domain = null) {
468:         $comment = '#';
469:         $escape = '\\';
470:         $currentToken = false;
471:         $value = '';
472:         while ($line = fgets($file)) {
473:             $line = trim($line);
474:             if (empty($line) || $line[0] === $comment) {
475:                 continue;
476:             }
477:             $parts = preg_split("/[[:space:]]+/",$line);
478:             if ($parts[0] === 'comment_char') {
479:                 $comment = $parts[1];
480:                 continue;
481:             }
482:             if ($parts[0] === 'escape_char') {
483:                 $escape = $parts[1];
484:                 continue;
485:             }
486:             $count = count($parts);
487:             if ($count == 2) {
488:                 $currentToken = $parts[0];
489:                 $value = $parts[1];
490:             } elseif ($count == 1) {
491:                 $value .= $parts[0];
492:             } else {
493:                 continue;
494:             }
495: 
496:             $len = strlen($value) - 1;
497:             if ($value[$len] === $escape) {
498:                 $value = substr($value, 0, $len);
499:                 continue;
500:             }
501: 
502:             $mustEscape = array($escape . ',' , $escape . ';', $escape . '<', $escape . '>', $escape . $escape);
503:             $replacements = array_map('crc32', $mustEscape);
504:             $value = str_replace($mustEscape, $replacements, $value);
505:             $value = explode(';', $value);
506:             $this->__escape = $escape;
507:             foreach ($value as $i => $val) {
508:                 $val = trim($val, '"');
509:                 $val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/', array(&$this, '__parseLiteralValue'), $val);
510:                 $val = str_replace($replacements, $mustEscape, $val);
511:                 $value[$i] = $val;
512:             }
513:             if (count($value) == 1) {
514:                 $this->__domains[$domain][$this->__lang][$this->category][$currentToken] = array_pop($value);
515:             } else {
516:                 $this->__domains[$domain][$this->__lang][$this->category][$currentToken] = $value;
517:             }
518:         }
519:     }
520: 
521: /**
522:  * Auxiliary function to parse a symbol from a locale definition file
523:  *
524:  * @param string $string Symbol to be parsed
525:  * @return string parsed symbol
526:  * @access private
527:  */
528:     function __parseLiteralValue($string) {
529:         $string = $string[1];
530:         if (substr($string, 0, 2) === $this->__escape . 'x') {
531:             $delimiter = $this->__escape . 'x';
532:             return join('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string)))));
533:         }
534:         if (substr($string, 0, 2) === $this->__escape . 'd') {
535:             $delimiter = $this->__escape . 'd';
536:             return join('', array_map('chr', array_filter(explode($delimiter, $string))));
537:         }
538:         if ($string[0] === $this->__escape && isset($string[1]) && is_numeric($string[1])) {
539:             $delimiter = $this->__escape;
540:             return join('', array_map('chr', array_filter(explode($delimiter, $string))));
541:         }
542:         if (substr($string, 0, 3) === 'U00') {
543:             $delimiter = 'U00';
544:             return join('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
545:         }
546:         if (preg_match('/U([0-9a-fA-F]{4})/', $string, $match)) {
547:             return Multibyte::ascii(array(hexdec($match[1])));
548:         }
549:         return $string;
550:     }
551: 
552: /**
553:  * Returns a Time format definition from corresponding domain
554:  *
555:  * @param string $format Format to be translated
556:  * @param string $domain Domain where format is stored
557:  * @return mixed translated format string if only value or array of translated strings for corresponding format.
558:  * @access private
559:  */
560:     function __translateTime($format, $domain) {
561:         if (!empty($this->__domains[$domain][$this->__lang]['LC_TIME'][$format])) {
562:             if (($trans = $this->__domains[$domain][$this->__lang][$this->category][$format])) {
563:                 return $trans;
564:             }
565:         }
566:         return $format;
567:     }
568: }
569: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs