Creating a loading backend translation hook

parent 633085d9
......@@ -3,31 +3,17 @@
namespace Modules\Core\Composers;
use Illuminate\Contracts\View\View;
use Modules\Core\Events\LoadingBackendTranslations;
class TranslationsViewComposer
{
public function compose(View $view)
{
$staticTranslations = json_encode([
'page' => array_dot(trans('page::pages')),
'pages' => array_dot(trans('page::pages')),
'core' => array_dot(trans('core::core')),
'media' => array_dot(trans('media::media')),
'folders' => array_dot(trans('media::folders')),
'roles' => array_dot(trans('user::roles')),
'users' => array_dot(trans('user::users')),
'sidebar' => array_dot(trans('core::sidebar')),
'dashboard' => array_dot(trans('dashboard::dashboard')),
'menu' => array_dot(trans('menu::menu')),
'menu-items' => array_dot(trans('menu::menu-items')),
'settings' => array_dot(trans('setting::settings')),
'tags' => array_dot(trans('tag::tags')),
'translations' => array_dot(trans('translation::translations')),
'workshop' => array_dot(trans('workshop::workshop')),
'modules' => array_dot(trans('workshop::modules')),
'themes' => array_dot(trans('workshop::themes')),
]);
if (app('asgard.onBackend') === false) {
return;
}
event($staticTranslations = new LoadingBackendTranslations());
$view->with(compact('staticTranslations'));
$view->with('staticTranslations', json_encode($staticTranslations->getTranslations()));
}
}
<?php
namespace Modules\Core\Events;
/**
* Hook LoadingBackendTranslations
* Triggered when loading the backend
* Used to send laravel translations to the frontend
* Example for VueJS
* @package Modules\Core\Events
*/
class LoadingBackendTranslations
{
private $translations = [];
public function getTranslations() : array
{
return $this->translations;
}
public function load($key, array $translations)
{
$this->translations = array_merge($this->translations, [$key => $translations]);
return $this;
}
public function loadMultiple(array $translations)
{
$this->translations = array_merge($this->translations, $translations);
return $this;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment