From 1465b79d42c4260530962831236d8e62523ba3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Krolow?= Date: Sun, 5 Feb 2012 21:38:08 -0200 Subject: [PATCH] improve the extract to know when there is the same string inside one plural tickect #2538 --- lib/Cake/Console/Command/Task/ExtractTask.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 08f00ad6592..9016ef0c717 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -74,6 +74,13 @@ class ExtractTask extends Shell { */ protected $_strings = array(); +/** + * Extracted sigular strings + * + * @var array + */ + protected $_singulars = array(); + /** * Destination path * @@ -322,6 +329,12 @@ protected function _parse($functionName, $map) { if ($mapCount == count($strings)) { extract(array_combine($map, $strings)); $domain = isset($domain) ? $domain : 'default'; + if (isset($plural)) { + if (!isset($_this->_singulars)) { + $this->_singulars[$domain] = array(); + } + array_push($this->_singulars[$domain], $singular); + } $string = isset($plural) ? $singular . "\0" . $plural : $singular; $this->_strings[$domain][$string][$this->_file][] = $line; } else { @@ -422,7 +435,10 @@ protected function _buildFiles() { $header = '#: ' . str_replace($this->_paths, '', $occurrences) . "\n"; if (strpos($string, "\0") === false) { - $sentence = "msgid \"{$string}\"\n"; + if (isset($this->_singulars[$domain]) && in_array($string, $this->_singulars[$domain])) { + continue; + } + $sentence = "msgid \"{$string}\"\n"; $sentence .= "msgstr \"\"\n\n"; } else { list($singular, $plural) = explode("\0", $string);