Files
timebank-cc-public/references/translations/replace-tag-with-label.php
Ronald Huynen 2547717edb Initial commit
2026-03-23 21:37:59 +01:00

54 lines
1.6 KiB
PHP

<?php
/**
* Replace 'tag'/'tags' with 'label'/'labels' in Dutch translation values
* Only modifies the translation values (right side), not the keys (left side)
*/
$file = "resources/lang/nl.json";
$translations = json_decode(file_get_contents($file), true);
// Create backup
copy($file, "{$file}.backup");
$replacements = 0;
$modified = [];
foreach ($translations as $key => $value) {
$original = $value;
// Replace all variations preserving case
// Order matters: do plural before singular to avoid double replacements
$value = str_replace('Tags', 'Labels', $value);
$value = str_replace('tags', 'labels', $value);
$value = str_replace('Tag', 'Label', $value);
$value = str_replace('tag', 'label', $value);
if ($original !== $value) {
$replacements++;
$modified[$key] = [
'before' => $original,
'after' => $value
];
$translations[$key] = $value;
}
}
// Save updated translations
file_put_contents($file, json_encode($translations, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL);
echo "Replaced 'tag'/'tags' with 'label'/'labels' in nl.json:\n";
echo " - Backup saved to nl.json.backup\n";
echo " - Made {$replacements} replacements in {$replacements} translation values\n\n";
if ($replacements > 0) {
echo "Modified translations:\n";
echo str_repeat('=', 80) . "\n";
foreach ($modified as $key => $changes) {
echo "Key: {$key}\n";
echo " Before: {$changes['before']}\n";
echo " After: {$changes['after']}\n";
echo str_repeat('-', 80) . "\n";
}
}