Skip to content

Commit

Permalink
Internal: Add .html.twig support to gettext migration script - refs B…
Browse files Browse the repository at this point in the history
…T#21777
  • Loading branch information
christianbeeznest committed Jun 12, 2024
1 parent f7af3b8 commit 8ff5955
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
18 changes: 7 additions & 11 deletions public/main/inc/lib/fileManage.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/scripts/switch_files_to_gettext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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++;
}
}
Expand Down

0 comments on commit 8ff5955

Please sign in to comment.