Skip to content

Commit

Permalink
Port changes in #8172 to 3.x
Browse files Browse the repository at this point in the history
* Make `cake i18n extract` faster.
* Make paths consistent.

Refs #8172
  • Loading branch information
markstory committed Feb 4, 2016
1 parent e246139 commit fda08ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/Shell/Task/ExtractTask.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Shell/Task/ExtractTaskTest.php
Expand Up @@ -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';
Expand All @@ -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);
Expand Down

0 comments on commit fda08ae

Please sign in to comment.