Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Continuing work on locale definition file parser

  • Loading branch information...
commit 50f58da60d52148562c4d743498011fbee4c80de 1 parent 8bc4f03
@lorenzo lorenzo authored
View
34 cake/libs/i18n.php
@@ -277,6 +277,7 @@ function __bindTextDomain($domain) {
foreach ($this->l10n->languagePath as $lang) {
$file = $directory . $lang . DS . $this->category . DS . $domain;
+ $localeDef = $directory . $lang . DS . $this->category;
if ($core) {
$app = $directory . $lang . DS . $this->category . DS . 'core';
@@ -302,6 +303,10 @@ function __bindTextDomain($domain) {
$this->__loadPo($f, $domain);
$this->__noLocale = false;
break 2;
+ } elseif (file_exists($localeDef) && ($f = fopen($localeDef, "r"))) {
+ $this->__loadLocaleDefinition($f, $domain);
+ $this->__noLocale = false;
+ return $domain;
}
}
}
@@ -445,12 +450,11 @@ function __loadPo($file, $domain) {
function __loadLocaleDefinition($file, $domain = null) {
$_this =& I18N::getInstance();
- $handler = fopen($file,'r');
$comment = '#';
$escape = '\\';
$currentToken = false;
$value = '';
- while ($line = fgets($handler)) {
+ while ($line = fgets($file)) {
$line = trim($line);
if (empty($line) || $line[0] === $comment) {
continue;
@@ -487,7 +491,7 @@ function __loadLocaleDefinition($file, $domain = null) {
$_this->__escape = $escape;
foreach ($value as $i => $val) {
$val = trim($val,'"');
- $val = preg_replace_callback('/(<)?(?P<literal>.[^>]*)(>)?/',array(&$this,'__parseLiteralValue'),$val);
+ $val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/',array(&$this,'__parseLiteralValue'),$val);
$val = str_replace($replacements,$mustEscape,$val);
$value[$i] = $val;
}
@@ -497,21 +501,25 @@ function __loadLocaleDefinition($file, $domain = null) {
$this->__domains[$this->category][$this->__lang][$domain][$currentToken] = $value;
}
}
- debug($this->__domains[$this->category][$this->__lang][$domain],true);
}
function __parseLiteralValue($string) {
- $string = $string['literal'];
- switch (substr($string,0,2)) {
- case $this->__escape . 'x':
- $string = chr(hexdec(substr($string,-2)));
- break;
- case $this->__escape . 'd':
-
- break;
+ $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)))));
+ }
+ if (substr($string,0,2) === $this->__escape . 'd') {
+ $delimiter = $this->__escape . 'd';
+ return join('',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))));
}
if (substr($string,0,3) === 'U00') {
- $string = chr(hexdec(substr($string,-2)));
+ $delimiter = 'U00';
+ return join('',array_map('chr',array_map('hexdec',array_filter(explode($delimiter,$string)))));
}
return $string;
}
View
5 cake/tests/cases/libs/i18n.test.php
@@ -2590,9 +2590,8 @@ function testCategoryThenSingular() {
}
function testTimeDefinition() {
- $I18n = I18n::getInstance();
- $file = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' . DS . 'po' . DS .'LC_TIME';
- $I18n->__loadLocaleDefinition($file);
+ Configure::write('Config.language', 'po');
+ $abday = __c('abday', 5, true);
}
/**
View
2  cake/tests/test_app/locale/po/LC_TIME
@@ -1,6 +1,6 @@
escape_char /
comment_char %
-abday "<U0053><U0075><U006E></x6e>";"<U004D><U006F><U006E>";/
+abday "<U0053><U0075><U006E>";"<U004D><U006F><U006E>";/
"<U0054><U0075><U0065>";"<U0057><U0065><U0064>";/
"<U0054><U0068><U0075>";"<U0046><U0072><U0069>";/
"<U0053><U0061><U0074>"
Please sign in to comment.
Something went wrong with that request. Please try again.