Reputation: 31
I'm using Laravel 6 and trying to make a dual-language page but I faced a serious problem when dealing with Arabic script.
I installed mcamara package then created test.blade.php
page for testing purposes which has the following code regardless of bootstrap and styling stuff:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
<a class="navbar-brand" href="{{ LaravelLocalization::getLocalizedURL($localeCode, null, [], true) }}">{{ $properties['native'] }}</a>
@endforeach
</nav>
<h1>{{ __('messages.test') }}</h1>
<h1>اختبار</h1>
</body>
</html>
And these are my lang files named 'messages' in Arabic:
'test'=>'اختبار',
And in English:
'test'=>'test',
Now the first h1
tag contains the word that must be translated according to language switching, but instead of getting an understandable word I get these strange characters اختبار
, and when I wrote the Arabic 'اختبار' word -which means 'test'- as a string it showed up very well.
Here is my input: enter image description here
I'm using VS code and all my pages has UTF-8 encoding. I also tried to put this code: Blade::setEchoFormat('e(utf8_encode(%s))');
in Boot class in AppServiceProvider.php but it does not work.
I hope I can find help.
Upvotes: 1
Views: 2130
Reputation: 81
It appears to be that your file is not correctly saved in UTF-8. You can see it yourself here. Paste the text you see on the page (اختبار
) into UTF-8 text (Example: a ä¸ Ð¯)
text box then you will see that it is actually اختبار
in Unicode.
To solve the problem, you need make sure that your files are saved in UTF-8.
Upvotes: 1
Reputation: 360
Salam @Hani, it looks like an encoding problem.
I tried to reproduce your case in my local computer, I copy paste your code and everything works as expected.
Check to see if your files messages.php
in resources/lang
are in a correct encoding format.
If they are, check the blade file.
You can also try to make a test route that only returns the translated string like so :
Route::get("test", function(){
return __("messages.test");
});
Upvotes: 1