Skip to content
Permalink
Browse files

Port changes in #8172 to 3.x

* Make `cake i18n extract` faster.
* Make paths consistent.

Refs #8172
  • Loading branch information...
markstory committed Feb 4, 2016
1 parent e246139 commit fda08ae2ea9711e2067bb0940bbc663127c5169e
Showing with 13 additions and 10 deletions.
  1. +8 −5 src/Shell/Task/ExtractTask.php
  2. +5 −5 tests/TestCase/Shell/Task/ExtractTaskTest.php
@@ -462,6 +462,11 @@ protected function _buildFiles()
{
$paths = $this->_paths;
$paths[] = realpath(APP) . DS;
usort($paths, function ($a, $b) {
return strlen($a) - strlen($b);
});
foreach ($this->_translations as $domain => $translations) {
foreach ($translations as $msgid => $contexts) {
foreach ($contexts as $context => $details) {
@@ -694,18 +699,16 @@ protected function _searchFiles()
$pattern = '/' . implode('|', $exclude) . '/';
}
foreach ($this->_paths as $path) {
$path = realpath($path) . DS;
$Folder = new Folder($path);
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
if (!empty($pattern)) {
foreach ($files as $i => $file) {
if (preg_match($pattern, $file)) {
unset($files[$i]);
}
}
$files = preg_grep($pattern, $files, PREG_GREP_INVERT);
$files = array_values($files);
}
$this->_files = array_merge($this->_files, $files);
}
$this->_files = array_unique($this->_files);
}
/**
@@ -89,18 +89,18 @@ public function testExecute()
$this->assertFalse(file_exists($this->path . DS . 'cake.pot'));
// extract.ctp
$pattern = '/\#: (\\\\|\/)extract\.ctp:\d+;\d+\n';
$pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+;\d+\n';
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "You have %d new message."\nmsgstr ""/';
$this->assertNotRegExp($pattern, $result, 'No duplicate msgid');
$pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\n';
$pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\n';
$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
$this->assertRegExp($pattern, $result);
$pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\nmsgid "';
$pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\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';
@@ -111,12 +111,12 @@ public function testExecute()
$this->assertContains('msgid "double \\"quoted\\""', $result, 'Strings with quotes not handled correctly');
$this->assertContains("msgid \"single 'quoted'\"", $result, 'Strings with quotes not handled correctly');
$pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\n';
$pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\n';
$pattern .= 'msgctxt "mail"\n';
$pattern .= 'msgid "letter"/';
$this->assertRegExp($pattern, $result);
$pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\n';
$pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\n';
$pattern .= 'msgctxt "alphabet"\n';
$pattern .= 'msgid "letter"/';
$this->assertRegExp($pattern, $result);

0 comments on commit fda08ae

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