Skip to content
Permalink
Browse files

Ticket #1669, i18n: parse (multiline) strings concatenated with "." (…

…for 1.3 branch)

The patch  builds on the code of cake 2.0, but with this fix, comments are allowed, and an exception is thrown if invalid output is found. Examples:

__('Split' . ' string')    => ok
__('Split' . // Comment
    ' string')             => ok
__('Split' . $var)         => error
  • Loading branch information...
zoydsan authored and markstory committed Sep 6, 2011
1 parent 31b0779 commit 200c85c7c4a1e0d11388b635e4ab55a1277b3e73
Showing with 35 additions and 15 deletions.
  1. +35 −15 cake/console/libs/tasks/extract.php
@@ -286,24 +286,13 @@ function __parse($functionName, $map) {
}
$mapCount = count($map);
$strings = array();
while (count($strings) < $mapCount && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$strings[] = $this->__tokens[$position][1];
}
$position++;
}
$strings = $this->__getStrings($position, $mapCount);
if ($mapCount == count($strings)) {
extract(array_combine($map, $strings));
if (!isset($domain)) {
$domain = '\'default\'';
}
$string = $this->__formatString($singular);
if (isset($plural)) {
$string .= "\0" . $this->__formatString($plural);
}
$this->__strings[$this->__formatString($domain)][$string][$this->__file][] = $line;
$domain = isset($domain) ? $domain : 'default';
$string = isset($plural) ? $singular . "\0" . $plural : $singular;
$this->__strings[$domain][$string][$this->__file][] = $line;
} else {
$this->__markerError($this->__file, $line, $functionName, $count);
}
@@ -312,6 +301,37 @@ function __parse($functionName, $map) {
}
}
/**
* Get the strings from the position forward
*
* @param integer $position Actual position on tokens array
* @param integer $target Number of strings to extract
* @return array Strings extracted
*/
function __getStrings($position, $target) {
$strings = array();
while (count($strings) < $target && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
$condition1 = ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1] == '.');
$condition2 = ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1][0] == T_COMMENT);
if ($condition1 || $condition2) {
$string = '';
while ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->__tokens[$position][0] == T_COMMENT || $this->__tokens[$position] == '.') {
if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$string .= $this->__formatString($this->__tokens[$position][1]);
}
$position++;
}
if ($this->__tokens[$position][0] == T_COMMENT || $this->__tokens[$position] == ',' || $this->__tokens[$position] == ')') {
$strings[] = $string;
}
} else if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$strings[] = $this->__formatString($this->__tokens[$position][1]);
}
$position++;
}
return $strings;
}
/**
* Build the translate template file contents out of obtained strings
*

0 comments on commit 200c85c

Please sign in to comment.
You can’t perform that action at this time.