From: Vincent Vanwaelscappel Date: Wed, 6 Sep 2023 06:24:30 +0000 (+0200) Subject: wait #6023 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=cdbf7b390a71c80db4cb3a8934fe9685b0c0dc24;p=fluidbook-toolbox.git wait #6023 @0.5 --- diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index ea05a5789..c5e037c5f 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -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) {