Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
2951b67b
Unverified
Commit
2951b67b
authored
Oct 16, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creating a loading backend translation hook
parent
633085d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
20 deletions
+40
-20
TranslationsViewComposer.php
Modules/Core/Composers/TranslationsViewComposer.php
+6
-20
LoadingBackendTranslations.php
Modules/Core/Events/LoadingBackendTranslations.php
+34
-0
No files found.
Modules/Core/Composers/TranslationsViewComposer.php
View file @
2951b67b
...
...
@@ -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
()
));
}
}
Modules/Core/Events/LoadingBackendTranslations.php
0 → 100644
View file @
2951b67b
<?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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment