From ddce8ee0e39c09ab185323b380cb4e023fc2e90e Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 6 Sep 2023 17:38:49 +0200 Subject: [PATCH] wip #6248 @1 --- .../ContentTranslate/ExcelExportOperation.php | 13 ++++++------- .../ContentTranslate/ExcelImportOperation.php | 6 ++++-- app/Models/Base/ToolboxContentTranslate.php | 4 +++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelExportOperation.php b/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelExportOperation.php index 66697c457..50532466d 100644 --- a/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelExportOperation.php +++ b/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelExportOperation.php @@ -20,11 +20,10 @@ trait ExcelExportOperation protected function excelExport($locale) { - $class = get_class($this); + $class = get_class($this->getModelInstance()); - $alldata = json_decode($class::find(1)->getRawOriginal('content_translatable'), true); + $alldata = $class::getAllTranslations(); - $t = $class::find(1); if ($locale === 'en') { $ref = 'fr'; } else { @@ -54,11 +53,11 @@ trait ExcelExportOperation } $row = 2; + foreach ($tref as $k => $v) { - $str = base64_decode(explode('t_', $k)[1]); $worksheet->setCellValueByColumnAndRow(1, $row, $k); - $worksheet->setCellValueByColumnAndRow(2, $row, $str); - $worksheet->setCellValueByColumnAndRow(3, $row, $v); + $worksheet->setCellValueByColumnAndRow(2, $row, $v['str']); + $worksheet->setCellValueByColumnAndRow(3, $row, $v['translation'] ?? $v['str']); for ($i = 1; $i <= 3; $i++) { $style = $worksheet->getStyleByColumnAndRow($i, $row); @@ -68,7 +67,7 @@ trait ExcelExportOperation $style = $worksheet->getStyleByColumnAndRow($i, $row); $style->getAlignment()->setWrapText(true); } - $worksheet->setCellValueByColumnAndRow(4, $row, $tr[$k] ?? ''); + $worksheet->setCellValueByColumnAndRow(4, $row, $tr[$k]['translation'] ?? ''); $row++; } diff --git a/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelImportOperation.php b/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelImportOperation.php index 0f37129ba..bb0cf55f7 100644 --- a/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelImportOperation.php +++ b/app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelImportOperation.php @@ -34,7 +34,9 @@ trait ExcelImportOperation $xls = $reader->load($file['tmp_name']); $sheet = $xls->getActiveSheet(); - $existingTranslation = FluidbookTranslate::getFluidbookTranslation($locale); + $class = get_class($this->getModelInstance()); + + $existingTranslation = $class::getLocaleTranslations($locale); $translations = []; @@ -65,7 +67,7 @@ trait ExcelImportOperation } elseif (!$updated) { Alert::warning('No translation were updated')->flash(); } else { - FluidbookTranslate::updateFluidbookTranslation($locale, $translations); + $class::updateTranslation($locale, $translations); Alert::success('' . $updated . ' translations were updated (' . $count . ' total)')->flash(); } return redirect($this->crud->route . '/1/edit/?locale=' . $locale); diff --git a/app/Models/Base/ToolboxContentTranslate.php b/app/Models/Base/ToolboxContentTranslate.php index cc6ac846d..1e041b2f5 100644 --- a/app/Models/Base/ToolboxContentTranslate.php +++ b/app/Models/Base/ToolboxContentTranslate.php @@ -48,7 +48,9 @@ class ToolboxContentTranslate extends Translate public function getExtensions() { - return parent::getExtensions() + ['js']; + $res = parent::getExtensions(); + $res[] = 'js'; + return $res; } protected static function _getCacheKey() -- 2.39.5