[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX][REF] Devtools - Update English Strings: Fix script failure due to...
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69fd88efa10dd_381900b49591b@gitlab-sidekiq-low-urgency-cpu-bound-v2-6746cb7cfd-bp6ln.mail> |
Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
b60d1c2b by ushindi bienvenu at 2026-05-08T06:39:15+00:00
[FIX][REF] Devtools - Update English Strings: Fix script failure due to missing dependencies + refactor to preserve formatting
---
* [FIX][REF] Fix script failure due to missing dependencies and preserve formatting
See merge request tikiwiki/tiki!10085
- - - - -
3 changed files:
- doc/devtools/update_english_strings.php
- + lib/language/LangStringEscaper.php
- lib/language/Language.php
Changes:
=====================================
doc/devtools/update_english_strings.php
=====================================
@@ -12,6 +12,7 @@
// Also see: doc/devtools/mass_wording_corrections.pl
//
+use Tiki\Lib\Language\LangStringEscaper;
if ($argc < 3) {
die("\nUsage: php doc/devtools/update_english_strings.php \"oldString\" \"newString\"\n\n");
@@ -19,30 +20,42 @@ if ($argc < 3) {
set_include_path(get_include_path() . PATH_SEPARATOR . '../../');
-require_once('lib/language/Language.php');
+require_once('lib/language/LangStringEscaper.php');
-$oldString = Language::addPhpSlashes($argv[1]);
-$newString = Language::addPhpSlashes($argv[2]);
+$oldString = LangStringEscaper::addPhpSlashes($argv[1]);
+$newString = LangStringEscaper::addPhpSlashes($argv[2]);
-$dirHandle = opendir('lang/');
+$totalFiles = 0;
+$updatedFiles = 0;
-while (($dir = readdir($dirHandle)) !== false) {
- if ($dir == '.' || $dir == '..') {
+$iterator = new FilesystemIterator('lang/', FilesystemIterator::SKIP_DOTS);
+
+echo "Processing languages: ";
+
+foreach ($iterator as $dirInfo) {
+ if (! $dirInfo->isDir()) {
continue;
}
- $dir = 'lang/' . $dir;
- if (is_dir($dir)) {
- $filePath = $dir . '/language.php';
-
- if (! file_exists($filePath)) {
- continue;
- }
+ $filePath = $dirInfo->getPathname() . '/language.php';
- $langFile = file_get_contents($filePath);
- $fileHandle = fopen($filePath, 'w');
- $langFile = str_replace("\"$oldString\" => ", "\n\"$newString\" => ", $langFile);
- fwrite($fileHandle, $langFile);
- fclose($fileHandle);
+ if (! file_exists($filePath)) {
+ continue;
}
+
+ $totalFiles++;
+
+ $content = file_get_contents($filePath);
+
+ $pattern = '~^([ \t]*(?://[ \t]*)?)"' . preg_quote($oldString, '~') . '"([ \t]*=>[ \t]*)~m';
+ $replacement = '$1"' . $newString . '"$2';
+
+ $updatedContent = preg_replace($pattern, $replacement, $content, -1, $replacements);
+ file_put_contents($filePath, $updatedContent);
+ $updatedFiles++;
+ echo ".";
}
+
+echo "\n\nSummary\n";
+printf(" Files checked: %d\n", $totalFiles);
+printf(" Files updated: %d\n", $updatedFiles);
=====================================
lib/language/LangStringEscaper.php
=====================================
@@ -0,0 +1,29 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+//this script may only be included - so its better to die if called directly.
+
+namespace Tiki\Lib\Language;
+
+if (str_contains($_SERVER['SCRIPT_NAME'], basename(__FILE__))) {
+ header('location: index.php');
+ exit;
+}
+final class LangStringEscaper
+{
+ public static function addPhpSlashes(string $string): string
+ {
+ $addPHPslashes = [
+ "\n" => '\n',
+ "\r" => '\r',
+ "\t" => '\t',
+ '\\' => '\\\\',
+ '$' => '\$',
+ '"' => '\"'
+ ];
+ return strtr($string, $addPHPslashes);
+ }
+}
=====================================
lib/language/Language.php
=====================================
@@ -10,6 +10,7 @@ if (str_contains($_SERVER['SCRIPT_NAME'], basename(__FILE__))) {
exit;
}
+use Tiki\Lib\Language\LangStringEscaper;
use Tiki\Sections;
/**
@@ -70,20 +71,12 @@ class Language extends TikiDb_Bridge
* since they should not apper in english strings.
*
* @param string $string
+ *
* @return string modified string;
*/
- public static function addPhpSlashes($string)
+ public static function addPhpSlashes(string $string): string
{
- $addPHPslashes = [
- "\n" => '\n',
- "\r" => '\r',
- "\t" => '\t',
- '\\' => '\\\\',
- '$' => '\$',
- '"' => '\"'
- ];
-
- return strtr($string, $addPHPslashes);
+ return LangStringEscaper::addPhpSlashes($string);
}
/**
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/b60d1c2b40b50ea0e01661da596b6ca4c5db60a0
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/b60d1c2b40b50ea0e01661da596b6ca4c5db60a0
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs