feat: add automated scripts and JSON datasets for managing and translating site content

This commit is contained in:
Ümit Tunç
2026-05-20 00:03:07 +03:00
parent 29ddc24602
commit 19c9202fc1
14 changed files with 9741 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
use App\Models\Translation;
$trTranslations = Translation::where('language_code', 'tr')->get();
$untranslated = [];
function hasTurkish($text) {
if (empty($text) || is_numeric($text)) return false;
// Check if contains Turkish letters or is generally Turkish words
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)/i', $text);
}
foreach ($trTranslations as $t) {
$en = Translation::where('translatable_type', $t->translatable_type)
->where('translatable_id', $t->translatable_id)
->where('field_name', $t->field_name)
->where('language_code', 'en')
->first();
$enVal = $en ? $en->field_value : null;
$trVal = $t->field_value;
$needsTranslation = false;
if (empty($enVal)) {
$needsTranslation = true;
} else if ($enVal === $trVal && hasTurkish($trVal)) {
$needsTranslation = true;
}
if ($needsTranslation) {
$untranslated[] = [
'type' => $t->translatable_type,
'id' => $t->translatable_id,
'field' => $t->field_name,
'tr' => $trVal,
'en' => $enVal
];
}
}
file_put_contents(__DIR__.'/untranslated_dynamic.json', json_encode($untranslated, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
echo "Found " . count($untranslated) . " untranslated dynamic model translations. Written to untranslated_dynamic.json.\n";