Internal: Add .html.twig support to gettext migration script - refs BT#21777

pull/5586/head
christianbeeznst 1 year ago
parent f7af3b83aa
commit 8ff5955d32
  1. 16
      public/main/inc/lib/fileManage.lib.php
  2. 10
      tests/scripts/switch_files_to_gettext.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)) {
foreach ($extensionsArray as $extension) {
if (substr($item, -strlen($extension)) == $extension) {
$files[] = $base_path.$item;
break;
}
}
}
}

@ -32,7 +32,8 @@ echo count($defined_terms)." terms were found in language files".PHP_EOL;
// 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 @@ foreach ($files as $file) {
$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 @@ foreach ($files as $file) {
$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++;
}
}

Loading…
Cancel
Save