mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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
This commit is contained in:
parent
31b07795b2
commit
200c85c7c4
1 changed files with 35 additions and 15 deletions
|
@ -286,24 +286,13 @@ class ExtractTask extends Shell {
|
|||
}
|
||||
|
||||
$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 @@ class ExtractTask extends Shell {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue