<?php

/**
 * Remove untranslated keys (where key === value) from all language files
 * This prepares them for AI translation
 */

$locales = ['nl', 'de', 'es', 'fr'];

echo "Preparing files for translation...\n\n";

foreach ($locales as $locale) {
    $file = "resources/lang/{$locale}.json";
    $data = json_decode(file_get_contents($file), true);
    $before = count($data);

    // Remove entries where key === value (untranslated)
    $filtered = array_filter($data, function($value, $key) {
        return $value !== $key;
    }, ARRAY_FILTER_USE_BOTH);

    $after = count($filtered);
    $removed = $before - $after;

    ksort($filtered);
    file_put_contents($file, json_encode($filtered, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL);

    echo "{$locale}.json: Removed {$removed} untranslated keys ({$before} → {$after} keys)\n";
}

echo "\nFiles prepared! Now ready for translation.\n";
echo "Next: Run translation for each language\n";
