mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: Allow string concatenation in default text in _t() calls
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81409 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
e1fa960775
commit
8ee9373807
@ -175,10 +175,11 @@ class i18nTextCollector extends Object {
|
||||
$entitiesArr = array();
|
||||
|
||||
$regexRule = '_t[[:space:]]*\(' .
|
||||
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . # namespace.entity
|
||||
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\')([[:space:]*,' . # value
|
||||
'[[:space:]]*[^,)]*)?([[:space:]]*,' . # priority (optional)
|
||||
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . # comment
|
||||
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity
|
||||
'[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value
|
||||
'([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations
|
||||
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
|
||||
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
|
||||
'\)';
|
||||
while (ereg($regexRule, $content, $regs)) {
|
||||
$entitiesArr = array_merge($entitiesArr, (array)$this->entitySpecFromRegexMatches($regs));
|
||||
@ -211,10 +212,11 @@ class i18nTextCollector extends Object {
|
||||
|
||||
// @todo respect template tags (< % _t() % > instead of _t())
|
||||
$regexRule = '_t[[:space:]]*\(' .
|
||||
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . # namespace.entity
|
||||
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\')([[:space:]]*,' . # value
|
||||
'[[:space:]]*[^,)]*)?([[:space:]]*,' . # priority (optional)
|
||||
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . # comment (optional)
|
||||
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity
|
||||
'[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value
|
||||
'([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations
|
||||
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
|
||||
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
|
||||
'\)';
|
||||
while(ereg($regexRule,$content,$regs)) {
|
||||
$entitiesArr = array_merge($entitiesArr,(array)$this->entitySpecFromRegexMatches($regs, $fileName));
|
||||
@ -281,16 +283,18 @@ class i18nTextCollector extends Object {
|
||||
// remove wrapping quotes
|
||||
$value = ($regs[2]) ? substr($regs[2],1,-1) : null;
|
||||
|
||||
$value = ereg_replace("([^\\])['\"][[:space:]]*.[[:space:]]*['\"]",'\\1',$value);
|
||||
|
||||
// only escape quotes when wrapped in double quotes, to make them safe for insertion
|
||||
// into single-quoted PHP code. If they're wrapped in single quotes, the string should
|
||||
// be properly escaped already
|
||||
if(substr($regs[2],0,1) == '"') $value = addcslashes($value,'\'');
|
||||
|
||||
// remove starting comma and any newlines
|
||||
$prio = ($regs[5]) ? trim(preg_replace('/\n/','',substr($regs[5],1))) : null;
|
||||
$prio = ($regs[10]) ? trim(preg_replace('/\n/','',substr($regs[10],1))) : null;
|
||||
|
||||
// remove wrapping quotes
|
||||
$comment = ($regs[7]) ? substr($regs[7],1,-1) : null;
|
||||
$comment = ($regs[12]) ? substr($regs[12],1,-1) : null;
|
||||
|
||||
return array(
|
||||
"{$namespace}.{$entity}" => array(
|
||||
|
@ -64,6 +64,26 @@ class i18nTextCollectorTest extends SapphireTest {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
function testConcatenationInEntityValues() {
|
||||
$c = new i18nTextCollector();
|
||||
|
||||
$php = <<<PHP
|
||||
_t(
|
||||
'Test.CONCATENATED',
|
||||
'Line 1' .
|
||||
'Line 2' .
|
||||
'Line 3',
|
||||
PR_MEDIUM,
|
||||
'Comment'
|
||||
);
|
||||
PHP;
|
||||
$this->assertEquals(
|
||||
$c->collectFromCode($php, 'mymodule'),
|
||||
array(
|
||||
'Test.CONCATENATED' => array("Line 1Line 2Line 3",'PR_MEDIUM','Comment')
|
||||
)
|
||||
);
|
||||
}
|
||||
function testCollectFromTemplateSimple() {
|
||||
$c = new i18nTextCollector();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user