Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: lang file in subfolder

I want to "multilocalize" my Laravel project.

I made my directory structure like this:

lang
- en
 - front
  - contact.php
-footer.php

And I built my footer like this:

{{ link_to('/', trans('footer.frontpage'))}}

It works perfectly, but when I want localize the other blade pages, for example the contact us page like this:

@lang('front.contact.name')

or this:

{{ __('front.contact.name') }}

or this:

{{ trans('front.contact.name') }}

I only got back on the page:

front.contact.name

What's the problem?

like image 695
Feralheart Avatar asked Aug 13 '17 06:08

Feralheart


1 Answers

Just use / as directory separator.

{{ trans('front/contact.name') }}

In Blade both "/" and "." function (while the latter is recommended).

But for Lang the "." is unintentionally reserved for file's content (array and any number of child-array), so that we can have both a folder and file with the same name (like both front folder and front.php file).

like image 147
Mahbub Avatar answered Sep 22 '22 13:09

Mahbub