Laravel locatization not translating

207 Views Asked by At

Okay so in my app.blade.php

<html>
    <head>
        //....
    </head>
    <body class="bg-black text-white flex flex-col min-h-screen page-{{ Route::currentRouteName() }}">
        {{-- Navbar --}}
        @include('layouts.navbar')
 
        {{-- Page content --}}
        <div class="flex-1">
            @yield('content')
        </div>

        {{-- Footer --}}
        @include('layouts.footer')
    </body>
</html>

Now i want to use localization in the navbar so i did this (Lets call this block 1)

<div class="swiper-slide bg-primary"><div class="swiper-content mx-auto w-fit py-3 flex items-center gap-2"><i class="fas fa-concierge-bell"></i> {{ __('content/navbar.orange header 1') }}</div></div>

And thats working but now in the same file only 20 lines below the code above (Lets call this block 2)

<a href={{ route("home") }}><div class="text-lg xl:text-2xl font-bold @if(Request::is('/')) border-b-2 border-primary md:border-b-[4px] @endif">{{ __('content/navbar.nav link 1') }}</div></a>

I have this line of code but its always translated in english. But the weird part is that when my locale is set to FR the content of block 1 shows in FR but the content of block 2 shows in EN eventhough they are in the same file

Im super confused and cant figure out why that is

Any help is welcome!

If u need more code let me know!

Content and structure of Lang file

Lang/en/content/navbar.php 

Content of EN file

<?php

// lang/en/content/navbar.php

return [
    'orange header 1' => 'Service to sold machines',
    'orange header 2' => 'Large stock',
    'orange header 3' => 'Transport to location',
    'orange header 4' => 'Trade-in possible',
    'nav link 1' => 'Home',
    'nav link 2' => 'Stock',
    'nav link 3' => 'Lease',
    'nav link 4' => 'Contact',
];

Content of FR file (Lang/fr/content/navbar.php)

<?php

// lang/fr/content/navbar.php

return [
    'orange header 1' => 'Service aux machines vendues',
    'orange header 2' => 'Stock important',
    'orange header 3' => "Transport à l'emplacement",
    'orange header 4' => "Reprise possible",
    'nav link 1' => 'Home',
    'nav link 2' => 'Stock',
    'nav link 3' => 'Louer',
    'nav link 4' => 'Contact',
];

First image shows the page in fr and second image in en but the navbar content is still the same eventhough the uspbars content is translated

App locale set to FR

App locale set to EN

1

There are 1 best solutions below

0
w3_ On

Ahhhh i had a piece of code between the uspsbar and navbar

            <li onclick="{{ App::setLocale("en") }}" class="flex items-center gap-2 text-white text-lg font-bold">
                      <a class="flex items-center gap-2" href="{{ route('locale.setting', 'en') }}">
                        <img class="h-5 w-7" src="{{ asset('img/flags/EN-flag.png') }}" alt="EN-flag"> EN
                      </a>
                    </li>

But the onclick sets the locale to en and forgot to remove the onclick function, my bad!

Thanks everyone!!!