The numbers get reversed when use of arabic language

1.8k Views Asked by At

I am using laravel localization

Here is the code I am using

<p class="retail-price">@lang('frontend/watch-detail.Reference.retail')
     <span class="prices">
     @if($watch['price'] == 0 || $watch['price'] == NULL) N/A

     @else
         @php
         $text =number_format($watch['price'], 0, ',', ' ');
         @endphp
         {{$text}}
     @endif
     </span>
</p>

Here is what I get in arabic =>Image that I get

While I should get 30 700!

I do not want to use a reverse function

2

There are 2 best solutions below

3
On BEST ANSWER

That issue occurs because Arabic is read from right to left. It would be easier to add an if statement to check if it is Arabic, then reverse it, so the reversed Arabic writing is reversed back to non-reversal.

0
On

You can wrap the text in a bdo element and define it as left-to-right:

function changeDir() {
  var el = document.getElementById('bdo0');
  el.dir = el.dir == 'ltr'? 'rtl':'ltr';
  document.getElementById('theDir').textContent = el.dir;
}
<div dir="rtl">هذا رقم: <bdo id="bdo0" dir="ltr">123 456 789</bdo></div>
<button onclick="changeDir()">Change direction</button><span id="theDir"></span>

You shouldn't need any in–page script, it should be just HTML.