Files
citrus/find_site_translations_needing_en.php
T

46 lines
1.7 KiB
PHP

<?php
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
use App\Models\SiteTranslation;
$siteTranslations = SiteTranslation::all();
$needingTranslation = [];
function hasTurkish($text) {
if (empty($text) || is_numeric($text)) return false;
return preg_match('/[ğüşıöçĞÜŞİÖÇ]/u', $text) || preg_match('/(ve|bir|bu|ne|de|da|icin|ile|o|en|ki|ile|ise|mi|mu|sonra|olarak|gibi|daha|hakkinda|giris|kayit|sunlar|bizim|hizmet|iletisim|hakkimizda)/i', $text);
}
foreach ($siteTranslations as $st) {
$translations = $st->translations ?? [];
$enVal = isset($translations['en']) ? trim($translations['en']) : '';
$trVal = isset($translations['tr']) ? trim($translations['tr']) : '';
$keyVal = trim($st->key);
// We check if either the key or the TR translation has Turkish and the EN translation is missing
$sourceVal = !empty($trVal) ? $trVal : $keyVal;
$needsTranslation = false;
if (empty($enVal)) {
if (hasTurkish($sourceVal)) {
$needsTranslation = true;
}
} else if ($enVal === $sourceVal && hasTurkish($sourceVal)) {
$needsTranslation = true;
}
if ($needsTranslation) {
$needingTranslation[] = [
'id' => $st->id,
'key' => $st->key,
'tr' => $sourceVal,
'en' => $enVal
];
}
}
file_put_contents(__DIR__.'/untranslated_site.json', json_encode($needingTranslation, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
echo "Found " . count($needingTranslation) . " untranslated site translations. Written to untranslated_site.json.\n";