mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-05-28 02:13:31 +00:00
Fix Extract task to correctly extract messages with context
This commit is contained in:
parent
02ca7f5fcb
commit
3ae61e9e16
3 changed files with 59 additions and 41 deletions
lib/Cake/Console/Command/Task
|
@ -70,7 +70,7 @@ class ExtractTask extends AppShell {
|
|||
protected $_tokens = array();
|
||||
|
||||
/**
|
||||
* Extracted strings indexed by category and domain.
|
||||
* Extracted strings indexed by category, domain, msgid and context.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -249,26 +249,26 @@ class ExtractTask extends AppShell {
|
|||
* @return void
|
||||
*/
|
||||
protected function _addTranslation($category, $domain, $msgid, $details = array()) {
|
||||
if (empty($this->_translations[$category][$domain][$msgid])) {
|
||||
$this->_translations[$category][$domain][$msgid] = 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,
|
||||
'msgctxt' => ''
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($details['msgid_plural'])) {
|
||||
$this->_translations[$category][$domain][$msgid]['msgid_plural'] = $details['msgid_plural'];
|
||||
$this->_translations[$category][$domain][$msgid][$context]['msgid_plural'] = $details['msgid_plural'];
|
||||
}
|
||||
if (isset($details['msgctxt'])) {
|
||||
$this->_translations[$category][$domain][$msgid]['msgctxt'] = $details['msgctxt'];
|
||||
}
|
||||
|
||||
if (isset($details['file'])) {
|
||||
$line = 0;
|
||||
if (isset($details['line'])) {
|
||||
$line = $details['line'];
|
||||
}
|
||||
$this->_translations[$category][$domain][$msgid]['references'][$details['file']][] = $line;
|
||||
$this->_translations[$category][$domain][$msgid][$context]['references'][$details['file']][] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -565,35 +565,36 @@ class ExtractTask extends AppShell {
|
|||
$paths[] = realpath(APP) . DS;
|
||||
foreach ($this->_translations as $category => $domains) {
|
||||
foreach ($domains as $domain => $translations) {
|
||||
foreach ($translations as $msgid => $details) {
|
||||
$plural = $details['msgid_plural'];
|
||||
$context = $details['msgctxt'];
|
||||
$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";
|
||||
foreach ($translations as $msgid => $contexts) {
|
||||
foreach ($contexts as $context => $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(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";
|
||||
}
|
||||
$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);
|
||||
$this->_store($category, $domain, $header, $sentence);
|
||||
if (($category !== 'LC_MESSAGES' || $domain !== 'default') && $this->_merge) {
|
||||
$this->_store('LC_MESSAGES', 'default', $header, $sentence);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue