-
Notifications
You must be signed in to change notification settings - Fork 17
Translating your app
Tortue Torche edited this page Mar 17, 2015
·
2 revisions
To use translations in your app define some PHP like this:
// resources/lang/en/messages.php # For Laravel 5.0
// app/lang/en/messages.php # For Laravel 4.*
return [
'unauthorized' => [
'manage' => [
'all' => "You have no access!",
],
],
];
If you want to customize messages for some model or even for some authority rule define translation like this:
// config/authority-controller.php # For Laravel 5.0
// app/config/packages/efficiently/authority-controller/config.php # For Laravel 4.*
...
$authority->allow('store', 'Article');
...
// resources/lang/en/messages.php # For Laravel 5.0
// app/lang/en/messages.php # For Laravel 4.*
return [
'unauthorized' => [
'store' => [
'article' => "Only admin may do this!",
],
],
];
Also translations is available for your custom authority rules:
// config/authority-controller.php # For Laravel 5.0
// app/config/packages/efficiently/authority-controller/config.php # For Laravel 4.*
...
$authority->allow('vote', 'Article');
...
// resources/lang/en/messages.php # For Laravel 5.0
// app/lang/en/messages.php # For Laravel 4.*
return [
'unauthorized' => [
'vote' => [
'article' => "Only users which have one or more article may do this!",
],
],
];
Finally you may use action
(which contain authority rule like 'store') and subject
(for example 'article') variables in your translation:
// resources/lang/en/messages.php # For Laravel 5.0
// app/lang/en/messages.php # For Laravel 4.*
return [
'unauthorized' => [
'manage' => [
'all' => "You do not have access to :action :subject!",
],
],
];
Enjoy!