89 lines
2.9 KiB
PHP
89 lines
2.9 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;
|
|
use App\Models\Translation;
|
|
use App\Models\Language;
|
|
|
|
// 1. Static translations
|
|
$staticResult = [];
|
|
$trPath = __DIR__.'/lang/tr';
|
|
$enPath = __DIR__.'/lang/en';
|
|
|
|
if (is_dir($trPath)) {
|
|
$files = scandir($trPath);
|
|
foreach ($files as $file) {
|
|
if ($file === '.' || $file === '..') continue;
|
|
if (pathinfo($file, PATHINFO_EXTENSION) !== 'php') continue;
|
|
|
|
$trData = include($trPath.'/'.$file);
|
|
$enData = [];
|
|
if (file_exists($enPath.'/'.$file)) {
|
|
$enData = include($enPath.'/'.$file);
|
|
}
|
|
|
|
if (is_array($trData)) {
|
|
foreach ($trData as $key => $trValue) {
|
|
$enValue = $enData[$key] ?? '';
|
|
// Let's gather all keys so we can manually review if the English translation is correct or needs translation
|
|
$staticResult[$file][$key] = [
|
|
'tr' => $trValue,
|
|
'en' => $enValue
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. Database Model Translations (translations table)
|
|
// Let's find all active translations for TR
|
|
$trDbTranslations = Translation::where('language_code', 'tr')->get();
|
|
$dynamicResult = [];
|
|
|
|
foreach ($trDbTranslations as $t) {
|
|
$enTranslation = Translation::where('translatable_type', $t->translatable_type)
|
|
->where('translatable_id', $t->translatable_id)
|
|
->where('field_name', $t->field_name)
|
|
->where('language_code', 'en')
|
|
->first();
|
|
|
|
$enValue = $enTranslation ? $enTranslation->field_value : '';
|
|
|
|
$dynamicResult[] = [
|
|
'translatable_type' => $t->translatable_type,
|
|
'translatable_id' => $t->translatable_id,
|
|
'field_name' => $t->field_name,
|
|
'tr' => $t->field_value,
|
|
'en' => $enValue
|
|
];
|
|
}
|
|
|
|
// 3. Site Translations (site_translations table)
|
|
$siteResult = [];
|
|
foreach (SiteTranslation::all() as $st) {
|
|
$translations = $st->translations ?? [];
|
|
$enValue = $translations['en'] ?? '';
|
|
|
|
// We capture both Turkish and English so we can ensure perfect translation
|
|
$siteResult[] = [
|
|
'id' => $st->id,
|
|
'key' => $st->key,
|
|
'tr' => $translations['tr'] ?? $st->key, // if tr is missing, default to key
|
|
'en' => $enValue
|
|
];
|
|
}
|
|
|
|
$output = [
|
|
'static' => $staticResult,
|
|
'dynamic' => $dynamicResult,
|
|
'site' => $siteResult
|
|
];
|
|
|
|
file_put_contents(__DIR__.'/to_translate.json', json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
echo "Successfully exported translation assets to to_translate.json!\n";
|
|
echo "Static keys: " . count($staticResult, COUNT_RECURSIVE) . "\n";
|
|
echo "Dynamic keys: " . count($dynamicResult) . "\n";
|
|
echo "Site keys: " . count($siteResult) . "\n";
|