Skip to content

Commit

Permalink
Loading translations via view composer
Browse files Browse the repository at this point in the history
  • Loading branch information
nWidart committed Sep 16, 2017
1 parent 51dc8dc commit 2a327fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Modules/Core/Composers/TranslationsViewComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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'));
}
}
4 changes: 4 additions & 0 deletions Modules/Core/composers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
view()->composer('*', \Modules\Core\Composers\CurrentUserViewComposer::class);
view()->composer('layouts.master', \Modules\Core\Composers\AssetsViewComposer::class);
view()->composer('*', \Modules\Core\Composers\EditorViewComposer::class);

view()->composer([
'layouts.master',
], \Modules\Core\Composers\TranslationsViewComposer::class);
2 changes: 1 addition & 1 deletion Themes/Adminlte/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
@endforeach
<script>
window.AsgardCMS = {
translations: {!! json_encode(['page' => array_dot(trans('page::pages')), 'core' => array_dot(trans('core::core'))]) !!},
translations: {!! $staticTranslations !!},
locales: {!! json_encode(LaravelLocalization::getSupportedLocales()) !!},
currentLocale: '{{ locale() }}',
};
Expand Down

0 comments on commit 2a327fe

Please sign in to comment.