Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Magalliu's avatar

Folder 'de' on lang not being recognized

I added locally the 'de' folder for German language under 'lang' folder and when changing the locale to '/de' it's working properly.

I uploaded the same folder to the server under the 'lang' folder and set permissions 774 to the 'de' folder and all related files. The new folder 'de' is not being recognized. When change the locale to '/de' the default locale language is showing.

I have also 'en' and 'it' folder under 'lang' and they are recognized without any problems.

Anyway the folder 'de' is not being recognized on server but locally works fine.

Any idea? Thanks!

0 likes
13 replies
Sinnbeck's avatar

Why do you have a slash in /de? How do you set it?

Sinnbeck's avatar

@Magalliu how are you setting locale based on url? That isn't a built in feature in laravel

Magalliu's avatar

@Sinnbeck It's a work around and I'm not using any package. I'm managing it on header like this:

        @php
        $thisUrl = url()->current().'/';

        if (app()->getlocale() == 'en') {
            $newUrlIt  = str_replace('/en/', '/it/', $thisUrl);
            $newUrlDe  = str_replace('/en/', '/de/', $thisUrl);
        } else if (app()->getlocale() == 'it') {
            $newUrlEn  = str_replace('/it/', '/en/', $thisUrl);
            $newUrlDe  = str_replace('/it/', '/de/', $thisUrl);
        } else if (app()->getlocale() == 'de') {
            $newUrlIt  = str_replace('/de/', '/it/', $thisUrl);
            $newUrlEn  = str_replace('/de/', '/en/', $thisUrl);
        }
        @endphp

          @if ( Config::get('app.locale') == 'it')
          <a class="dropdown-item" href="{{ $newUrlEn }}">
            <span class="lang lang-en">English</span>
          </a>
          <a class="dropdown-item" href="{{ $newUrlDe }}">
            <span class="lang lang-de">German</span>
          </a>
          @elseif ( Config::get('app.locale') == 'en' )
          <a class="dropdown-item" href="{{ $newUrlIt  }}">
            <span class="lang lang-it">Italian</span>
          </a>
          <a class="dropdown-item" href="{{ $newUrlDe }}">
            <span class="lang lang-de">German</span>
          </a>
          @elseif ( Config::get('app.locale') == 'de' )
          <a class="dropdown-item" href="{{ $newUrlEn }}">
            <span class="lang lang-en">English</span>
          </a>
          <a class="dropdown-item" href="{{ $newUrlIt }}">
            <span class="lang lang-it">Italian</span>
          </a>
          @endif

The problem is that 'de' is not being recognized. English and Italian it's working fine.

Sinnbeck's avatar

@Magalliu my guess is that you are replacing wrong here

$newUrlIt  = str_replace('/de/', '/en/', $thisUrl); //en instead of it 
            $newUrlEn  = str_replace('/de/', '/en/', $thisUrl); 
Magalliu's avatar

@Sinnbeck

$newUrlIt  = str_replace('/de/', '/it/', $thisUrl); // 'it' stands for italian language
$newUrlEn  = str_replace('/de/', '/en/', $thisUrl); // 'en' stands for italian language

And that's not the problem because all the url are having the correct locale. The problem is when I'm on 'domain.com/de' it does not take the translations from 'de' folder but it takes the translations from the default locale which is 'it'.

Magalliu's avatar

@Sinnbeck when I'm on 'domain.com/de' it shows the same as it was 'domain.com/it'. So the behavior when I'm on 'domain.com/de' is same as it was 'domain.com/it'. And 'it' is the default locale.

So when I check else if (app()->getlocale() == 'de') when I'm on 'domain.com/de' it return false because '/de' is not being recognized at all.

Magalliu's avatar

@Sinnbeck Sorry my bad I had to add 'de' at locales on the middleware.

if(in_array($locale, ['en','it', 'de'])) {
            App::setLocale($locale);
            $request->except(0); // handle request without locale further
}
Magalliu's avatar

@Sinnbeck can I ask you another question which is related always to locale. Changing locale now will add public on the url like this: 'domain.com/public/en' or 'domain.com/public/it' or 'domain.com/public/de'.

This is happening only on changing the locale using the code provided above. I have already created the rules on .htaccess and public is already removed from url.

It will be added public on url only when changing the locale. Any idea or I have to open a new thread?

Please or to participate in this conversation.