0

I've got a weird case of a BOM character (%EF%BB%BF) getting prepended to the output of the localization function __($key) in Laravel 5.5

The strange part is that in two subsequent calls of the same function, one will yield the correct result, and the other one won't.. I've opened all my files in Notepad++ displaying all characters, nothing stands out.. I've literally copied the second (correct) line and pasted it in place of the first (incorrect) line - with still the same result!

I'm basically trying to localize the routes being used ($uLng is either 'fr' or 'en') - and a few links are directing towards a specific anchor on the page, which I localized using __()

Here is the code of my view:

<a class="floatingMenuLink" href="{{ route('public_features.' . $uLng) }}#{{ __('pub_how_it_works.routeIdSecurity') }}">{{ __('global.publicMenuSecurity') }}</a>
<a class="floatingMenuLink" href="{{ route('public_features.' . $uLng) }}#{{ __('pub_how_it_works.routeIdSecurity') }}">{{ __('global.publicMenuSecurity') }}</a>

Pretty similar right?

The first link generated is : http://localhost/fonctionnement#%EF%BB%BFsecurite

The second link generated is : http://localhost/fonctionnement#securite

Further testing shows that:

  • using a different key (ie 'pub_how_it_works.foo' instead of 'pub_how_it_works.routeIdSecurity') yields the same issue for the first link
  • replacing the __() function by static text resolves the issue

So.. I really think the problem comes from localization, but I have no clue how to solve it..

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Buno
  • 597
  • 1
  • 9
  • 20

1 Answers1

0

After a lot more head-banging and investigation - the problem comes from the language files, which are encoded in UTF8 with BOM.

I use Excel to maintain my translations repository and have a small macro to generate the 'lang' files - and turns out it writes in UTF8 BOM by default. I used this solution to solve the issue.

Buno
  • 597
  • 1
  • 9
  • 20