29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Localization 287<br />

.<br />

1 Route::get('welcome/{locale}', function ($locale) {<br />

2 App::setLocale($locale);<br />

3<br />

4 //<br />

5 });<br />

You may also configure a “fallback language”, which will be used when the active language does not<br />

contain a given language line. Like the default language, the fallback language is also configured in<br />

the config/app.php configuration file:<br />

.<br />

1 'fallback_locale' => 'en',<br />

Basic Usage<br />

You may retrieve lines from language files using the trans helper function. The trans method<br />

accepts the file and key of the language line as its first argument. For example, let’s retrieve the<br />

language line welcome in the resources/lang/messages.php language file:<br />

.<br />

1 echo trans('messages.welcome');<br />

Of course if you are using the Blade templating engine, you may use the {{ }} syntax to echo the<br />

language line:<br />

.<br />

1 {{ trans('messages.welcome') }}<br />

If the specified language line does not exist, the trans function will simply return the language<br />

line key. So, using the example above, the trans function would return messages.welcome if the<br />

language line does not exist.<br />

Replacing Parameters In Language Lines<br />

If you wish, you may define place-holders in your language lines. All place-holders are prefixed<br />

with a :. For example, you may define a welcome message with a place-holder name:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!