23

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?

1 Answer 1

64

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, that was the problem :)
Wow, thanks for that answer! This seems completely undocumented, and is very inconsistent with blade's usual path handling. Did you arrive at it by reading the source?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.