mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-10-30 15:53:59 +01:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
|
@ -2,18 +2,17 @@
|
|||
/**
|
||||
* Language string extractor
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppShell', 'Console/Command');
|
||||
|
|
@ -43,9 +42,9 @@ class ExtractTask extends AppShell {
|
|||
protected $_files = array();
|
||||
|
||||
/**
|
||||
* Merge all domains string into the default.pot file
|
||||
* Merge all domain and category strings into the default.pot file
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_merge = false;
|
||||
|
||||
|
|
@ -71,7 +70,7 @@ class ExtractTask extends AppShell {
|
|||
protected $_tokens = array();
|
||||
|
||||
/**
|
||||
* Extracted strings indexed by domain.
|
||||
* Extracted strings indexed by category, domain, msgid and context.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -94,21 +93,21 @@ class ExtractTask extends AppShell {
|
|||
/**
|
||||
* Holds whether this call should extract model validation messages
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_extractValidation = true;
|
||||
|
||||
/**
|
||||
* Holds the validation string domain to use for validation messages when extracting
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_validationDomain = 'default';
|
||||
|
||||
/**
|
||||
* Holds whether this call should extract the CakePHP Lib messages
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_extractCore = false;
|
||||
|
||||
|
|
@ -128,7 +127,7 @@ class ExtractTask extends AppShell {
|
|||
);
|
||||
$response = $this->in($message, null, $defaultPath);
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__d('cake_console', 'Extract Aborted'));
|
||||
$this->err(__d('cake_console', 'Extract Aborted'));
|
||||
return $this->_stop();
|
||||
} elseif (strtoupper($response) === 'D' && count($this->_paths)) {
|
||||
$this->out();
|
||||
|
|
@ -152,7 +151,7 @@ class ExtractTask extends AppShell {
|
|||
*/
|
||||
public function execute() {
|
||||
if (!empty($this->params['exclude'])) {
|
||||
$this->_exclude = explode(',', $this->params['exclude']);
|
||||
$this->_exclude = explode(',', str_replace('/', DS, $this->params['exclude']));
|
||||
}
|
||||
if (isset($this->params['files']) && !is_array($this->params['files'])) {
|
||||
$this->_files = explode(',', $this->params['files']);
|
||||
|
|
@ -177,14 +176,6 @@ class ExtractTask extends AppShell {
|
|||
$this->_extractCore = strtolower($response) === 'y';
|
||||
}
|
||||
|
||||
if ($this->_extractCore) {
|
||||
$this->_paths[] = CAKE;
|
||||
$this->_exclude = array_merge($this->_exclude, array(
|
||||
CAKE . 'Test',
|
||||
CAKE . 'Console' . DS . 'Templates'
|
||||
));
|
||||
}
|
||||
|
||||
if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
|
||||
$this->_exclude = array_merge($this->_exclude, App::path('plugins'));
|
||||
}
|
||||
|
|
@ -196,6 +187,14 @@ class ExtractTask extends AppShell {
|
|||
$this->_validationDomain = $this->params['validation-domain'];
|
||||
}
|
||||
|
||||
if ($this->_extractCore) {
|
||||
$this->_paths[] = CAKE;
|
||||
$this->_exclude = array_merge($this->_exclude, array(
|
||||
CAKE . 'Test',
|
||||
CAKE . 'Console' . DS . 'Templates'
|
||||
));
|
||||
}
|
||||
|
||||
if (isset($this->params['output'])) {
|
||||
$this->_output = $this->params['output'];
|
||||
} elseif (isset($this->params['plugin'])) {
|
||||
|
|
@ -205,9 +204,9 @@ class ExtractTask extends AppShell {
|
|||
while (true) {
|
||||
$response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale');
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__d('cake_console', 'Extract Aborted'));
|
||||
$this->_stop();
|
||||
} elseif (is_dir($response)) {
|
||||
$this->err(__d('cake_console', 'Extract Aborted'));
|
||||
return $this->_stop();
|
||||
} elseif ($this->_isPathUsable($response)) {
|
||||
$this->_output = $response . DS;
|
||||
break;
|
||||
} else {
|
||||
|
|
@ -221,14 +220,20 @@ class ExtractTask extends AppShell {
|
|||
$this->_merge = !(strtolower($this->params['merge']) === 'no');
|
||||
} else {
|
||||
$this->out();
|
||||
$response = $this->in(__d('cake_console', 'Would you like to merge all domains strings into the default.pot file?'), array('y', 'n'), 'n');
|
||||
$response = $this->in(__d('cake_console', 'Would you like to merge all domain and category strings into the default.pot file?'), array('y', 'n'), 'n');
|
||||
$this->_merge = strtolower($response) === 'y';
|
||||
}
|
||||
|
||||
if (empty($this->_files)) {
|
||||
$this->_searchFiles();
|
||||
}
|
||||
|
||||
$this->_output = rtrim($this->_output, DS) . DS;
|
||||
if (!$this->_isPathUsable($this->_output)) {
|
||||
$this->err(__d('cake_console', 'The output directory %s was not found or writable.', $this->_output));
|
||||
return $this->_stop();
|
||||
}
|
||||
|
||||
$this->_extract();
|
||||
}
|
||||
|
||||
|
|
@ -237,27 +242,33 @@ class ExtractTask extends AppShell {
|
|||
*
|
||||
* Takes care of duplicate translations
|
||||
*
|
||||
* @param string $domain
|
||||
* @param string $msgid
|
||||
* @param array $details
|
||||
* @param string $category The category
|
||||
* @param string $domain The domain
|
||||
* @param string $msgid The message string
|
||||
* @param array $details The file and line references
|
||||
* @return void
|
||||
*/
|
||||
protected function _addTranslation($domain, $msgid, $details = array()) {
|
||||
if (empty($this->_translations[$domain][$msgid])) {
|
||||
$this->_translations[$domain][$msgid] = array(
|
||||
'msgid_plural' => false
|
||||
);
|
||||
protected function _addTranslation($category, $domain, $msgid, $details = array()) {
|
||||
$context = '';
|
||||
if (isset($details['msgctxt'])) {
|
||||
$context = $details['msgctxt'];
|
||||
}
|
||||
|
||||
if (empty($this->_translations[$category][$domain][$msgid][$context])) {
|
||||
$this->_translations[$category][$domain][$msgid][$context] = array(
|
||||
'msgid_plural' => false,
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($details['msgid_plural'])) {
|
||||
$this->_translations[$domain][$msgid]['msgid_plural'] = $details['msgid_plural'];
|
||||
$this->_translations[$category][$domain][$msgid][$context]['msgid_plural'] = $details['msgid_plural'];
|
||||
}
|
||||
|
||||
if (isset($details['file'])) {
|
||||
$line = 0;
|
||||
if (isset($details['line'])) {
|
||||
$line = $details['line'];
|
||||
}
|
||||
$this->_translations[$domain][$msgid]['references'][$details['file']][] = $line;
|
||||
$this->_translations[$category][$domain][$msgid][$context]['references'][$details['file']][] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -289,52 +300,59 @@ class ExtractTask extends AppShell {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get & configure the option parser
|
||||
* Gets the option parser instance and configures it.
|
||||
*
|
||||
* @return void
|
||||
* @return ConsoleOptionParser
|
||||
*/
|
||||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(__d('cake_console', 'CakePHP Language String Extraction:'))
|
||||
->addOption('app', array('help' => __d('cake_console', 'Directory where your application is located.')))
|
||||
->addOption('paths', array('help' => __d('cake_console', 'Comma separated list of paths.')))
|
||||
->addOption('merge', array(
|
||||
'help' => __d('cake_console', 'Merge all domain strings into the default.po file.'),
|
||||
'choices' => array('yes', 'no')
|
||||
))
|
||||
->addOption('output', array('help' => __d('cake_console', 'Full path to output directory.')))
|
||||
->addOption('files', array('help' => __d('cake_console', 'Comma separated list of files.')))
|
||||
->addOption('exclude-plugins', array(
|
||||
'boolean' => true,
|
||||
'default' => true,
|
||||
'help' => __d('cake_console', 'Ignores all files in plugins if this command is run inside from the same app directory.')
|
||||
))
|
||||
->addOption('plugin', array(
|
||||
'help' => __d('cake_console', 'Extracts tokens only from the plugin specified and puts the result in the plugin\'s Locale directory.')
|
||||
))
|
||||
->addOption('ignore-model-validation', array(
|
||||
'boolean' => true,
|
||||
'default' => false,
|
||||
'help' => __d('cake_console', 'Ignores validation messages in the $validate property.' .
|
||||
' If this flag is not set and the command is run from the same app directory,' .
|
||||
' all messages in model validation rules will be extracted as tokens.')
|
||||
))
|
||||
->addOption('validation-domain', array(
|
||||
'help' => __d('cake_console', 'If set to a value, the localization domain to be used for model validation messages.')
|
||||
))
|
||||
->addOption('exclude', array(
|
||||
'help' => __d('cake_console', 'Comma separated list of directories to exclude.' .
|
||||
' Any path containing a path segment with the provided values will be skipped. E.g. test,vendors')
|
||||
))
|
||||
->addOption('overwrite', array(
|
||||
'boolean' => true,
|
||||
'default' => false,
|
||||
'help' => __d('cake_console', 'Always overwrite existing .pot files.')
|
||||
))
|
||||
->addOption('extract-core', array(
|
||||
'help' => __d('cake_console', 'Extract messages from the CakePHP core libs.'),
|
||||
'choices' => array('yes', 'no')
|
||||
));
|
||||
|
||||
$parser->description(
|
||||
__d('cake_console', 'CakePHP Language String Extraction:')
|
||||
)->addOption('app', array(
|
||||
'help' => __d('cake_console', 'Directory where your application is located.')
|
||||
))->addOption('paths', array(
|
||||
'help' => __d('cake_console', 'Comma separated list of paths.')
|
||||
))->addOption('merge', array(
|
||||
'help' => __d('cake_console', 'Merge all domain and category strings into the default.po file.'),
|
||||
'choices' => array('yes', 'no')
|
||||
))->addOption('no-location', array(
|
||||
'boolean' => true,
|
||||
'default' => false,
|
||||
'help' => __d('cake_console', 'Do not write lines with locations'),
|
||||
))->addOption('output', array(
|
||||
'help' => __d('cake_console', 'Full path to output directory.')
|
||||
))->addOption('files', array(
|
||||
'help' => __d('cake_console', 'Comma separated list of files.')
|
||||
))->addOption('exclude-plugins', array(
|
||||
'boolean' => true,
|
||||
'default' => true,
|
||||
'help' => __d('cake_console', 'Ignores all files in plugins if this command is run inside from the same app directory.')
|
||||
))->addOption('plugin', array(
|
||||
'help' => __d('cake_console', 'Extracts tokens only from the plugin specified and puts the result in the plugin\'s Locale directory.')
|
||||
))->addOption('ignore-model-validation', array(
|
||||
'boolean' => true,
|
||||
'default' => false,
|
||||
'help' => __d('cake_console', 'Ignores validation messages in the $validate property.' .
|
||||
' If this flag is not set and the command is run from the same app directory,' .
|
||||
' all messages in model validation rules will be extracted as tokens.'
|
||||
)
|
||||
))->addOption('validation-domain', array(
|
||||
'help' => __d('cake_console', 'If set to a value, the localization domain to be used for model validation messages.')
|
||||
))->addOption('exclude', array(
|
||||
'help' => __d('cake_console', 'Comma separated list of directories to exclude.' .
|
||||
' Any path containing a path segment with the provided values will be skipped. E.g. test,vendors'
|
||||
)
|
||||
))->addOption('overwrite', array(
|
||||
'boolean' => true,
|
||||
'default' => false,
|
||||
'help' => __d('cake_console', 'Always overwrite existing .pot files.')
|
||||
))->addOption('extract-core', array(
|
||||
'help' => __d('cake_console', 'Extract messages from the CakePHP core libs.'),
|
||||
'choices' => array('yes', 'no')
|
||||
));
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -345,14 +363,14 @@ class ExtractTask extends AppShell {
|
|||
protected function _extractTokens() {
|
||||
foreach ($this->_files as $file) {
|
||||
$this->_file = $file;
|
||||
$this->out(__d('cake_console', 'Processing %s...', $file));
|
||||
$this->out(__d('cake_console', 'Processing %s...', $file), 1, Shell::VERBOSE);
|
||||
|
||||
$code = file_get_contents($file);
|
||||
$allTokens = token_get_all($code);
|
||||
|
||||
$this->_tokens = array();
|
||||
foreach ($allTokens as $token) {
|
||||
if (!is_array($token) || ($token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML)) {
|
||||
if (!is_array($token) || ($token[0] !== T_WHITESPACE && $token[0] !== T_INLINE_HTML)) {
|
||||
$this->_tokens[] = $token;
|
||||
}
|
||||
}
|
||||
|
|
@ -360,10 +378,19 @@ class ExtractTask extends AppShell {
|
|||
$this->_parse('__', array('singular'));
|
||||
$this->_parse('__n', array('singular', 'plural'));
|
||||
$this->_parse('__d', array('domain', 'singular'));
|
||||
$this->_parse('__c', array('singular'));
|
||||
$this->_parse('__dc', array('domain', 'singular'));
|
||||
$this->_parse('__c', array('singular', 'category'));
|
||||
$this->_parse('__dc', array('domain', 'singular', 'category'));
|
||||
$this->_parse('__dn', array('domain', 'singular', 'plural'));
|
||||
$this->_parse('__dcn', array('domain', 'singular', 'plural'));
|
||||
$this->_parse('__dcn', array('domain', 'singular', 'plural', 'count', 'category'));
|
||||
|
||||
$this->_parse('__x', array('context', 'singular'));
|
||||
$this->_parse('__xn', array('context', 'singular', 'plural'));
|
||||
$this->_parse('__dx', array('domain', 'context', 'singular'));
|
||||
$this->_parse('__dxc', array('domain', 'context', 'singular', 'category'));
|
||||
$this->_parse('__dxn', array('domain', 'context', 'singular', 'plural'));
|
||||
$this->_parse('__dxcn', array('domain', 'context', 'singular', 'plural', 'count', 'category'));
|
||||
$this->_parse('__xc', array('context', 'singular', 'category'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -371,11 +398,12 @@ class ExtractTask extends AppShell {
|
|||
* Parse tokens
|
||||
*
|
||||
* @param string $functionName Function name that indicates translatable string (e.g: '__')
|
||||
* @param array $map Array containing what variables it will find (e.g: domain, singular, plural)
|
||||
* @param array $map Array containing what variables it will find (e.g: category, domain, singular, plural)
|
||||
* @return void
|
||||
*/
|
||||
protected function _parse($functionName, $map) {
|
||||
$count = 0;
|
||||
$categories = array('LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES');
|
||||
$tokenCount = count($this->_tokens);
|
||||
|
||||
while (($tokenCount - $count) > 1) {
|
||||
|
|
@ -387,14 +415,14 @@ class ExtractTask extends AppShell {
|
|||
}
|
||||
|
||||
list($type, $string, $line) = $countToken;
|
||||
if (($type == T_STRING) && ($string == $functionName) && ($firstParenthesis == '(')) {
|
||||
if (($type == T_STRING) && ($string === $functionName) && ($firstParenthesis === '(')) {
|
||||
$position = $count;
|
||||
$depth = 0;
|
||||
|
||||
while ($depth == 0) {
|
||||
if ($this->_tokens[$position] == '(') {
|
||||
while (!$depth) {
|
||||
if ($this->_tokens[$position] === '(') {
|
||||
$depth++;
|
||||
} elseif ($this->_tokens[$position] == ')') {
|
||||
} elseif ($this->_tokens[$position] === ')') {
|
||||
$depth--;
|
||||
}
|
||||
$position++;
|
||||
|
|
@ -403,8 +431,12 @@ class ExtractTask extends AppShell {
|
|||
$mapCount = count($map);
|
||||
$strings = $this->_getStrings($position, $mapCount);
|
||||
|
||||
if ($mapCount == count($strings)) {
|
||||
if ($mapCount === count($strings)) {
|
||||
extract(array_combine($map, $strings));
|
||||
$category = isset($category) ? $category : 6;
|
||||
$category = (int)$category;
|
||||
$categoryName = $categories[$category];
|
||||
|
||||
$domain = isset($domain) ? $domain : 'default';
|
||||
$details = array(
|
||||
'file' => $this->_file,
|
||||
|
|
@ -413,8 +445,14 @@ class ExtractTask extends AppShell {
|
|||
if (isset($plural)) {
|
||||
$details['msgid_plural'] = $plural;
|
||||
}
|
||||
$this->_addTranslation($domain, $singular, $details);
|
||||
} else {
|
||||
if (isset($context)) {
|
||||
$details['msgctxt'] = $context;
|
||||
}
|
||||
// Skip LC_TIME files as we use a special file format for them.
|
||||
if ($categoryName !== 'LC_TIME') {
|
||||
$this->_addTranslation($categoryName, $domain, $singular, $details);
|
||||
}
|
||||
} elseif (!is_array($this->_tokens[$count - 1]) || $this->_tokens[$count - 1][0] != T_FUNCTION) {
|
||||
$this->_markerError($this->_file, $line, $functionName, $count);
|
||||
}
|
||||
}
|
||||
|
|
@ -433,11 +471,29 @@ class ExtractTask extends AppShell {
|
|||
return;
|
||||
}
|
||||
|
||||
$plugins = array(null);
|
||||
if (empty($this->params['exclude-plugins'])) {
|
||||
$plugins = array_merge($plugins, App::objects('plugin', null, false));
|
||||
}
|
||||
foreach ($plugins as $plugin) {
|
||||
$this->_extractPluginValidationMessages($plugin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract validation messages from application or plugin models
|
||||
*
|
||||
* @param string $plugin Plugin name or `null` to process application models
|
||||
* @return void
|
||||
*/
|
||||
protected function _extractPluginValidationMessages($plugin = null) {
|
||||
App::uses('AppModel', 'Model');
|
||||
$plugin = null;
|
||||
if (!empty($this->params['plugin'])) {
|
||||
App::uses($this->params['plugin'] . 'AppModel', $this->params['plugin'] . '.Model');
|
||||
$plugin = $this->params['plugin'] . '.';
|
||||
if (!empty($plugin)) {
|
||||
if (!CakePlugin::loaded($plugin)) {
|
||||
return;
|
||||
}
|
||||
App::uses($plugin . 'AppModel', $plugin . '.Model');
|
||||
$plugin = $plugin . '.';
|
||||
}
|
||||
$models = App::objects($plugin . 'Model', null, false);
|
||||
|
||||
|
|
@ -472,15 +528,16 @@ class ExtractTask extends AppShell {
|
|||
* @param array $rules the set of validation rules for the field
|
||||
* @param string $file the file name where this validation rule was found
|
||||
* @param string $domain default domain to bind the validations to
|
||||
* @param string $category the translation category
|
||||
* @return void
|
||||
*/
|
||||
protected function _processValidationRules($field, $rules, $file, $domain) {
|
||||
protected function _processValidationRules($field, $rules, $file, $domain, $category = 'LC_MESSAGES') {
|
||||
if (!is_array($rules)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dims = Hash::dimensions($rules);
|
||||
if ($dims == 1 || ($dims == 2 && isset($rules['message']))) {
|
||||
if ($dims === 1 || ($dims === 2 && isset($rules['message']))) {
|
||||
$rules = array($rules);
|
||||
}
|
||||
|
||||
|
|
@ -496,11 +553,12 @@ class ExtractTask extends AppShell {
|
|||
$msgid = $rule;
|
||||
}
|
||||
if ($msgid) {
|
||||
$msgid = $this->_formatString(sprintf("'%s'", $msgid));
|
||||
$details = array(
|
||||
'file' => $file,
|
||||
'line' => 'validation for field ' . $field
|
||||
);
|
||||
$this->_addTranslation($domain, $msgid, $details);
|
||||
$this->_addTranslation($category, $domain, $msgid, $details);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -513,31 +571,47 @@ class ExtractTask extends AppShell {
|
|||
protected function _buildFiles() {
|
||||
$paths = $this->_paths;
|
||||
$paths[] = realpath(APP) . DS;
|
||||
foreach ($this->_translations as $domain => $translations) {
|
||||
foreach ($translations as $msgid => $details) {
|
||||
$plural = $details['msgid_plural'];
|
||||
$files = $details['references'];
|
||||
$occurrences = array();
|
||||
foreach ($files as $file => $lines) {
|
||||
$lines = array_unique($lines);
|
||||
$occurrences[] = $file . ':' . implode(';', $lines);
|
||||
}
|
||||
$occurrences = implode("\n#: ", $occurrences);
|
||||
$header = '#: ' . str_replace($paths, '', $occurrences) . "\n";
|
||||
|
||||
if ($plural === false) {
|
||||
$sentence = "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgstr \"\"\n\n";
|
||||
} else {
|
||||
$sentence = "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgid_plural \"{$plural}\"\n";
|
||||
$sentence .= "msgstr[0] \"\"\n";
|
||||
$sentence .= "msgstr[1] \"\"\n\n";
|
||||
}
|
||||
usort($paths, function ($a, $b) {
|
||||
return strlen($b) - strlen($a);
|
||||
});
|
||||
|
||||
$this->_store($domain, $header, $sentence);
|
||||
if ($domain != 'default' && $this->_merge) {
|
||||
$this->_store('default', $header, $sentence);
|
||||
foreach ($this->_translations as $category => $domains) {
|
||||
foreach ($domains as $domain => $translations) {
|
||||
foreach ($translations as $msgid => $contexts) {
|
||||
foreach ($contexts as $context => $details) {
|
||||
$plural = $details['msgid_plural'];
|
||||
$header = '';
|
||||
if (empty($this->params['no-location'])) {
|
||||
$files = $details['references'];
|
||||
$occurrences = array();
|
||||
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";
|
||||
}
|
||||
|
||||
$sentence = '';
|
||||
if ($context) {
|
||||
$sentence .= "msgctxt \"{$context}\"\n";
|
||||
}
|
||||
if ($plural === false) {
|
||||
$sentence .= "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgstr \"\"\n\n";
|
||||
} else {
|
||||
$sentence .= "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgid_plural \"{$plural}\"\n";
|
||||
$sentence .= "msgstr[0] \"\"\n";
|
||||
$sentence .= "msgstr[1] \"\"\n\n";
|
||||
}
|
||||
|
||||
$this->_store($category, $domain, $header, $sentence);
|
||||
if (($category !== 'LC_MESSAGES' || $domain !== 'default') && $this->_merge) {
|
||||
$this->_store('LC_MESSAGES', 'default', $header, $sentence);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -546,19 +620,23 @@ class ExtractTask extends AppShell {
|
|||
/**
|
||||
* Prepare a file to be stored
|
||||
*
|
||||
* @param string $domain
|
||||
* @param string $header
|
||||
* @param string $sentence
|
||||
* @param string $category The category
|
||||
* @param string $domain The domain
|
||||
* @param string $header The header content.
|
||||
* @param string $sentence The sentence to store.
|
||||
* @return void
|
||||
*/
|
||||
protected function _store($domain, $header, $sentence) {
|
||||
if (!isset($this->_storage[$domain])) {
|
||||
$this->_storage[$domain] = array();
|
||||
protected function _store($category, $domain, $header, $sentence) {
|
||||
if (!isset($this->_storage[$category])) {
|
||||
$this->_storage[$category] = array();
|
||||
}
|
||||
if (!isset($this->_storage[$domain][$sentence])) {
|
||||
$this->_storage[$domain][$sentence] = $header;
|
||||
if (!isset($this->_storage[$category][$domain])) {
|
||||
$this->_storage[$category][$domain] = array();
|
||||
}
|
||||
if (!isset($this->_storage[$category][$domain][$sentence])) {
|
||||
$this->_storage[$category][$domain][$sentence] = $header;
|
||||
} else {
|
||||
$this->_storage[$domain][$sentence] .= $header;
|
||||
$this->_storage[$category][$domain][$sentence] .= $header;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -572,36 +650,42 @@ class ExtractTask extends AppShell {
|
|||
if (!empty($this->params['overwrite'])) {
|
||||
$overwriteAll = true;
|
||||
}
|
||||
|
||||
foreach ($this->_storage as $domain => $sentences) {
|
||||
$output = $this->_writeHeader();
|
||||
foreach ($sentences as $sentence => $header) {
|
||||
$output .= $header . $sentence;
|
||||
}
|
||||
|
||||
$filename = $domain . '.pot';
|
||||
$File = new File($this->_output . $filename);
|
||||
$response = '';
|
||||
while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
|
||||
$this->out();
|
||||
$response = $this->in(
|
||||
__d('cake_console', 'Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename),
|
||||
array('y', 'n', 'a'),
|
||||
'y'
|
||||
);
|
||||
if (strtoupper($response) === 'N') {
|
||||
$response = '';
|
||||
while ($response == '') {
|
||||
$response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
|
||||
$File = new File($this->_output . $response);
|
||||
$filename = $response;
|
||||
}
|
||||
} elseif (strtoupper($response) === 'A') {
|
||||
$overwriteAll = true;
|
||||
foreach ($this->_storage as $category => $domains) {
|
||||
foreach ($domains as $domain => $sentences) {
|
||||
$output = $this->_writeHeader();
|
||||
foreach ($sentences as $sentence => $header) {
|
||||
$output .= $header . $sentence;
|
||||
}
|
||||
|
||||
$filename = $domain . '.pot';
|
||||
if ($category === 'LC_MESSAGES') {
|
||||
$File = new File($this->_output . $filename);
|
||||
} else {
|
||||
new Folder($this->_output . $category, true);
|
||||
$File = new File($this->_output . $category . DS . $filename);
|
||||
}
|
||||
$response = '';
|
||||
while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
|
||||
$this->out();
|
||||
$response = $this->in(
|
||||
__d('cake_console', 'Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename),
|
||||
array('y', 'n', 'a'),
|
||||
'y'
|
||||
);
|
||||
if (strtoupper($response) === 'N') {
|
||||
$response = '';
|
||||
while (!$response) {
|
||||
$response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
|
||||
$File = new File($this->_output . $response);
|
||||
$filename = $response;
|
||||
}
|
||||
} elseif (strtoupper($response) === 'A') {
|
||||
$overwriteAll = true;
|
||||
}
|
||||
}
|
||||
$File->write($output);
|
||||
$File->close();
|
||||
}
|
||||
$File->write($output);
|
||||
$File->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -611,14 +695,13 @@ class ExtractTask extends AppShell {
|
|||
* @return string Translation template header
|
||||
*/
|
||||
protected function _writeHeader() {
|
||||
$output = "# LANGUAGE translation of CakePHP Application\n";
|
||||
$output = "# LANGUAGE translation of CakePHP Application\n";
|
||||
$output .= "# Copyright YEAR NAME <EMAIL@ADDRESS>\n";
|
||||
$output .= "#\n";
|
||||
$output .= "#, fuzzy\n";
|
||||
$output .= "msgid \"\"\n";
|
||||
$output .= "msgstr \"\"\n";
|
||||
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
|
||||
$output .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
|
||||
$output .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
|
||||
$output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
|
||||
$output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
|
||||
|
|
@ -632,18 +715,18 @@ class ExtractTask extends AppShell {
|
|||
/**
|
||||
* Get the strings from the position forward
|
||||
*
|
||||
* @param integer $position Actual position on tokens array
|
||||
* @param integer $target Number of strings to extract
|
||||
* @param int &$position Actual position on tokens array
|
||||
* @param int $target Number of strings to extract
|
||||
* @return array Strings extracted
|
||||
*/
|
||||
protected function _getStrings(&$position, $target) {
|
||||
$strings = array();
|
||||
$count = count($strings);
|
||||
while ($count < $target && ($this->_tokens[$position] == ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
|
||||
while ($count < $target && ($this->_tokens[$position] === ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position][0] == T_LNUMBER)) {
|
||||
$count = count($strings);
|
||||
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position + 1] == '.') {
|
||||
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] == '.') {
|
||||
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]);
|
||||
}
|
||||
|
|
@ -652,6 +735,8 @@ class ExtractTask extends AppShell {
|
|||
$strings[] = $string;
|
||||
} elseif ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
|
||||
$strings[] = $this->_formatString($this->_tokens[$position][1]);
|
||||
} elseif ($this->_tokens[$position][0] == T_LNUMBER) {
|
||||
$strings[] = $this->_tokens[$position][1];
|
||||
}
|
||||
$position++;
|
||||
}
|
||||
|
|
@ -667,7 +752,7 @@ class ExtractTask extends AppShell {
|
|||
protected function _formatString($string) {
|
||||
$quote = substr($string, 0, 1);
|
||||
$string = substr($string, 1, -1);
|
||||
if ($quote == '"') {
|
||||
if ($quote === '"') {
|
||||
$string = stripcslashes($string);
|
||||
} else {
|
||||
$string = strtr($string, array("\\'" => "'", "\\\\" => "\\"));
|
||||
|
|
@ -680,33 +765,33 @@ class ExtractTask extends AppShell {
|
|||
* Indicate an invalid marker on a processed file
|
||||
*
|
||||
* @param string $file File where invalid marker resides
|
||||
* @param integer $line Line number
|
||||
* @param int $line Line number
|
||||
* @param string $marker Marker found
|
||||
* @param integer $count Count
|
||||
* @param int $count Count
|
||||
* @return void
|
||||
*/
|
||||
protected function _markerError($file, $line, $marker, $count) {
|
||||
$this->out(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker), true);
|
||||
$this->err(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker));
|
||||
$count += 2;
|
||||
$tokenCount = count($this->_tokens);
|
||||
$parenthesis = 1;
|
||||
|
||||
while ((($tokenCount - $count) > 0) && $parenthesis) {
|
||||
if (is_array($this->_tokens[$count])) {
|
||||
$this->out($this->_tokens[$count][1], false);
|
||||
$this->err($this->_tokens[$count][1], false);
|
||||
} else {
|
||||
$this->out($this->_tokens[$count], false);
|
||||
if ($this->_tokens[$count] == '(') {
|
||||
$this->err($this->_tokens[$count], false);
|
||||
if ($this->_tokens[$count] === '(') {
|
||||
$parenthesis++;
|
||||
}
|
||||
|
||||
if ($this->_tokens[$count] == ')') {
|
||||
if ($this->_tokens[$count] === ')') {
|
||||
$parenthesis--;
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
$this->out("\n", true);
|
||||
$this->err("\n", true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -726,29 +811,36 @@ class ExtractTask extends AppShell {
|
|||
}
|
||||
$pattern = '/' . implode('|', $exclude) . '/';
|
||||
}
|
||||
foreach ($this->_paths as $path) {
|
||||
$Folder = new Folder($path);
|
||||
foreach ($this->_paths as $i => $path) {
|
||||
$this->_paths[$i] = realpath($path) . DS;
|
||||
$Folder = new Folder($this->_paths[$i]);
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this execution is meant to extract string only from directories in folder represented by the
|
||||
* APP constant, i.e. this task is extracting strings from same application.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isExtractingApp() {
|
||||
return $this->_paths === array(APP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a given path is usable for writing.
|
||||
*
|
||||
* @param string $path Path to folder
|
||||
* @return bool true if it exists and is writable, false otherwise
|
||||
*/
|
||||
protected function _isPathUsable($path) {
|
||||
return is_dir($path) && is_writable($path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue