From e4c089f556f72a0c1b502c72e66ef4e0fc972198 Mon Sep 17 00:00:00 2001 From: PGBarrow Date: Mon, 11 May 2015 22:41:55 -0700 Subject: [PATCH] Fix issue #6542 --- src/Shell/Task/ExtractTask.php | 78 ++++++++++++++++------------------ 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/src/Shell/Task/ExtractTask.php b/src/Shell/Task/ExtractTask.php index aacaa94f58d..1400da40113 100644 --- a/src/Shell/Task/ExtractTask.php +++ b/src/Shell/Task/ExtractTask.php @@ -243,31 +243,26 @@ public function main() * * @param string $domain The domain * @param string $msgid The message string - * @param array $details The file and line references + * @param array $details Context and plural form if any, file and line references * @return void */ protected function _addTranslation($domain, $msgid, $details = []) { - if (empty($this->_translations[$domain][$msgid])) { - $this->_translations[$domain][$msgid] = [ - 'msgid_plural' => false, - 'msgctxt' => '' + $context = isset($details['msgctxt']) ? $details['msgctxt'] : ""; + + if (empty($this->_translations[$domain][$msgid][$context])) { + $this->_translations[$domain][$msgid][$context] = [ + 'msgid_plural' => false ]; } if (isset($details['msgid_plural'])) { - $this->_translations[$domain][$msgid]['msgid_plural'] = $details['msgid_plural']; - } - if (isset($details['msgctxt'])) { - $this->_translations[$domain][$msgid]['msgctxt'] = $details['msgctxt']; + $this->_translations[$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; + $line = isset($details['line']) ? $details['line'] : 0; + $this->_translations[$domain][$msgid][$context]['references'][$details['file']][] = $line; } } @@ -449,35 +444,36 @@ 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']; - $context = $details['msgctxt']; - $files = $details['references']; - $occurrences = []; - 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 = []; + 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($domain, $header, $sentence); - if ($domain !== 'default' && $this->_merge) { - $this->_store('default', $header, $sentence); + $this->_store($domain, $header, $sentence); + if ($domain !== 'default' && $this->_merge) { + $this->_store('default', $header, $sentence); + } } } }