mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding a new option to i18n shell to generate .pot files without sentence references
This commit is contained in:
parent
47dd42ae84
commit
44756eaac5
2 changed files with 53 additions and 7 deletions
|
@ -48,6 +48,13 @@ class ExtractTask extends AppShell {
|
||||||
*/
|
*/
|
||||||
protected $_merge = false;
|
protected $_merge = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add headers for each sentence showing references
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $_headers = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current file being processed
|
* Current file being processed
|
||||||
*
|
*
|
||||||
|
@ -224,6 +231,10 @@ class ExtractTask extends AppShell {
|
||||||
$this->_merge = strtolower($response) === 'y';
|
$this->_merge = strtolower($response) === 'y';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($this->params['headers'])) {
|
||||||
|
$this->_headers = !(strtolower($this->params['headers']) === 'no');
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($this->_files)) {
|
if (empty($this->_files)) {
|
||||||
$this->_searchFiles();
|
$this->_searchFiles();
|
||||||
}
|
}
|
||||||
|
@ -316,6 +327,9 @@ class ExtractTask extends AppShell {
|
||||||
))->addOption('merge', array(
|
))->addOption('merge', array(
|
||||||
'help' => __d('cake_console', 'Merge all domain and category strings into the default.po file.'),
|
'help' => __d('cake_console', 'Merge all domain and category strings into the default.po file.'),
|
||||||
'choices' => array('yes', 'no')
|
'choices' => array('yes', 'no')
|
||||||
|
))->addOption('headers', array(
|
||||||
|
'help' => __d('cake_console', 'Add headers for each sentence showing references'),
|
||||||
|
'choices' => array('yes', 'no')
|
||||||
))->addOption('output', array(
|
))->addOption('output', array(
|
||||||
'help' => __d('cake_console', 'Full path to output directory.')
|
'help' => __d('cake_console', 'Full path to output directory.')
|
||||||
))->addOption('files', array(
|
))->addOption('files', array(
|
||||||
|
@ -572,14 +586,17 @@ class ExtractTask extends AppShell {
|
||||||
foreach ($translations as $msgid => $contexts) {
|
foreach ($translations as $msgid => $contexts) {
|
||||||
foreach ($contexts as $context => $details) {
|
foreach ($contexts as $context => $details) {
|
||||||
$plural = $details['msgid_plural'];
|
$plural = $details['msgid_plural'];
|
||||||
$files = $details['references'];
|
$header = '';
|
||||||
$occurrences = array();
|
if ($this->_headers) {
|
||||||
foreach ($files as $file => $lines) {
|
$files = $details['references'];
|
||||||
$lines = array_unique($lines);
|
$occurrences = array();
|
||||||
$occurrences[] = $file . ':' . implode(';', $lines);
|
foreach ($files as $file => $lines) {
|
||||||
|
$lines = array_unique($lines);
|
||||||
|
$occurrences[] = $file . ':' . implode(';', $lines);
|
||||||
|
}
|
||||||
|
$occurrences = implode("\n#: ", $occurrences);
|
||||||
|
$header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
|
||||||
}
|
}
|
||||||
$occurrences = implode("\n#: ", $occurrences);
|
|
||||||
$header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
|
|
||||||
|
|
||||||
$sentence = '';
|
$sentence = '';
|
||||||
if ($context) {
|
if ($context) {
|
||||||
|
|
|
@ -221,6 +221,35 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
$this->assertNotRegExp($pattern, $result);
|
$this->assertNotRegExp($pattern, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testExtractWithoutHeaders method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExtractWithoutHeaders() {
|
||||||
|
$this->Task->interactive = false;
|
||||||
|
|
||||||
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages';
|
||||||
|
$this->Task->params['output'] = $this->path . DS;
|
||||||
|
$this->Task->params['extract-core'] = 'no';
|
||||||
|
$this->Task->params['merge'] = 'no';
|
||||||
|
$this->Task->params['headers'] = 'no';
|
||||||
|
|
||||||
|
$this->Task->expects($this->never())->method('err');
|
||||||
|
$this->Task->expects($this->any())->method('in')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
$this->Task->expects($this->never())->method('_stop');
|
||||||
|
|
||||||
|
$this->Task->execute();
|
||||||
|
$this->assertTrue(file_exists($this->path . DS . 'LC_NUMERIC' . DS . 'default.pot'));
|
||||||
|
$this->assertFalse(file_exists($this->path . DS . 'LC_TIME' . DS . 'default.pot'));
|
||||||
|
|
||||||
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
||||||
|
|
||||||
|
$pattern = '/\n\#: .*\n/';
|
||||||
|
$this->assertNotRegExp($pattern, $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test exclusions
|
* test exclusions
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue