Loading translations via view composer

parent 51dc8dc1
<?php
namespace Modules\Core\Composers;
use Illuminate\Contracts\View\View;
class TranslationsViewComposer
{
public function compose(View $view)
{
$staticTranslations = json_encode([
'page' => array_dot(trans('page::pages')),
'core' => array_dot(trans('core::core'))
]);
$view->with(compact('staticTranslations'));
}
}
...@@ -9,3 +9,7 @@ view()->composer('*', \Modules\Core\Composers\LocaleComposer::class); ...@@ -9,3 +9,7 @@ view()->composer('*', \Modules\Core\Composers\LocaleComposer::class);
view()->composer('*', \Modules\Core\Composers\CurrentUserViewComposer::class); view()->composer('*', \Modules\Core\Composers\CurrentUserViewComposer::class);
view()->composer('layouts.master', \Modules\Core\Composers\AssetsViewComposer::class); view()->composer('layouts.master', \Modules\Core\Composers\AssetsViewComposer::class);
view()->composer('*', \Modules\Core\Composers\EditorViewComposer::class); view()->composer('*', \Modules\Core\Composers\EditorViewComposer::class);
view()->composer([
'layouts.master',
], \Modules\Core\Composers\TranslationsViewComposer::class);
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
@endforeach @endforeach
<script> <script>
window.AsgardCMS = { window.AsgardCMS = {
translations: {!! json_encode(['page' => array_dot(trans('page::pages')), 'core' => array_dot(trans('core::core'))]) !!}, translations: {!! $staticTranslations !!},
locales: {!! json_encode(LaravelLocalization::getSupportedLocales()) !!}, locales: {!! json_encode(LaravelLocalization::getSupportedLocales()) !!},
currentLocale: '{{ locale() }}', currentLocale: '{{ locale() }}',
}; };
......
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