From 8ff5955d3296e3094fd98b5b2bfbbe14e21d9070 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Wed, 12 Jun 2024 15:46:05 -0500 Subject: [PATCH] Internal: Add .html.twig support to gettext migration script - refs BT#21777 --- public/main/inc/lib/fileManage.lib.php | 18 +++++++----------- tests/scripts/switch_files_to_gettext.php | 10 +++++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/public/main/inc/lib/fileManage.lib.php b/public/main/inc/lib/fileManage.lib.php index 63b26a9d61e..9fd3819180b 100644 --- a/public/main/inc/lib/fileManage.lib.php +++ b/public/main/inc/lib/fileManage.lib.php @@ -74,17 +74,12 @@ function copyDirTo($source, $destination, $move = true) /** * Get a list of all PHP (.php) files in a given directory. Includes .tpl files. - * - * @param string $base_path The base path in which to find the corresponding files - * @param bool $includeStatic Include static .html, .htm and .css files - * - * @return array */ -function getAllPhpFiles($base_path, $includeStatic = false) +function getAllPhpFiles(string $base_path, bool $includeStatic = false): array { $list = scandir($base_path); $files = []; - $extensionsArray = ['.php', '.tpl']; + $extensionsArray = ['.php', '.tpl', '.html.twig']; if ($includeStatic) { $extensionsArray[] = 'html'; $extensionsArray[] = '.htm'; @@ -101,10 +96,11 @@ function getAllPhpFiles($base_path, $includeStatic = false) if (is_dir($base_path.$item)) { $files = array_merge($files, getAllPhpFiles($base_path.$item.'/', $includeStatic)); } else { - //only analyse php files - $sub = substr($item, -4); - if (in_array($sub, $extensionsArray)) { - $files[] = $base_path.$item; + foreach ($extensionsArray as $extension) { + if (substr($item, -strlen($extension)) == $extension) { + $files[] = $base_path.$item; + break; + } } } } diff --git a/tests/scripts/switch_files_to_gettext.php b/tests/scripts/switch_files_to_gettext.php index fdef9768f0e..f80bc2f5077 100644 --- a/tests/scripts/switch_files_to_gettext.php +++ b/tests/scripts/switch_files_to_gettext.php @@ -32,7 +32,8 @@ // time and memory) $usedTerms = []; $l = strlen(api_get_path(SYS_PATH)); -$files = getAllPhpFiles(api_get_path(SYS_PATH)); +$pathfile = api_get_path(SYS_PATH)."main/template/default/gamification/"; +$files = getAllPhpFiles($pathfile); $rootLength = strlen(api_get_path(SYS_PATH)); $countFiles = 0; $countReplaces = 0; @@ -59,13 +60,12 @@ $translation = $terms[$term]; $quotedTerm = $myTerms[1][0]; //echo "Would do sed -i \"s#$quotedTerm#'$translation'#g\" $file here\n"; - system("sed -i \"s#$term#'$translation'#g\" $file"); + system("sed -i \"s#$quotedTerm#'$translation'#g\" $file"); $countReplaces++; } } } else { - $res = 0; - $res = preg_match_all('/\{\s*([\'"](\\w*)[\'"])\s*\|get_lang\}/m', $line, $myTerms); + $res = preg_match_all('/\{\{\s*([\'"](\\w*)[\'"])\s*\|get_lang\}\}/m', $line, $myTerms); if ($res > 0) { foreach ($myTerms[2] as $term) { echo "Found term $term".PHP_EOL; @@ -76,7 +76,7 @@ $translation = $terms[$term]; $quotedTerm = $myTerms[1][0]; //echo "Would do sed -i \"s#$quotedTerm#'$translation'#g\" $file here\n"; - system("sed -i \"s#$term#'$translation'#g\" $file"); + system("sed -i \"s#$quotedTerm#'$translation'#g\" $file"); $countReplaces++; } }