From 3a1fc7e3fb1c4dac8d570ae118de2e8580d957c2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 28 Jul 2021 16:38:27 +0200 Subject: [PATCH] wip #4623 @0:15 --- src/Translate.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Translate.php b/src/Translate.php index b3ed68b..aa81e94 100644 --- a/src/Translate.php +++ b/src/Translate.php @@ -18,9 +18,13 @@ class Translate } - public function addPath($path) + public function addPath($path, $sectionLabel = null) { - $this->_paths[] = $path; + if (null === $sectionLabel) { + $this->_paths[] = $path; + } else { + $this->_paths[$sectionLabel] = $path; + } } public function clearPaths() @@ -44,23 +48,25 @@ class Translate $this->_extensions = array_unique($this->_extensions); $this->_paths = array_unique($this->_paths); - foreach ($this->_paths as $path) { + foreach ($this->_paths as $sectionLabel => $path) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach ($iterator as $p) { if ($p->isFile()) { - $this->_parseFile($p); + $this->_parseFile($p, $sectionLabel); } } } - $this->_toTranslate = array_unique($this->_toTranslate); } - protected function _parseFile(SplFileInfo $file) + protected function _parseFile(SplFileInfo $file, $sectionLabel) { if (!in_array($file->getExtension(), $this->_extensions)) { return; } - $this->_toTranslate = array_merge($this->_toTranslate, self::extractTextsToTranslate($file)); + if (!isset($this->_toTranslate[$sectionLabel])) { + $this->_toTranslate[$sectionLabel] = []; + } + $this->_toTranslate[$sectionLabel] = array_merge($this->_toTranslate[$sectionLabel], self::extractTextsToTranslate($file)); } public static function extractTextsToTranslate(SplFileInfo $file) -- 2.39.5