]> _ Git - fluidbook-toolbox.git/commitdiff
wip #4623 0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Jul 2021 15:10:55 +0000 (17:10 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Jul 2021 15:10:55 +0000 (17:10 +0200)
app/Console/Commands/WorkshopMigration.php
app/Models/FluidbookTranslate.php

index c998ebf2ff941d7aa6ea3682a7deddae5a24504a..9a78f5447e807d85deb82c3bff6bdb18dfae90d2 100644 (file)
@@ -5,6 +5,7 @@ namespace App\Console\Commands;
 
 use App\Models\FluidbookTheme;
 use App\Models\FluidbookQuote;
+use App\Models\FluidbookTranslate;
 use Cubist\Backpack\Console\Commands\CubistCommand;
 use Cubist\Backpack\Magic\Fields\Files;
 use Cubist\Backpack\Magic\Fields\Color;
@@ -24,7 +25,7 @@ class WorkshopMigration extends CubistCommand
             //'Backup current database' => 'backup',
             //'Import Quotes' => 'importQuotes',
             'Migrate magic models' => 'migrate',
-            'Import Themes' => 'importThemes',
+            'Import Translations' => 'importTranslations',
 
             'Clean caches' => 'cleanCache'
         ];
@@ -61,68 +62,6 @@ class WorkshopMigration extends CubistCommand
         $this->executeProcessQuiet('php artisan optimize:clear');
     }
 
-    protected function themeCompatTable()
-    {
-        $theme = new FluidbookTheme();
-        $theme->updateWS2Table();
-    }
-
-    protected function importThemes()
-    {
-
-        $map = ['theme_id' => 'id',
-            'nom' => 'name',
-            'proprietaire' => 'owner',
-            'date' => 'created_at',];
-
-        $ignore = ['extraXSpace', 'extraYSpace'];
-
-        FluidbookTheme::$updateWS2ViewOnChange = false;
-        foreach (FluidbookTheme::all() as $theme) {
-            $theme->delete();
-        }
-
-        foreach (DB::table($this->_oldDB . '.themes')->get() as $e) {
-            $oldRoot = $this->_oldRoot . 'themes/' . $e->theme_id . '/';
-            $c = new FluidbookTheme();
-            foreach ($map as $old => $new) {
-                $v = $e->$old;
-                if ($old === 'date') {
-                    $date = new \DateTime();
-                    $date->setTimestamp($v);
-                    $v = $date;
-                }
-                $c->setAttribute($new, $v);
-            }
-            $c->save();
-
-
-            $s = $this->_unserialize($e->parametres);
-
-            foreach ($s->datas as $k => $data) {
-                if (in_array($k, $ignore)) {
-                    continue;
-                }
-
-                $f = $c->getField($k);
-                if (null === $f) {
-                    continue;
-                }
-                if ($f instanceof Files) {
-                    $c->_handleWS2File($f, $data, $oldRoot);
-                } else {
-                    if ($f instanceof Color) {
-                        $data = FluidbookTheme::_colorToWS3($data);
-                    }
-                    $c->setAttribute($k, $data);
-                }
-            }
-            $c->save();
-        }
-        FluidbookTheme::$updateWS2ViewOnChange = true;
-        $this->themeCompatTable();
-
-    }
 
     protected function _unserialize($str)
     {
@@ -158,4 +97,29 @@ class WorkshopMigration extends CubistCommand
         }
     }
 
+    protected function importTranslations()
+    {
+        $slug = [];
+        $nsis = [];
+        $contents = [];
+
+        foreach (DB::table($this->_oldDB . '.langues')->get() as $e) {
+            $code = $e->lang_id;
+            if (stristr($code, '-')) {
+                $ex = explode('-', $code);
+                $code = $ex[0] . '_' . mb_strtoupper($ex[1]);
+            }
+            $slug[$code] = '1';
+            $nsis[$code] = $e->nsis;
+            $contents[$code] = ['k' => '-'];
+            $translations = json_decode($e->traductions, true);
+            foreach ($translations as $str => $translation) {
+                $contents[$code]['t_' . base64_encode($str)] = $translation;
+            }
+            touch(FluidbookTranslate::getLanguageFile($code));
+        }
+
+        DB::table('fluidbook_translate')->where('id',1)->update(['slug' => json_encode($slug), 'nsis' => json_encode($nsis), 'content_translatable' => json_encode($contents)]);
+    }
+
 }
index 3e423fc99f638ceabfa049e4fc10662f6113a87e..ab12b89de3a336250dad8425427cddd4cae3e012 100644 (file)
@@ -25,7 +25,7 @@ class FluidbookTranslate extends Translate
 
     public function setFields()
     {
-        $this->addField(['name' => 'nsis', 'type' => NSISLocale::class, 'label' => __('Langue de l\'installeur'), 'translatable' => true]);
+        $this->addField(['name' => 'nsis', 'type' => NSISLocale::class, 'label' => __('Langue de l\'installeur'), 'translatable' => true, 'default' => 'English']);
         parent::setFields();
     }
 
@@ -38,4 +38,13 @@ class FluidbookTranslate extends Translate
     {
         return array_merge(parent::getExtensions(), ['js']);
     }
+
+    protected function _getLanguageFile($locale)
+    {
+       return self::getLanguageFile($locale);
+    }
+
+    public static function getLanguageFile($locale){
+        return resource_path('lang/fluidbook.' . $locale . '.json');
+    }
 }