Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel translation not working

I have languages for french and english. Fallback and standard is french (fr).

My folder structure: enter image description here

This is the content of the login.php (english):

<?php
return [
    'welcome' => 'Welcome',
    'mail' => 'E-Mail address',
    'password' => 'Password'
];

I am referencing the keys either using @lang() or {{ trans('') }}. Example:

<label for="email" class="col-md-4 control-label">{{ trans('admin.login.mail') }}</label>

However this gets returned as: enter image description here

like image 438
xTheWolf Avatar asked Oct 20 '16 11:10

xTheWolf


People also ask

How do I set localization in Laravel?

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.

What is @lang in Laravel?

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.

How can I get Laravel language?

I use App::getLocale() which is probably the most supported way as the App::setLocale('EN') method is used in the documentation. You can use this method everywhere. If it throughs an error somewhere, you can use \App::... to make it work.


1 Answers

When you're putting language files into subfolder, you need to specify it using slash. So, try this instead:

{{ trans('admin/login.mail') }}
like image 127
Alexey Mezenin Avatar answered Oct 04 '22 13:10

Alexey Mezenin