Feralheart
Feralheart

Reputation: 1920

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?

Upvotes: 22

Views: 16011

Answers (1)

Mahbub
Mahbub

Reputation: 4942

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).

Upvotes: 62

Related Questions