Download the PHP package waterloomatt/translation without Composer
On this page you can find all versions of the php package waterloomatt/translation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download waterloomatt/translation
More information about waterloomatt/translation
Files in waterloomatt/translation
Package translation
Short Description Handle dynamic translations based on current controller/action.
License MIT
Informations about the package translation
laravel-dynamic-translations
Allows your application to use dynamic translations with ease
Installation
Composer
Run the following to include this via Composer
Laravel 5 Configuration
Register the service provider with your application by adding the following line to config/app.php
That's it! You're good to go.
Usage
In your views, use Laravel's translation helper as you normally would. Nothing needs to change here.
Now, the fun bit! In this example, you can override the 'pageTitle' translation by specifying which controller or action (or both) a translation should apply to.
In your messages.php translation file, override the pageTitle
translation by specifying a controller or action (or both).
As you can see, you can control which translation will be used by specifying the controller or action or both. The most specific translation that matches the current route will be used.
- Each component separates its name from its value by a colon
controller:user
,controller:payment
- Each component separates itself from other components by an underscore
controller:user_action:update
,controller:payment_action:decline_key:pageTitle
- The third component is key which simply defines the translation key.
- Both controller and action are optional
Important! Translations are searched by most specific to least specific.
- controller:name_action:name_key:name
- action:name_key:name
- controller:name_key:name
- name
In the following examples, assume your current route is http://localhost/public/search/index
-
Example 1
-
Example 2
-
Example 3
- Example 4