Laravel locatization not translating - laravel

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)
{{ __('content/navbar.nav link 1') }}</div>
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

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

Related

how do I insert a different icon for each widgets

how do I insert a different icon for each widgets?
[
'type' => 'progress_white',
'class' => 'card mb-2',
'progressClass' => 'progress-bar bg-primary',
'value' => $userCount,
'description' => 'Utenti registrati.',
'progress' => (int)$userCount/10*100, // integer
'hint' => 'Numero di utenti registrati al portale.',
],
the html part is this this part below
<div class="{{ $widget['wrapperClass'] ?? 'col-sm-6 col-md-4' }}">
<div class="{{ $widget['class'] ?? 'card' }}">
<div class="card-body">
#if (isset($widget['value']))
<div class="text-value">{!! $widget['value'] !!}</div>
#endif
......
Unfortunately there is no way with the default widgets you will ave to create your own.
#if(isset($widget['icon']))
<div class="text-right" style="position:absolute;top:5px;right:15px;font-size: 40px;color: {{ $widget['icon_color'] ?? 'rgba(0,0,0,0.2)' }}">
<span class="{{ $widget['icon'] }}"></span>
</div>
#endif
Put that within the card-body class. Styling might need to be changed a little bit.
Other option is Backpack uses a new theme based on CoreUI. Can look at the documentation for CoreUI, or take a look at the source for the theme at https://backstrap.net
What kind of icons do you want? If you use icon set like material icon or awesome icon, you can pass your icon name and use it in "i" tag like this:
"icon" => "fa fa user"
and in your blade:
<i class"{{$widget['icon']}}"></i>

Populated Array Throws Undefined Offset: 1 In Laravel 5.6

I have a laravel 5.6 query that populates an array with a single result to pass to a view.
This is the query :
$farms=DB::select("select pic,shop_name,StateName,amount,
duration,ror,farm_shop.id from farm_shop join states on states.id=farm_shop.state_id where
farm_shop.id=:id",['id' => $id]);
A print_r command returns this:
Array ( [0] => stdClass Object ( [pic] =>
092720180421565bac5ae4974f9MAIN.jpg
[shop_name] => Pig Farm [StateName] => STATEGTR
[amount] => 3000000 [duration] => 11 [ror] => 28 [id] => 4 ) )
My view accesses it like this :
#foreach($farms->as $farmshop)
<div class="row course-set courses__row col-md-6 col-offset-md-3">
#php
$pic="http://xxxxxx/storage/".$farmshop['pic'];
#endphp
<section class="col-md-3">
<img src="{{$pic}}" alt="" width="1200" height="1200" title="xxx">
<div class="text-center"><b>{{$farmshop['shop_name']}}</b><br/>
Location: {{$farmshop[['StateName']}}
<br/>
Amount (X):<span style="color:red">
<b> {{number_format($farmshop['amount'],2)}}</b></span><br/>
Period (Months): {{$farmshop['duration']}}<br/>
Rate (%): {{$farmshop['ror']}} <div class="text-
center">
<div class="col-md-12 text-center">
Invest
</div>
<div> </div>
</div>
</section>
</div>
#endforeach
The error that now gets thrown is :
Undefined offset: 1
And the below line gets highlighted in the inbuilt laravel function compileForEach($expression):
$iteratee = trim($matches[1]);
Please how do i resolve this?..Thanks
The problem was in this line of code: #foreach($farms->as $farmshop)
Correct code is supposed to be : #foreach($farms as $farmshop)
Thanks

Symfony DomCrawler can't get attribute

For this div:
<section class='menu'>
<div class="some beautiful classes" link="/some/path/in/web">
<div class="contImgHome">
<img src="/images/icon.jpg alt="">
</div>
<h5>
Go to Section
</h5>
</div>
<div class="some beautiful classes" link="/another/path/in/web">
<div class="contImgHome">
<img src="/images/icon.jpg alt="">
</div>
<h5>
Go to another section
</h5>
</div>
</section>
I make:
$response = $guzzleClient->request('GET', $url_base);
$crawler = new Crawler( (string) $response->getBody() );
$crawler->filter('section.menu > div')->each(function( Crawler $div, $i )
{
$xx = $div->extract( [ 'class', 'link'] );
print_r( $xx );
echo PHP_EOL;
die;
});
And return this:
Array
(
[0] => Array
(
[0] => some beautiful classes
[1] =>
)
)
I also tried with:
$div->attr('classes');
$div->attr('link');
But 'link' attribute is always empty. ¿Why I cant get "link" attribute?
I'm using Laravel 5.2 and installed Symfony Crawler vía composer.
It was my mistake!
Web set that "link" attribute with javascript using Document Ready, so attr is not existing when Crawler gets page DOM.

Illegal string offset Laravel 5.3

I'm trying to build a 'breadcrumb' thing dynamically using an array and this pass it to the view
In my controller
//build the breadcrumbs
$breadcrumbs = [
[
'link' => 'test link',
'name' => ''
]
];
return view('home',compact('breadcrumbs'));
the 'home.blade.php' extends the 'master.blade.php' where the
#include('_breadcrumbs')
resides. And here's the contents of '_breadcrumbs.blade.php'
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li #if(!isset($breadcrumbs))class="active"#endif>
<i class="fa fa-dashboard"></i> Dashboard
</li>
#if(isset($breadcrumbs))
#foreach($breadcrumbs as $b)
<li>{{$b['name']}}</li>
#endforeach
#endif
</ol>
</div>
</div>
<!-- /.row -->
but it gives me this error
Illegal string offset 'link' (View:
C:\laravel-projects\dinhi_ecommerce\resources\views_breadcrumbs.blade.php)
(View:
C:\laravel-projects\dinhi_ecommerce\resources\views_breadcrumbs.blade.php)\
If I do
dd(var_dump($breadcrumbs));
it gives me the contents of the array 'breadcrumbs' which means it does work in the controller part.
Any ideas, help please?
UPDATE:
I actually have a line where I modify the index 'name' in the array which I forgot to include in my post. Anyway I change it from
$breadcrumbs['name'] = categories::where('cat_id',$id)->first()->cat_name;
to
$breadcrumbs[0]['name'] = categories::where('cat_id',$id)->first()->cat_name;
and now its working :)

Laravel locale translate paragraph

I'd like to ask if this is the correct way to translate a story:
'story' => 'This is a story about <br> peanut butter. <br> Peanut butter tastes good.'
Should I use <br> tags like above or is there another way?
Thanks,
g3
You could make "story" an array.
For example:
'story' => [
'This is a story about',
'peanut butter',
'Penut butter tastes good'
];
Then in your code:
#foreach($story as $paragraph)
{{ $paragraph }}<br>
#endforeach
This way also supports unlimited paragraphs, which can be an issue across translation barriers.
This is implemented in my website.
#foreach (trans('menus.benefits_menu') as $key => $translation)
<a href="{{ route('benefits', ['slug' => $key]) }}" class="{{ ($key == $uri) ? 'active' : ''}}">
<div class="name">{{ $translation }}</div>
</a>
#endforeach
You can see it working here: http://www.metinet.co/benefits/cloud_technology
(as the left hand menu)

Resources