]> _ Git - cubist_locale.git/commitdiff
wip #4623 @0:15
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Jul 2021 14:38:27 +0000 (16:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Jul 2021 14:38:27 +0000 (16:38 +0200)
src/Translate.php

index b3ed68bacd48d645b5c4e8bdc945021c7336eb29..aa81e94b3e8552f1f878f0eb3ceacb787000daa6 100644 (file)
@@ -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)