Skip to content

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!",
		],
	],
];

Translation for individual authority rules

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!",
		],
	],
];

Translating custom authority rules

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!",
		],
	],
];

Variables for translations

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!

Clone this wiki locally