Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,27 +2,24 @@
/**
* Internationalization
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.I18n
* @since CakePHP(tm) v 1.2.0.4116
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Included libraries.
*/
App::uses('CakePlugin', 'Core');
App::uses('L10n', 'I18n');
App::uses('Multibyte', 'I18n');
App::uses('CakeSession', 'Model/Datasource');
/**
* I18n handles translation of Text and time format strings.
@ -77,7 +74,7 @@ class I18n {
* Set to true when I18N::_bindTextDomain() is called for the first time.
* If a translation file is found it is set to false again
*
* @var boolean
* @var bool
*/
protected $_noLocale = false;
@ -90,12 +87,77 @@ class I18n {
'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES'
);
/**
* Constants for the translation categories.
*
* The constants may be used in translation fetching
* instead of hardcoded integers.
* Example:
* ```
* I18n::translate('CakePHP is awesome.', null, null, I18n::LC_MESSAGES)
* ```
*
* To keep the code more readable, I18n constants are preferred over
* hardcoded integers.
*/
/**
* Constant for LC_ALL.
*
* @var int
*/
const LC_ALL = 0;
/**
* Constant for LC_COLLATE.
*
* @var int
*/
const LC_COLLATE = 1;
/**
* Constant for LC_CTYPE.
*
* @var int
*/
const LC_CTYPE = 2;
/**
* Constant for LC_MONETARY.
*
* @var int
*/
const LC_MONETARY = 3;
/**
* Constant for LC_NUMERIC.
*
* @var int
*/
const LC_NUMERIC = 4;
/**
* Constant for LC_TIME.
*
* @var int
*/
const LC_TIME = 5;
/**
* Constant for LC_MESSAGES.
*
* @var int
*/
const LC_MESSAGES = 6;
/**
* Escape string
*
* @var string
*/
protected $_escape = null;
/**
* Constructor, use I18n::getInstance() to get the i18n translation object.
*
* @return void
*/
public function __construct() {
$this->l10n = new L10n();
@ -106,7 +168,7 @@ class I18n {
*
* @return I18n
*/
public static function &getInstance() {
public static function getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] = new I18n();
@ -120,14 +182,19 @@ class I18n {
*
* @param string $singular String to translate
* @param string $plural Plural string (if any)
* @param string $domain Domain The domain of the translation. Domains are often used by plugin translations
* @param string $domain Domain The domain of the translation. Domains are often used by plugin translations.
* If null, the default domain will be used.
* @param string $category Category The integer value of the category to use.
* @param integer $count Count Count is used with $plural to choose the correct plural form.
* @param int $count Count Count is used with $plural to choose the correct plural form.
* @param string $language Language to translate string to.
* If null it checks for language in session followed by Config.language configuration variable.
* If null it checks for language in session followed by Config.language configuration variable.
* @param string $context Context The context of the translation, e.g a verb or a noun.
* @return string translated string.
* @throws CakeException When '' is provided as a domain.
*/
public static function translate($singular, $plural = null, $domain = null, $category = 6, $count = null, $language = null) {
public static function translate($singular, $plural = null, $domain = null, $category = self::LC_MESSAGES,
$count = null, $language = null, $context = null
) {
$_this = I18n::getInstance();
if (strpos($singular, "\r\n") !== false) {
@ -142,9 +209,10 @@ class I18n {
}
if (empty($language)) {
if (!empty($_SESSION['Config']['language'])) {
$language = $_SESSION['Config']['language'];
} else {
if (CakeSession::started()) {
$language = CakeSession::read('Config.language');
}
if (empty($language)) {
$language = Configure::read('Config.language');
}
}
@ -154,8 +222,11 @@ class I18n {
$_this->_lang = $lang;
}
if (is_null($domain)) {
$domain = self::$defaultDomain;
if ($domain === null) {
$domain = static::$defaultDomain;
}
if ($domain === '') {
throw new CakeException(__d('cake_dev', 'You cannot use "" as a domain.'));
}
$_this->domain = $domain . '_' . $_this->l10n->lang;
@ -169,7 +240,7 @@ class I18n {
Cache::write($_this->domain, $_this->_domains[$domain][$_this->_lang], '_cake_core_');
}
if ($_this->category == 'LC_TIME') {
if ($_this->category === 'LC_TIME') {
return $_this->_translateTime($singular, $domain);
}
@ -186,8 +257,10 @@ class I18n {
}
}
if (!empty($_this->_domains[$domain][$_this->_lang][$_this->category][$singular])) {
if (($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$singular]) || ($plurals) && ($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$plural])) {
if (!empty($_this->_domains[$domain][$_this->_lang][$_this->category][$singular][$context])) {
if (($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$singular][$context]) ||
($plurals) && ($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$plural][$context])
) {
if (is_array($trans)) {
if (isset($trans[$plurals])) {
$trans = $trans[$plurals];
@ -218,7 +291,7 @@ class I18n {
}
/**
* Clears the domains internal data array. Useful for testing i18n.
* Clears the domains internal data array. Useful for testing i18n.
*
* @return void
*/
@ -241,8 +314,10 @@ class I18n {
* Attempts to find the plural form of a string.
*
* @param string $header Type
* @param integer $n Number
* @return integer plural match
* @param int $n Number
* @return int plural match
* @link http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
* @link https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules
*/
protected function _pluralGuess($header, $n) {
if (!is_string($header) || $header === "nplurals=1;plural=0;" || !isset($header[0])) {
@ -283,7 +358,15 @@ class I18n {
}
} elseif (strpos($header, "plurals=5")) {
return $n == 1 ? 0 : ($n == 2 ? 1 : ($n >= 3 && $n <= 6 ? 2 : ($n >= 7 && $n <= 10 ? 3 : 4)));
} elseif (strpos($header, "plurals=6")) {
return $n == 0 ? 0 :
($n == 1 ? 1 :
($n == 2 ? 2 :
($n % 100 >= 3 && $n % 100 <= 10 ? 3 :
($n % 100 >= 11 ? 4 : 5))));
}
return 0;
}
/**
@ -304,7 +387,9 @@ class I18n {
$pluginDomain = Inflector::underscore($plugin);
if ($pluginDomain === $domain) {
$searchPaths[] = CakePlugin::path($plugin) . 'Locale' . DS;
$searchPaths = array_reverse($searchPaths);
if (!Configure::read('I18n.preferApp')) {
$searchPaths = array_reverse($searchPaths);
}
break;
}
}
@ -314,9 +399,9 @@ class I18n {
foreach ($this->l10n->languagePath as $lang) {
$localeDef = $directory . $lang . DS . $this->category;
if (is_file($localeDef)) {
$definitions = self::loadLocaleDefinition($localeDef);
$definitions = static::loadLocaleDefinition($localeDef);
if ($definitions !== false) {
$this->_domains[$domain][$this->_lang][$this->category] = self::loadLocaleDefinition($localeDef);
$this->_domains[$domain][$this->_lang][$this->category] = $definitions;
$this->_noLocale = false;
return $domain;
}
@ -327,10 +412,10 @@ class I18n {
$translations = false;
if (is_file($app . '.mo')) {
$translations = self::loadMo($app . '.mo');
$translations = static::loadMo($app . '.mo');
}
if ($translations === false && is_file($app . '.po')) {
$translations = self::loadPo($app . '.po');
$translations = static::loadPo($app . '.po');
}
if ($translations !== false) {
@ -345,10 +430,10 @@ class I18n {
$translations = false;
if (is_file($file . '.mo')) {
$translations = self::loadMo($file . '.mo');
$translations = static::loadMo($file . '.mo');
}
if ($translations === false && is_file($file . '.po')) {
$translations = self::loadPo($file . '.po');
$translations = static::loadPo($file . '.po');
}
if ($translations !== false) {
@ -368,7 +453,7 @@ class I18n {
$head = $this->_domains[$domain][$this->_lang][$this->category][""];
foreach (explode("\n", $head) as $line) {
$header = strtok($line,":");
$header = strtok($line, ':');
$line = trim(strtok("\n"));
$this->_domains[$domain][$this->_lang][$this->category]["%po-header"][strtolower($header)] = $line;
}
@ -393,6 +478,7 @@ class I18n {
*
* @param string $filename Binary .mo file to load
* @return mixed Array of translations on success or false on failure
* @link https://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
*/
public static function loadMo($filename) {
$translations = false;
@ -402,15 +488,19 @@ class I18n {
if ($data = file_get_contents($filename)) {
$translations = array();
$header = substr($data, 0, 20);
$header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
$header = unpack('L1magic/L1version/L1count/L1o_msg/L1o_trn', $header);
extract($header);
if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) {
if ((dechex($magic) === '950412de' || dechex($magic) === 'ffffffff950412de') && !$version) {
for ($n = 0; $n < $count; $n++) {
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]);
unset($msgid_plural);
$context = null;
if (strpos($msgid, "\x04") !== false) {
list($context, $msgid) = explode("\x04", $msgid);
}
if (strpos($msgid, "\000")) {
list($msgid, $msgid_plural) = explode("\000", $msgid);
}
@ -420,7 +510,12 @@ class I18n {
if (strpos($msgstr, "\000")) {
$msgstr = explode("\000", $msgstr);
}
$translations[$msgid] = $msgstr;
if ($msgid != '') {
$translations[$msgid][$context] = $msgstr;
} else {
$translations[$msgid] = $msgstr;
}
if (isset($msgid_plural)) {
$translations[$msgid_plural] =& $translations[$msgid];
@ -440,19 +535,22 @@ class I18n {
* @return mixed Array of translations on success or false on failure
*/
public static function loadPo($filename) {
if (!$file = fopen($filename, "r")) {
if (!$file = fopen($filename, 'r')) {
return false;
}
$type = 0;
$translations = array();
$translationKey = "";
$translationKey = '';
$translationContext = null;
$plural = 0;
$header = "";
$header = '';
do {
$line = trim(fgets($file));
if ($line == "" || $line[0] == "#") {
if ($line === '' || $line[0] === '#') {
$translationContext = null;
continue;
}
if (preg_match("/msgid[[:space:]]+\"(.+)\"$/i", $line, $regs)) {
@ -460,50 +558,53 @@ class I18n {
$translationKey = stripcslashes($regs[1]);
} elseif (preg_match("/msgid[[:space:]]+\"\"$/i", $line, $regs)) {
$type = 2;
$translationKey = "";
$translationKey = '';
} elseif (preg_match("/msgctxt[[:space:]]+\"(.+)\"$/i", $line, $regs)) {
$translationContext = $regs[1];
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && ($type == 1 || $type == 2 || $type == 3)) {
$type = 3;
$translationKey .= stripcslashes($regs[1]);
} elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
$translations[$translationKey] = stripcslashes($regs[1]);
$translations[$translationKey][$translationContext] = stripcslashes($regs[1]);
$type = 4;
} elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
$type = 4;
$translations[$translationKey] = "";
$translations[$translationKey][$translationContext] = '';
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 4 && $translationKey) {
$translations[$translationKey] .= stripcslashes($regs[1]);
$translations[$translationKey][$translationContext] .= stripcslashes($regs[1]);
} elseif (preg_match("/msgid_plural[[:space:]]+\".*\"$/i", $line, $regs)) {
$type = 6;
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 6 && $translationKey) {
$type = 6;
} elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
$plural = $regs[1];
$translations[$translationKey][$plural] = stripcslashes($regs[2]);
$translations[$translationKey][$translationContext][$plural] = stripcslashes($regs[2]);
$type = 7;
} elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
$plural = $regs[1];
$translations[$translationKey][$plural] = "";
$translations[$translationKey][$translationContext][$plural] = '';
$type = 7;
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 7 && $translationKey) {
$translations[$translationKey][$plural] .= stripcslashes($regs[1]);
$translations[$translationKey][$translationContext][$plural] .= stripcslashes($regs[1]);
} elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && $type == 2 && !$translationKey) {
$header .= stripcslashes($regs[1]);
$type = 5;
} elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && !$translationKey) {
$header = "";
$header = '';
$type = 5;
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 5) {
$header .= stripcslashes($regs[1]);
} else {
unset($translations[$translationKey]);
unset($translations[$translationKey][$translationContext]);
$type = 0;
$translationKey = "";
$translationKey = '';
$translationContext = null;
$plural = 0;
}
} while (!feof($file));
fclose($file);
$merge[""] = $header;
$merge[''] = $header;
return array_merge($merge, $translations);
}
@ -514,7 +615,7 @@ class I18n {
* @return mixed Array of definitions on success or false on failure
*/
public static function loadLocaleDefinition($filename) {
if (!$file = fopen($filename, "r")) {
if (!$file = fopen($filename, 'r')) {
return false;
}
@ -539,11 +640,11 @@ class I18n {
continue;
}
$count = count($parts);
if ($count == 2) {
if ($count === 2) {
$currentToken = $parts[0];
$value = $parts[1];
} elseif ($count == 1) {
$value .= $parts[0];
} elseif ($count === 1) {
$value = is_array($value) ? $parts[0] : $value . $parts[0];
} else {
continue;
}
@ -565,7 +666,7 @@ class I18n {
$val = str_replace($replacements, $mustEscape, $val);
$value[$i] = $val;
}
if (count($value) == 1) {
if (count($value) === 1) {
$definitions[$currentToken] = array_pop($value);
} else {
$definitions[$currentToken] = $value;
@ -575,6 +676,27 @@ class I18n {
return $definitions;
}
/**
* Puts the parameters in raw translated strings
*
* @param string $translated The raw translated string
* @param array $args The arguments to put in the translation
* @return string Translated string with arguments
*/
public static function insertArgs($translated, array $args) {
$len = count($args);
if ($len === 0 || ($len === 1 && $args[0] === null)) {
return $translated;
}
if (is_array($args[0])) {
$args = $args[0];
}
$translated = preg_replace('/(?<!%)%(?![%\'\-+bcdeEfFgGosuxX\d\.])/', '%%', $translated);
return vsprintf($translated, $args);
}
/**
* Auxiliary function to parse a symbol from a locale definition file
*
@ -585,19 +707,19 @@ class I18n {
$string = $string[1];
if (substr($string, 0, 2) === $this->_escape . 'x') {
$delimiter = $this->_escape . 'x';
return join('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string)))));
return implode('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
}
if (substr($string, 0, 2) === $this->_escape . 'd') {
$delimiter = $this->_escape . 'd';
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
return implode('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if ($string[0] === $this->_escape && isset($string[1]) && is_numeric($string[1])) {
$delimiter = $this->_escape;
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
return implode('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if (substr($string, 0, 3) === 'U00') {
$delimiter = 'U00';
return join('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
return implode('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
}
if (preg_match('/U([0-9a-fA-F]{4})/', $string, $match)) {
return Multibyte::ascii(array(hexdec($match[1])));

View file

@ -2,20 +2,20 @@
/**
* Localization
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.I18n
* @since CakePHP(tm) v 1.2.0.4116
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakeRequest', 'Network');
/**
@ -37,7 +37,7 @@ class L10n {
*
* @var array
*/
public $languagePath = array('eng');
public $languagePath = array('en_us', 'eng');
/**
* ISO 639-3 for current locale
@ -54,9 +54,11 @@ class L10n {
public $locale = 'en_us';
/**
* Default ISO 639-3 language.
* Default language.
*
* DEFAULT_LANGUAGE is defined in an application this will be set as a fall back
* If config value 'Config.language' is set in an application this will be set
* as a fall back else if DEFAULT_LANGUAGE it defined it will be used.
* Constant DEFAULT_LANGUAGE has been deprecated in 2.4
*
* @var string
*/
@ -76,67 +78,69 @@ class L10n {
*/
public $direction = 'ltr';
/**
* Set to true if a locale is found
*
* @var string
*/
public $found = false;
/**
* Maps ISO 639-3 to I10n::_l10nCatalog
* The terminological codes (first one per language) should be used if possible.
* They are the ones building the path in `/APP/Locale/[code]/`
* The bibliographic codes are aliases.
*
* @var array
*/
protected $_l10nMap = array(
/* Afrikaans */ 'afr' => 'af',
/* Albanian */ 'alb' => 'sq',
/* Albanian */ 'sqi' => 'sq',
/* Albanian - bibliographic */ 'alb' => 'sq',
/* Arabic */ 'ara' => 'ar',
/* Armenian - Armenia */ 'hye' => 'hy',
/* Armenian/Armenia */ 'hye' => 'hy',
/* Basque */ 'eus' => 'eu',
/* Basque */ 'baq' => 'eu',
/* Tibetan */ 'bod' => 'bo',
/* Tibetan - bibliographic */ 'tib' => 'bo',
/* Bosnian */ 'bos' => 'bs',
/* Bulgarian */ 'bul' => 'bg',
/* Byelorussian */ 'bel' => 'be',
/* Catalan */ 'cat' => 'ca',
/* Chinese */ 'chi' => 'zh',
/* Chinese */ 'zho' => 'zh',
/* Chinese - bibliographic */ 'chi' => 'zh',
/* Croatian */ 'hrv' => 'hr',
/* Czech */ 'cze' => 'cs',
/* Czech */ 'ces' => 'cs',
/* Czech - bibliographic */ 'cze' => 'cs',
/* Danish */ 'dan' => 'da',
/* Dutch (Standard) */ 'dut' => 'nl',
/* Dutch (Standard) */ 'nld' => 'nl',
/* Dutch (Standard) - bibliographic */ 'dut' => 'nl',
/* English */ 'eng' => 'en',
/* Estonian */ 'est' => 'et',
/* Faeroese */ 'fao' => 'fo',
/* Farsi */ 'fas' => 'fa',
/* Farsi */ 'per' => 'fa',
/* Farsi/Persian */ 'fas' => 'fa',
/* Farsi/Persian - bibliographic */ 'per' => 'fa',
/* Finnish */ 'fin' => 'fi',
/* French (Standard) */ 'fre' => 'fr',
/* French (Standard) */ 'fra' => 'fr',
/* French (Standard) - bibliographic */ 'fre' => 'fr',
/* Gaelic (Scots) */ 'gla' => 'gd',
/* Galician */ 'glg' => 'gl',
/* German (Standard) */ 'deu' => 'de',
/* German (Standard) */ 'ger' => 'de',
/* German (Standard) - bibliographic */ 'ger' => 'de',
/* Greek */ 'gre' => 'el',
/* Greek */ 'ell' => 'el',
/* Hebrew */ 'heb' => 'he',
/* Hindi */ 'hin' => 'hi',
/* Hungarian */ 'hun' => 'hu',
/* Icelandic */ 'ice' => 'is',
/* Icelandic */ 'isl' => 'is',
/* Icelandic - bibliographic */ 'ice' => 'is',
/* Indonesian */ 'ind' => 'id',
/* Irish */ 'gle' => 'ga',
/* Italian */ 'ita' => 'it',
/* Japanese */ 'jpn' => 'ja',
/* Kazakh */ 'kaz' => 'kk',
/* Kalaallisut (Greenlandic) */ 'kal' => 'kl',
/* Korean */ 'kor' => 'ko',
/* Latvian */ 'lav' => 'lv',
/* Limburgish */ 'lim' => 'li',
/* Lithuanian */ 'lit' => 'lt',
/* Macedonian */ 'mac' => 'mk',
/* Macedonian */ 'mkd' => 'mk',
/* Malaysian */ 'may' => 'ms',
/* Macedonian - bibliographic */ 'mac' => 'mk',
/* Malaysian */ 'msa' => 'ms',
/* Malaysian - bibliographic */ 'may' => 'ms',
/* Maltese */ 'mlt' => 'mt',
/* Norwegian */ 'nor' => 'no',
/* Norwegian Bokmal */ 'nob' => 'nb',
@ -144,14 +148,13 @@ class L10n {
/* Polish */ 'pol' => 'pl',
/* Portuguese (Portugal) */ 'por' => 'pt',
/* Rhaeto-Romanic */ 'roh' => 'rm',
/* Romanian */ 'rum' => 'ro',
/* Romanian */ 'ron' => 'ro',
/* Romanian - bibliographic */ 'rum' => 'ro',
/* Russian */ 'rus' => 'ru',
/* Sami (Lappish) */ 'smi' => 'sz',
/* Serbian */ 'scc' => 'sr',
/* Sami */ 'sme' => 'se',
/* Serbian */ 'srp' => 'sr',
/* Slovak */ 'slo' => 'sk',
/* Slovak */ 'slk' => 'sk',
/* Slovak - bibliographic */ 'slo' => 'sk',
/* Slovenian */ 'slv' => 'sl',
/* Sorbian */ 'wen' => 'sb',
/* Spanish (Spain - Traditional) */ 'spa' => 'es',
@ -165,6 +168,7 @@ class L10n {
/* Venda */ 'ven' => 've',
/* Vietnamese */ 'vie' => 'vi',
/* Welsh */ 'cym' => 'cy',
/* Welsh - bibliographic */ 'wel' => 'cy',
/* Xhosa */ 'xho' => 'xh',
/* Yiddish */ 'yid' => 'yi',
/* Zulu */ 'zul' => 'zu'
@ -203,16 +207,16 @@ class L10n {
'bo-in' => array('language' => 'Tibetan (India)', 'locale' => 'bo_in', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr'),
'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr'),
'cs' => array('language' => 'Czech', 'locale' => 'ces', 'localeFallback' => 'ces', 'charset' => 'utf-8', 'direction' => 'ltr'),
'da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr'),
'da-dk' => array('language' => 'Danish (Denmark)', 'locale' => 'da_dk', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-ch' => array('language' => 'German (Swiss)', 'locale' => 'de_ch', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-de' => array('language' => 'German (Germany)', 'locale' => 'de_de', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-li' => array('language' => 'German (Liechtenstein)', 'locale' => 'de_li', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-lu' => array('language' => 'German (Luxembourg)', 'locale' => 'de_lu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'e' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'el' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'el' => array('language' => 'Greek', 'locale' => 'ell', 'localeFallback' => 'ell', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-au' => array('language' => 'English (Australian)', 'locale' => 'en_au', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'en-bz' => array('language' => 'English (Belize)', 'locale' => 'en_bz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -245,16 +249,18 @@ class L10n {
'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr'),
'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fa' => array('language' => 'Farsi', 'locale' => 'per', 'localeFallback' => 'per', 'charset' => 'utf-8', 'direction' => 'rtl'),
'et-ee' => array('language' => 'Estonian (Estonia)', 'locale' => 'et_ee', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr'),
'eu' => array('language' => 'Basque', 'locale' => 'eus', 'localeFallback' => 'eus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fa' => array('language' => 'Farsi', 'locale' => 'fas', 'localeFallback' => 'fas', 'charset' => 'utf-8', 'direction' => 'rtl'),
'fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fi-fi' => array('language' => 'Finnish (Finland)', 'locale' => 'fi_fi', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr' => array('language' => 'French (Standard)', 'locale' => 'fra', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8', 'direction' => 'ltr'),
'gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -263,47 +269,56 @@ class L10n {
'hi' => array('language' => 'Hindi', 'locale' => 'hin', 'localeFallback' => 'hin', 'charset' => 'utf-8', 'direction' => 'ltr'),
'hr' => array('language' => 'Croatian', 'locale' => 'hrv', 'localeFallback' => 'hrv', 'charset' => 'utf-8', 'direction' => 'ltr'),
'hu' => array('language' => 'Hungarian', 'locale' => 'hun', 'localeFallback' => 'hun', 'charset' => 'utf-8', 'direction' => 'ltr'),
'hu-hu' => array('language' => 'Hungarian (Hungary)', 'locale' => 'hun', 'localeFallback' => 'hun', 'charset' => 'utf-8', 'direction' => 'ltr'),
'hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8', 'direction' => 'ltr'),
'id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
'in' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8', 'direction' => 'ltr'),
'is' => array('language' => 'Icelandic', 'locale' => 'isl', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr'),
'is-is' => array('language' => 'Icelandic (Iceland)', 'locale' => 'is_is', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr'),
'it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr'),
'kk' => array('language' => 'Kazakh', 'locale' => 'kaz', 'localeFallback' => 'kaz', 'charset' => 'utf-8', 'direction' => 'ltr'),
'kl' => array('language' => 'Kalaallisut (Greenlandic)', 'locale' => 'kal', 'localeFallback' => 'kal', 'charset' => 'kl', 'direction' => 'ltr'),
'kl-gl' => array('language' => 'Kalaallisut (Greenland)', 'locale' => 'kl_gl', 'localeFallback' => 'kal', 'charset' => 'kl', 'direction' => 'ltr'),
'ko' => array('language' => 'Korean', 'locale' => 'kor', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'),
'li' => array('language' => 'Limburgish', 'locale' => 'lim', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lv-lv' => array('language' => 'Latvian (Latvia)', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mkd', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ms' => array('language' => 'Malaysian', 'locale' => 'msa', 'localeFallback' => 'msa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr'),
'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nb-no' => array('language' => 'Norwegian Bokmål (Norway)', 'locale' => 'nb_no', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-nl' => array('language' => 'Dutch (Netherlands)', 'locale' => 'nl_nl', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nn-no' => array('language' => 'Norwegian Nynorsk (Norway)', 'locale' => 'nn_no', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'p' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pl' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
'rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-ro' => array('language' => 'Romanian (Romania)', 'locale' => 'ro_ro', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ru-ru' => array('language' => 'Russian (Russia)', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sk' => array('language' => 'Slovak', 'locale' => 'slk', 'localeFallback' => 'slk', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sq' => array('language' => 'Albanian', 'locale' => 'sqi', 'localeFallback' => 'sqi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sr' => array('language' => 'Serbian', 'locale' => 'srp', 'localeFallback' => 'srp', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sv-se' => array('language' => 'Swedish (Sweden)', 'locale' => 'sv_se', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sx' => array('language' => 'Sutu', 'locale' => 'sx', 'localeFallback' => 'sx', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'se' => array('language' => 'Sami', 'locale' => 'sme', 'localeFallback' => 'sme', 'charset' => 'utf-8', 'direction' => 'ltr'),
'th' => array('language' => 'Thai', 'locale' => 'tha', 'localeFallback' => 'tha', 'charset' => 'utf-8', 'direction' => 'ltr'),
'tn' => array('language' => 'Tswana', 'locale' => 'tsn', 'localeFallback' => 'tsn', 'charset' => 'utf-8', 'direction' => 'ltr'),
'tr' => array('language' => 'Turkish', 'locale' => 'tur', 'localeFallback' => 'tur', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -315,11 +330,11 @@ class L10n {
'cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8', 'direction' => 'ltr'),
'xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'zho', 'charset' => 'GB2312', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr')
);
@ -330,6 +345,10 @@ class L10n {
if (defined('DEFAULT_LANGUAGE')) {
$this->default = DEFAULT_LANGUAGE;
}
$default = Configure::read('Config.language');
if ($default) {
$this->default = $default;
}
}
/**
@ -353,44 +372,44 @@ class L10n {
/**
* Sets the class vars to correct values for $language.
* If $language is null it will use the DEFAULT_LANGUAGE if defined
* If $language is null it will use the L10n::$default if defined
*
* @param string $language Language (if null will use DEFAULT_LANGUAGE if defined)
* @param string $language Language (if null will use L10n::$default if defined)
* @return mixed
*/
protected function _setLanguage($language = null) {
$langKey = null;
if ($language !== null && isset($this->_l10nMap[$language]) && isset($this->_l10nCatalog[$this->_l10nMap[$language]])) {
$langKey = $this->_l10nMap[$language];
} elseif ($language !== null && isset($this->_l10nCatalog[$language])) {
$langKey = $language;
} elseif (defined('DEFAULT_LANGUAGE')) {
$langKey = $language = DEFAULT_LANGUAGE;
$catalog = false;
if ($language !== null) {
$catalog = $this->catalog($language);
}
if ($langKey !== null && isset($this->_l10nCatalog[$langKey])) {
$this->language = $this->_l10nCatalog[$langKey]['language'];
$this->languagePath = array(
$this->_l10nCatalog[$langKey]['locale'],
$this->_l10nCatalog[$langKey]['localeFallback']
);
if (!$catalog && $this->default) {
$language = $this->default;
$catalog = $this->catalog($language);
}
if ($catalog) {
$this->language = $catalog['language'];
$this->languagePath = array_unique(array(
$catalog['locale'],
$catalog['localeFallback']
));
$this->lang = $language;
$this->locale = $this->_l10nCatalog[$langKey]['locale'];
$this->charset = $this->_l10nCatalog[$langKey]['charset'];
$this->direction = $this->_l10nCatalog[$langKey]['direction'];
} else {
$this->locale = $catalog['locale'];
$this->charset = $catalog['charset'];
$this->direction = $catalog['direction'];
} elseif ($language) {
$this->lang = $language;
$this->languagePath = array($language);
}
if ($this->default) {
if (isset($this->_l10nMap[$this->default]) && isset($this->_l10nCatalog[$this->_l10nMap[$this->default]])) {
$this->languagePath[] = $this->_l10nCatalog[$this->_l10nMap[$this->default]]['localeFallback'];
} elseif (isset($this->_l10nCatalog[$this->default])) {
$this->languagePath[] = $this->_l10nCatalog[$this->default]['localeFallback'];
if ($this->default && $language !== $this->default) {
$catalog = $this->catalog($this->default);
$fallback = $catalog['localeFallback'];
if (!in_array($fallback, $this->languagePath)) {
$this->languagePath[] = $fallback;
}
}
$this->found = true;
if (Configure::read('Config.language') === null) {
Configure::write('Config.language', $this->lang);
@ -404,15 +423,16 @@ class L10n {
/**
* Attempts to find the locale settings based on the HTTP_ACCEPT_LANGUAGE variable
*
* @return boolean Success
* @return bool Success
*/
protected function _autoLanguage() {
$_detectableLanguages = CakeRequest::acceptLanguage();
foreach ($_detectableLanguages as $key => $langKey) {
foreach ($_detectableLanguages as $langKey) {
if (isset($this->_l10nCatalog[$langKey])) {
$this->_setLanguage($langKey);
return true;
} elseif (strpos($langKey, '-') !== false) {
}
if (strpos($langKey, '-') !== false) {
$langKey = substr($langKey, 0, 2);
if (isset($this->_l10nCatalog[$langKey])) {
$this->_setLanguage($langKey);
@ -427,7 +447,7 @@ class L10n {
* Attempts to find locale for language, or language for locale
*
* @param string|array $mixed 2/3 char string (language/locale), array of those strings, or null
* @return string|array|boolean string language/locale, array of those values, whole map as an array,
* @return string|array|bool string language/locale, array of those values, whole map as an array,
* or false when language/locale doesn't exist
*/
public function map($mixed = null) {
@ -439,10 +459,12 @@ class L10n {
}
}
return $result;
} elseif (is_string($mixed)) {
}
if (is_string($mixed)) {
if (strlen($mixed) === 2 && in_array($mixed, $this->_l10nMap)) {
return array_search($mixed, $this->_l10nMap);
} elseif (isset($this->_l10nMap[$mixed])) {
}
if (isset($this->_l10nMap[$mixed])) {
return $this->_l10nMap[$mixed];
}
return false;
@ -454,7 +476,7 @@ class L10n {
* Attempts to find catalog record for requested language
*
* @param string|array $language string requested language, array of requested languages, or null for whole catalog
* @return array|boolean array catalog record for requested language, array of catalog records, whole catalog,
* @return array|bool array catalog record for requested language, array of catalog records, whole catalog,
* or false when language doesn't exist
*/
public function catalog($language = null) {
@ -466,10 +488,12 @@ class L10n {
}
}
return $result;
} elseif (is_string($language)) {
}
if (is_string($language)) {
if (isset($this->_l10nCatalog[$language])) {
return $this->_l10nCatalog[$language];
} elseif (isset($this->_l10nMap[$language]) && isset($this->_l10nCatalog[$this->_l10nMap[$language]])) {
}
if (isset($this->_l10nMap[$language]) && isset($this->_l10nCatalog[$this->_l10nMap[$language]])) {
return $this->_l10nCatalog[$this->_l10nMap[$language]];
}
return false;

View file

@ -2,277 +2,20 @@
/**
* Multibyte handling methods.
*
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.I18n
* @since CakePHP(tm) v 1.2.0.6833
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
if (!function_exists('mb_stripos')) {
/**
* Find position of first occurrence of a case-insensitive string.
*
* @param string $haystack The string from which to get the position of the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false
* if $needle is not found.
*/
function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::stripos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_stristr')) {
/**
* Finds first occurrence of a string within another, case insensitive.
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack, or false if $needle is not found.
*/
function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::stristr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strlen')) {
/**
* Get string length.
*
* @param string $string The string being checked for length.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer The number of characters in string $string having character encoding encoding.
* A multi-byte character is counted as 1.
*/
function mb_strlen($string, $encoding = null) {
return Multibyte::strlen($string);
}
}
if (!function_exists('mb_strpos')) {
/**
* Find position of first occurrence of a string.
*
* @param string $haystack The string being checked.
* @param string $needle The position counted from the beginning of haystack.
* @param integer $offset The search offset. If it is not specified, 0 is used.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::strpos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_strrchr')) {
/**
* Finds the last occurrence of a character in a string within another.
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
*/
function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strrchr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strrichr')) {
/**
* Finds the last occurrence of a character in a string within another, case insensitive.
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
*/
function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strrichr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strripos')) {
/**
* Finds position of last occurrence of a string within another, case insensitive
*
* @param string $haystack The string from which to get the position of the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
* or false if $needle is not found.
*/
function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::strripos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_strrpos')) {
/**
* Find position of last occurrence of a string in a string.
*
* @param string $haystack The string being checked, for the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
* Negative values will stop searching at an arbitrary point prior to the end of the string.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::strrpos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_strstr')) {
/**
* Finds first occurrence of a string within another
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is FALSE.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack, or true if $needle is not found.
*/
function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strstr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strtolower')) {
/**
* Make a string lowercase
*
* @param string $string The string being lowercased.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string with all alphabetic characters converted to lowercase.
*/
function mb_strtolower($string, $encoding = null) {
return Multibyte::strtolower($string);
}
}
if (!function_exists('mb_strtoupper')) {
/**
* Make a string uppercase
*
* @param string $string The string being uppercased.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string with all alphabetic characters converted to uppercase.
*/
function mb_strtoupper($string, $encoding = null) {
return Multibyte::strtoupper($string);
}
}
if (!function_exists('mb_substr_count')) {
/**
* Count the number of substring occurrences
*
* @param string $haystack The string being checked.
* @param string $needle The string being found.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer The number of times the $needle substring occurs in the $haystack string.
*/
function mb_substr_count($haystack, $needle, $encoding = null) {
return Multibyte::substrCount($haystack, $needle);
}
}
if (!function_exists('mb_substr')) {
/**
* Get part of string
*
* @param string $string The string being checked.
* @param integer $start The first position used in $string.
* @param integer $length The maximum length of the returned string.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string The portion of $string specified by the $string and $length parameters.
*/
function mb_substr($string, $start, $length = null, $encoding = null) {
return Multibyte::substr($string, $start, $length);
}
}
if (!function_exists('mb_encode_mimeheader')) {
/**
* Encode string for MIME header
*
* @param string $str The string being encoded
* @param string $charset specifies the name of the character set in which str is represented in.
* The default value is determined by the current NLS setting (mbstring.language).
* @param string $transfer_encoding specifies the scheme of MIME encoding.
* It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
* @param string $linefeed specifies the EOL (end-of-line) marker with which
* mb_encode_mimeheader() performs line-folding
* (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
* The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
* @param integer $indent [definition unknown and appears to have no affect]
* @return string A converted version of the string represented in ASCII.
*/
function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
return Multibyte::mimeEncode($str, $charset, $linefeed);
}
}
/**
* Multibyte handling methods.
*
@ -305,7 +48,7 @@ class Multibyte {
* Converts a multibyte character string
* to the decimal value of the character
*
* @param string $string
* @param string $string String to convert.
* @return array
*/
public static function utf8($string) {
@ -344,7 +87,7 @@ class Multibyte {
* Converts the decimal value of a multibyte character string
* to a string
*
* @param array $array
* @param array $array Values array.
* @return string
*/
public static function ascii($array) {
@ -370,8 +113,8 @@ class Multibyte {
*
* @param string $haystack The string from which to get the position of the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string,
* @param int $offset The position in $haystack to start searching.
* @return int|bool The numeric position of the first occurrence of $needle in the $haystack string,
* or false if $needle is not found.
*/
public static function stripos($haystack, $needle, $offset = 0) {
@ -388,11 +131,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is false.
* @return integer|boolean The portion of $haystack, or false if $needle is not found.
* @return int|bool The portion of $haystack, or false if $needle is not found.
*/
public static function stristr($haystack, $needle, $part = false) {
$php = (PHP_VERSION < 5.3);
@ -448,7 +191,7 @@ class Multibyte {
* Get string length.
*
* @param string $string The string being checked for length.
* @return integer The number of characters in string $string
* @return int The number of characters in string $string
*/
public static function strlen($string) {
if (Multibyte::checkMultibyte($string)) {
@ -463,8 +206,8 @@ class Multibyte {
*
* @param string $haystack The string being checked.
* @param string $needle The position counted from the beginning of haystack.
* @param integer $offset The search offset. If it is not specified, 0 is used.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
* @param int $offset The search offset. If it is not specified, 0 is used.
* @return int|bool The numeric position of the first occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
public static function strpos($haystack, $needle, $offset = 0) {
@ -506,11 +249,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
* @return string|bool The portion of $haystack. or false if $needle is not found.
*/
public static function strrchr($haystack, $needle, $part = false) {
$check = Multibyte::utf8($haystack);
@ -566,11 +309,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
* @return string|bool The portion of $haystack. or false if $needle is not found.
*/
public static function strrichr($haystack, $needle, $part = false) {
$check = Multibyte::strtoupper($haystack);
@ -628,8 +371,8 @@ class Multibyte {
*
* @param string $haystack The string from which to get the position of the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
* @param int $offset The position in $haystack to start searching.
* @return int|bool The numeric position of the last occurrence of $needle in the $haystack string,
* or false if $needle is not found.
*/
public static function strripos($haystack, $needle, $offset = 0) {
@ -678,9 +421,9 @@ class Multibyte {
*
* @param string $haystack The string being checked, for the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
* @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
* Negative values will stop searching at an arbitrary point prior to the end of the string.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
* @return int|bool The numeric position of the last occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
public static function strrpos($haystack, $needle, $offset = 0) {
@ -728,11 +471,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is FALSE.
* @return string|boolean The portion of $haystack, or true if $needle is not found.
* @return string|bool The portion of $haystack, or true if $needle is not found.
*/
public static function strstr($haystack, $needle, $part = false) {
$php = (PHP_VERSION < 5.3);
@ -807,7 +550,7 @@ class Multibyte {
$matched = true;
} else {
$matched = false;
$keys = self::_find($char, 'upper');
$keys = static::_find($char, 'upper');
if (!empty($keys)) {
foreach ($keys as $key => $value) {
@ -853,7 +596,7 @@ class Multibyte {
} else {
$matched = false;
$keys = self::_find($char);
$keys = static::_find($char);
$keyCount = count($keys);
if (!empty($keys)) {
@ -919,7 +662,7 @@ class Multibyte {
*
* @param string $haystack The string being checked.
* @param string $needle The string being found.
* @return integer The number of times the $needle substring occurs in the $haystack string.
* @return int The number of times the $needle substring occurs in the $haystack string.
*/
public static function substrCount($haystack, $needle) {
$count = 0;
@ -953,8 +696,8 @@ class Multibyte {
* Get part of string
*
* @param string $string The string being checked.
* @param integer $start The first position used in $string.
* @param integer $length The maximum length of the returned string.
* @param int $start The first position used in $string.
* @param int $length The maximum length of the returned string.
* @return string The portion of $string specified by the $string and $length parameters.
*/
public static function substr($string, $start, $length = null) {
@ -985,7 +728,7 @@ class Multibyte {
*
* @param string $string value to encode
* @param string $charset charset to use for encoding. defaults to UTF-8
* @param string $newline
* @param string $newline Newline string.
* @return string
*/
public static function mimeEncode($string, $charset = null, $newline = "\r\n") {
@ -1004,7 +747,7 @@ class Multibyte {
$length = 75 - strlen($start) - strlen($end);
$length = $length - ($length % 4);
if ($charset == 'UTF-8') {
if ($charset === 'UTF-8') {
$parts = array();
$maxchars = floor(($length * 3) / 4);
$stringLength = strlen($string);
@ -1031,7 +774,7 @@ class Multibyte {
/**
* Return the Code points range for Unicode characters
*
* @param integer $decimal
* @param int $decimal Decimal value.
* @return string
*/
protected static function _codepoint($decimal) {
@ -1072,44 +815,44 @@ class Multibyte {
} else {
$return = false;
}
self::$_codeRange[$decimal] = $return;
static::$_codeRange[$decimal] = $return;
return $return;
}
/**
* Find the related code folding values for $char
*
* @param integer $char decimal value of character
* @param string $type
* @param int $char decimal value of character
* @param string $type Type 'lower' or 'upper'. Defaults to 'lower'.
* @return array
*/
protected static function _find($char, $type = 'lower') {
$found = array();
if (!isset(self::$_codeRange[$char])) {
$range = self::_codepoint($char);
if (!isset(static::$_codeRange[$char])) {
$range = static::_codepoint($char);
if ($range === false) {
return null;
return array();
}
if (!Configure::configured('_cake_core_')) {
App::uses('PhpReader', 'Configure');
Configure::config('_cake_core_', new PhpReader(CAKE . 'Config' . DS));
}
Configure::load('unicode' . DS . 'casefolding' . DS . $range, '_cake_core_');
self::$_caseFold[$range] = Configure::read($range);
static::$_caseFold[$range] = Configure::read($range);
Configure::delete($range);
}
if (!self::$_codeRange[$char]) {
return null;
if (!static::$_codeRange[$char]) {
return array();
}
self::$_table = self::$_codeRange[$char];
$count = count(self::$_caseFold[self::$_table]);
static::$_table = static::$_codeRange[$char];
$count = count(static::$_caseFold[static::$_table]);
for ($i = 0; $i < $count; $i++) {
if ($type === 'lower' && self::$_caseFold[self::$_table][$i][$type][0] === $char) {
$found[] = self::$_caseFold[self::$_table][$i];
} elseif ($type === 'upper' && self::$_caseFold[self::$_table][$i][$type] === $char) {
$found[] = self::$_caseFold[self::$_table][$i];
if ($type === 'lower' && static::$_caseFold[static::$_table][$i][$type][0] === $char) {
$found[] = static::$_caseFold[static::$_table][$i];
} elseif ($type === 'upper' && static::$_caseFold[static::$_table][$i][$type] === $char) {
$found[] = static::$_caseFold[static::$_table][$i];
}
}
return $found;
@ -1117,13 +860,14 @@ class Multibyte {
/**
* Check the $string for multibyte characters
* @param string $string value to test
* @return boolean
*
* @param string $string Value to test.
* @return bool
*/
public static function checkMultibyte($string) {
$length = strlen($string);
for ($i = 0; $i < $length; $i++ ) {
for ($i = 0; $i < $length; $i++) {
$value = ord(($string[$i]));
if ($value > 128) {
return true;