]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6248 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 15:38:49 +0000 (17:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 15:38:49 +0000 (17:38 +0200)
app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelExportOperation.php
app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelImportOperation.php
app/Models/Base/ToolboxContentTranslate.php

index 66697c457dd04d1c2b49be908bf9e9d70d653f37..50532466d14296e27504e90d271129c7efbb5e30 100644 (file)
@@ -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++;
         }
 
index 0f37129ba07fd9cd95836d2e8f48ac0a122e90e8..bb0cf55f73eefb9f771992fdd21188faef86c266 100644 (file)
@@ -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('<b>' . $updated . ' translations</b> were updated (' . $count . ' total)')->flash();
         }
         return redirect($this->crud->route . '/1/edit/?locale=' . $locale);
index cc6ac846d25f13bace99d852b31cc0f8adf18b71..1e041b2f50663ae20da72fe3e5dd05d9111ace15 100644 (file)
@@ -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()