1st question:
I've inserted the localization in many types of texts and things, but I don't know how to import it into in the following forms:
{{ Form::label('name', 'here') }}
{{ Form::text('name', null, array('placeholder' => 'here')) }}
{{ Form::submit('here', array('class' => 'btn btn-success')) }}
{{ Form::button('here', array('class' => 'btn btn-default')) }}
I want it to be in the form label 'here' and in the placeholder of the text 'here'.
2nd question:
I am not allowed to insert it with links in my language file: text here blah blah <a href="{{ URL::to('text') }}">BLAH</a>?
Is there anyway to insert it with links?
Thanks in advance.
Localization feature of Laravel supports different language to be used in application. You need to store all the strings of different language in a file and these files are stored at resources/views directory. You should create a separate directory for each supported language.
Laravel-lang is a collection of over 68 language translations for Laravel by developer Fred Delrieu (caouecs), including authentication, pagination, passwords, and validation rules. This package also includes JSON files for many languages.
To fetch current locale you should use App::getLocale() or App::isLocale('...') . Localization. You can also use app()->getLocale() which in Blade would be {{ app()->getLocale() }} .
Laravel's gives you the option to change the locale for a single Http Request by executing the setLocale method on App Facade App::setLocale($locale); , But what if once the language is changed you don't want to worry about setting the Locale and this should be taken care by an automatic code logic.
Supposing that your messages are stored in app/lang/en/message.php
you can use the same way for all your cases:
In Blade template:
{{ Form::label('name', Lang::get('message.key')) }}
{{ Form::text('name', null, array('placeholder' => Lang::get('message.key'))) }}
{{ Form::submit(Lang::get('message.key'), array('class' => 'btn btn-success')) }}
In HTML tag mixed with some Blade expression:
<a href="{{ URL::to(Lang::get('message.key')) }}">BLAH</a>
You can also use localization in Blade templates using strictly Blade syntax.
Given that you have a message in your /app/lang/en/messages.php
that corresponds to the key "message_key", you can do :
@lang('messages.message_key')
to render the message in the locale that your application is configured to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With