]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6023 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 06:24:30 +0000 (08:24 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 06:24:30 +0000 (08:24 +0200)
app/Console/Commands/WorkshopMigration.php

index ea05a5789b7966ee00a7e227bfcbb997dadff90f..c5e037c5faa4483a87090530ea96b6238d220961 100644 (file)
@@ -14,6 +14,7 @@ use Cubist\Util\ArrayUtil;
 use Cubist\Util\Json;
 use Cubist\Util\ObjectUtil;
 use Cubist\Util\PHP;
+use Cubist\Util\Text;
 use Illuminate\Contracts\Cache\Lock;
 use Illuminate\Support\Facades\Artisan;
 use Illuminate\Support\Facades\Cache;
@@ -254,6 +255,8 @@ class WorkshopMigration extends CubistCommand
                     $v = $this->_normalizeTranslations($v, $e->lang);
                 } else if (Json::isJson($v)) {
                     $v = json_decode($v, true);
+                } else if ($new === 'locale') {
+                    $v = $this->_normalizeLang($v);
                 }
                 $c->setAttribute($new, $v);
             }
@@ -281,7 +284,7 @@ class WorkshopMigration extends CubistCommand
                 } else if (Json::isJson($data)) {
                     $data = json_decode($data, true);
                 }
-                if (isset($mapValues[$data])) {
+                if (is_scalar($data) && isset($mapValues[$data])) {
                     $data = $mapValues[$data];
                 }
 
@@ -307,6 +310,15 @@ class WorkshopMigration extends CubistCommand
         }
     }
 
+    protected function _normalizeLang($lang)
+    {
+        $e = preg_split('/[-_]+/', $lang);
+        if (count($e) === 1) {
+            return $lang;
+        }
+        return mb_strtolower($e[0]) . "_" . mb_strtoupper($e[1]);
+    }
+
     protected function _normalizeTranslations($value, $lang)
     {
         if (!is_string($value) || !Json::isJson($value)) {
@@ -315,7 +327,7 @@ class WorkshopMigration extends CubistCommand
         $translations = json_decode($value);
         $res = [];
 
-        $l10n = FluidbookTranslate::getCompiledTranslations()[$lang];
+        $l10n = FluidbookTranslate::getCompiledTranslations()[$this->_normalizeLang($lang)];
 
         foreach ($translations as $base => $trans) {
             if (!isset($l10n[$base]) || !$trans || $l10n[$base] === $trans) {