PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 11, 2022

[FIXED] Laravel: lang file in subfolder

 March 11, 2022     laravel, laravel-5, localization, php     No comments   

Issue

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?


Solution

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



Answered By - Mahbub
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing