2

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

w3_
  • 64
  • 1
  • 1
  • 14
  • can you post the content of the translation file ? – ThS Sep 23 '22 at 09:22
  • @ths added the content of translations file as edit – w3_ Sep 23 '22 at 09:26
  • it is working, but because you have the same values in both translation files you think it doesn't. Try changing `'nav link 1' => 'Home'` in the FR file to `'nav link 1' => 'Accueil'` (for example) and check again. – ThS Sep 23 '22 at 09:30
  • @ths oh my bad i showt the wrong one, i actually have all 4 nav links in the file and they will not translate to fr, i know that because nav link 3 content is different in fr – w3_ Sep 23 '22 at 09:32
  • so ? Did you try as I suggested ? – ThS Sep 23 '22 at 09:33
  • @ths Yes, i changed "Home" to "Test" and it still shows the english "Home" instead of "test", i also added a picture to be more clear – w3_ Sep 23 '22 at 09:36
  • 1
    Caching your views? Also the way you're naming your translation keys is odd, they should explain the string they're actually translating so it's clear. – Daniel Dewhurst Sep 23 '22 at 09:39
  • try to debug the output of `__` function and see what does it return. – ThS Sep 23 '22 at 09:39
  • How to debug the output of __ ?? – w3_ Sep 23 '22 at 09:42
  • @ths, fixed it, made a stupid mistake :X – w3_ Sep 23 '22 at 09:44

1 Answers1

0

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!!!

w3_
  • 64
  • 1
  • 1
  • 14