mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Implementing support to multiline string in __*() calls.
This commit is contained in:
parent
43a95a79fc
commit
cd3529c986
3 changed files with 50 additions and 19 deletions
|
@ -316,24 +316,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);
|
||||
}
|
||||
|
@ -455,6 +444,34 @@ class ExtractTask extends Shell {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the strings from the position forward
|
||||
*
|
||||
* @param int $position Actual position on tokens array
|
||||
* @param int $target Number of strings to extract
|
||||
* @return array Strings extracted
|
||||
* @access private
|
||||
*/
|
||||
function __getStrings(&$position, $target) {
|
||||
$strings = array();
|
||||
while (count($strings) < $target && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
|
||||
if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1] == '.') {
|
||||
$string = '';
|
||||
while ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->__tokens[$position] == '.') {
|
||||
if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
|
||||
$string .= $this->__formatString($this->__tokens[$position][1]);
|
||||
}
|
||||
$position++;
|
||||
}
|
||||
$strings[] = $string;
|
||||
} else if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
|
||||
$strings[] = $this->__formatString($this->__tokens[$position][1]);
|
||||
}
|
||||
$position++;
|
||||
}
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string to be added as a translateable string
|
||||
*
|
||||
|
|
|
@ -118,7 +118,6 @@ class ExtractTaskTest extends CakeTestCase {
|
|||
$pattern = '/To change its layout, create: APP\/views\/layouts\/default\.ctp\./s';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
|
||||
// extract.ctp
|
||||
$pattern = '/\#: (\\\\|\/)extract\.ctp:6\n';
|
||||
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
||||
|
@ -131,9 +130,15 @@ class ExtractTaskTest extends CakeTestCase {
|
|||
$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
|
||||
$pattern .= '\#: (\\\\|\/)home\.ctp:99\n';
|
||||
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
||||
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
$pattern = '/\#: (\\\\|\/)extract\.ctp:17\nmsgid "';
|
||||
$pattern .= 'Hot features!';
|
||||
$pattern .= '\\\n - No Configuration: Set-up the database and let the magic begin';
|
||||
$pattern .= '\\\n - Extremely Simple: Just look at the name...It\'s Cake';
|
||||
$pattern .= '\\\n - Active, Friendly Community: Join us #cakephp on IRC. We\'d love to help you get started';
|
||||
$pattern .= '"\nmsgstr ""/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
// extract.ctp - reading the domain.pot
|
||||
$result = file_get_contents($this->path . DS . 'domain.pot');
|
||||
|
|
|
@ -12,3 +12,12 @@ echo __dn('domain', 'You deleted %d message (domain).', 'You deleted %d messages
|
|||
|
||||
// Duplicated Message
|
||||
echo __('Editing this Page');
|
||||
|
||||
// Multiline
|
||||
__('Hot features!'
|
||||
. "\n - No Configuration:"
|
||||
. ' Set-up the database and let the magic begin'
|
||||
. "\n - Extremely Simple:"
|
||||
. ' Just look at the name...It\'s Cake'
|
||||
. "\n - Active, Friendly Community:"
|
||||
. ' Join us #cakephp on IRC. We\'d love to help you get started');
|
||||
|
|
Loading…
Add table
Reference in a new issue