]> _ Git - cubist_locale.git/commitdiff
wip #6462 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 8 Nov 2023 15:08:50 +0000 (16:08 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 8 Nov 2023 15:08:50 +0000 (16:08 +0100)
src/Translate.php

index f583e2d82d6401530f36836fcea8bda79c495188..52b0c622fda80424f1dcc9a3d927c74542f47c1e 100644 (file)
@@ -13,7 +13,7 @@ class Translate
 
     protected $_paths = [];
     protected $_extensions = ['php', 'phtml'];
-    protected $_exclude = ['^\.git'];
+    protected $_exclude = ['\/\.git\/'];
     protected $_toTranslate = [];
     protected static $_parsed = [];
 
@@ -67,8 +67,19 @@ class Translate
                 start_measure('Parse path for translations ' . $path);
                 $res = [];
                 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
+                /** @var SplFileInfo $p */
                 foreach ($iterator as $p) {
                     if ($p->isFile() && in_array($p->getExtension(), $this->_extensions)) {
+                        $excluded = false;
+                        foreach ($this->_exclude as $exclude) {
+                            if (preg_match('/' . $exclude . '/', $p->getPathname())) {
+                                $excluded = true;
+                                break;
+                            }
+                        }
+                        if (!$excluded) {
+                            continue;
+                        }
                         $res = array_merge($res, static::extractTextsToTranslate($p));
                     }
                 }
@@ -88,7 +99,7 @@ class Translate
             return [];
         }
         $cacheKey = 'totranslate_' . Files::hashFileAttributes($file->getPathname());
-        return Cache::remember($cacheKey,3600, function () use ($file) {
+        return Cache::remember($cacheKey, 3600, function () use ($file) {
             $c = file_get_contents($file);
             $res = [];
             // @link https://regex101.com/r/uD0eT1/4