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

anand_aks's avatar

How to access localization variable inside @php directive

This is a sample code

@php
	$totaltime = $totaltime + $deliverylocation->delivery_time;
	$hours = intdiv($totaltime, 60);
	$time = '';

	if ($hours != 0) {
		$time = $hours.'hour';
	}
@endphp
			
<input type="hidden" id="delivery_time" value="{{$time}}">

In the above code, I am attaching the string "hour" with the variable $hour. But for adding localization I added "hour" to localization file along with the other language.

But how can i access that here

i tried

if ($hours != 0) {
	$time = $hours.{{__('hour')}};
}

But it is showing error.

0 likes
2 replies
Snapey's avatar

because you don't need the double curly braces when already in php context

Please or to participate in this conversation.