本文整理汇总了PHP中Cake\I18n\I18n::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP I18n::getInstance方法的具体用法?PHP I18n::getInstance怎么用?PHP I18n::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\I18n\I18n
的用法示例。
在下文中一共展示了I18n::getInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadLocaleDefinition
/**
* Parses a locale definition file following the POSIX standard
*
* @param string $filename Locale definition filename
* @return mixed Array of definitions on success or false on failure
*/
public static function loadLocaleDefinition($filename)
{
if (!($file = fopen($filename, 'r'))) {
return false;
}
$definitions = array();
$comment = '#';
$escape = '\\';
$currentToken = false;
$value = '';
$_this = I18n::getInstance();
while ($line = fgets($file)) {
$line = trim($line);
if (empty($line) || $line[0] === $comment) {
continue;
}
$parts = preg_split("/[[:space:]]+/", $line);
if ($parts[0] === 'comment_char') {
$comment = $parts[1];
continue;
}
if ($parts[0] === 'escape_char') {
$escape = $parts[1];
continue;
}
$count = count($parts);
if ($count === 2) {
$currentToken = $parts[0];
$value = $parts[1];
} elseif ($count === 1) {
$value = is_array($value) ? $parts[0] : $value . $parts[0];
} else {
continue;
}
$len = strlen($value) - 1;
if ($value[$len] === $escape) {
$value = substr($value, 0, $len);
continue;
}
$mustEscape = array($escape . ',', $escape . ';', $escape . '<', $escape . '>', $escape . $escape);
$replacements = array_map('crc32', $mustEscape);
$value = str_replace($mustEscape, $replacements, $value);
$value = explode(';', $value);
$_this->_escape = $escape;
foreach ($value as $i => $val) {
$val = trim($val, '"');
$val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/', array(&$_this, '_parseLiteralValue'), $val);
$val = str_replace($replacements, $mustEscape, $val);
$value[$i] = $val;
}
if (count($value) === 1) {
$definitions[$currentToken] = array_pop($value);
} else {
$definitions[$currentToken] = $value;
}
}
return $definitions;
}