]> _ Git - cubist_cms-back.git/commitdiff
#2868
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 8 Jul 2019 16:16:02 +0000 (18:16 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 8 Jul 2019 16:16:02 +0000 (18:16 +0200)
src/app/Magic/Models/Translate.php

index 9ce01eafd51e4eb7e2619147d6e007ee2cb55b9e..379c61ff9f632dec8a3360cfcf1b4b6e2f153390 100644 (file)
@@ -44,4 +44,40 @@ class Translate extends CubistMagicModel
                 'fake' => true]);
         }
     }
+
+    /**
+     * @param \Cubist\Backpack\app\Magic\Controllers\CubistMagicController $controller
+     * @param \Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest $request
+     */
+    public function onBeforeUpdate($controller, $request)
+    {
+        $this->saveLanguageFile($controller, $request);
+        parent::onBeforeUpdate($controller, $request); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * @param \Cubist\Backpack\app\Magic\Controllers\CubistMagicController $controller
+     * @param \Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest $request
+     */
+    public function saveLanguageFile($controller, $request)
+    {
+        $exclude = ['_token', '_method', 'http_referrer', 'locale', 'slug', 'id', 'k', 'save_action'];
+
+        $translations = [];
+        $all = $request->all();
+        $locale = $all['locale'];
+        foreach ($all as $field => $content) {
+            if ($content == '') {
+                continue;
+            }
+            if (in_array($field, $exclude)) {
+                continue;
+            }
+
+            $key = base64_decode(substr($field, 2));
+            $translations[$key] = $content;
+        }
+
+        file_put_contents(base_path() . '/resources/lang/' . $locale . '.json', json_encode($translations));
+    }
 }