From c7cf3e8da99e38c2884bbca01607ebc7468c4ea6 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 17 Jan 2024 19:22:17 +0100 Subject: [PATCH] wip #6634 @1 --- app/Fluidbook/Packager/WindowsInstaller.php | 4 +++- app/Models/Base/ToolboxBaseTranslate.php | 26 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/Fluidbook/Packager/WindowsInstaller.php b/app/Fluidbook/Packager/WindowsInstaller.php index 85cdf1931..bb43b7116 100644 --- a/app/Fluidbook/Packager/WindowsInstaller.php +++ b/app/Fluidbook/Packager/WindowsInstaller.php @@ -26,7 +26,9 @@ class WindowsInstaller extends WindowsZIP { $winvdir = $this->getFinalPackageDir(); - $locale = $this->book->getDefaultTranslations()['nsis']; + $trans=$this->book->getDefaultTranslations(); + + $locale = $trans['nsis']; if ($locale === 'Arabic') { $locale = 'English'; } diff --git a/app/Models/Base/ToolboxBaseTranslate.php b/app/Models/Base/ToolboxBaseTranslate.php index cfc6f5c39..f60ff9a89 100644 --- a/app/Models/Base/ToolboxBaseTranslate.php +++ b/app/Models/Base/ToolboxBaseTranslate.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Admin\Operations\ContentTranslate\ExcelImportOperation; use Cubist\Backpack\Facades\App; use Cubist\Backpack\Magic\Models\Translate; use Cubist\Util\Files\Files; +use Cubist\Util\Json; use Cubist\Util\PHP; use Illuminate\Support\Facades\Cache; @@ -60,14 +61,13 @@ class ToolboxBaseTranslate extends Translate public static function getAllTranslations($force = true) { if (null === static::$_allTranslations) { - - $cacheKey = static::_getCacheKey(); - if ($force) { + if (true || $force) { Cache::forget($cacheKey); } static::$_allTranslations = Cache::remember($cacheKey, 3600, function () { start_measure('Get all ' . static::$_name . ' translations !'); + /** @var ToolboxBaseTranslate $t */ $t = static::find(1); try { $json = json_decode($t->getRawOriginal('content_translatable'), true, 512, JSON_THROW_ON_ERROR); @@ -82,6 +82,26 @@ class ToolboxBaseTranslate extends Translate $res[$code][$k] = ['str' => static::keyToStr($k), 'translation' => $v]; } } + + foreach ($t->getAttributes() as $k => $item) { + if (in_array($k, ['content_translatable', 'id', 'deleted_at', 'created_at', 'updated_at', 'created_ok'])) { + continue; + } + $v = $item; + if (Json::isJson($v)) { + $v = json_decode($v, true); + } + if (is_scalar($v)) { + continue; + } + foreach ($v as $locale => $str) { + if (isset($res[$locale])) { + $res[$locale][$k] = ['str' => $k, 'translation' => $str]; + } + } + + } + stop_measure('Get all ' . static::$_name . ' translations !'); return $res; -- 2.39.5