Search code examples
laravelmultilinguallaravel-blade

Multilingual links in Blade Laravel


I'm translating a Laravel site which is using Blade templates and was wondering if there is a better way to translate a link as shown below:

app/lang/en/contact.php:

return [
    '1' => 'text before link',
    '2' => 'link text',
    '3' => 'text after link'
];

app/views/contact.blade.php:

<p>{{ Lang::get('contact.1') }} 
      <a herf="{{URL::route('home')}}">{{ Lang::get('contact.2') }}</a> 
{{ Lang::get('contact.3') }}}</p>

Solution

  • What about this solution?

    blade template:

    {!! Lang::get('test.test', [ 'url' => 'http://stackoverflow.com/' ]) !!}
    

    lang/test.php

    <?php
    return [
        'test' => '<a href=":url">My Pretty Link</a>'
    ]