Merge pull request #6476 from AJ0070/fix-training-translation-keys

fix: pass two missing translation keys to the training page
This commit is contained in:
Isaac Connor authored and GitHub committed 2026-11-16 18:53:16 -05:00
commit cc1affffe6
2 files changed
+40 -1

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
<?php
// Every translation the training view JS reads must be passed by training.js.php
// and have an en_gb entry.
// Run: php tests/php/test_lang_training_keys.php
$root = dirname(__DIR__, 2);
$SLANG = array();
include $root.'/web/lang/en_gb.php';
$phpSrc = file_get_contents($root.'/web/skins/classic/views/js/training.js.php');
$jsSrc = file_get_contents($root.'/web/skins/classic/views/js/training.js');
if (!preg_match('/\$translationKeys = \[(.*?)\];/s', $phpSrc, $m)) {
fwrite(STDERR, "FAIL: cannot find \$translationKeys\n");
exit(1);
}
preg_match_all("/'(\w+)'/", $m[1], $mm);
$passed = array_flip($mm[1]);
// JS reads through this.translations / self.translations, or the local alias `t`
// (const t = this.translations).
preg_match_all('/\b(?:translations|t)\.(Training\w+|[A-Z]\w+)\b/', $jsSrc, $rm);
$read = array_unique($rm[1]);
sort($read);
$fail = 0;
foreach ($read as $k) {
if (!isset($passed[$k])) {
echo "FAIL: training.js reads translations.$k but training.js.php does not pass it\n";
$fail++;
}
}
foreach (array('TrainingSavedLoaded', 'TrainingEditAnnotation') as $k) {
if (!isset($SLANG[$k])) {
echo "FAIL: $k missing from en_gb.php\n";
$fail++;
}
}
if ($fail) exit(1);
echo "OK: ".count($read)." keys read by training.js are all passed\n";
+1 -1
View File
@@ -23,7 +23,7 @@ const trainingTranslations = <?php
'TrainingSelectBoxFirst', 'TrainingTotalClasses', 'TrainingTotalImages',
'TrainingUnsaved', 'AcceptDetection', 'ConfirmDeleteTrainingData',
'DrawBox', 'Frame', 'GoToFrame', 'ImagesPerClass', 'NewLabel',
'NoDetectionData', 'SelectLabel',
'NoDetectionData', 'SelectLabel', 'TrainingSavedLoaded', 'TrainingEditAnnotation',
];
$t = [];
foreach ($translationKeys as $k) $t[$k] = translate($k);