toby
1 year ago

German locale on Windows Server 2008 causes problems w/ umlauts

Posted 1 year ago by toby

Hi!

I have a strange problem with locales (esp. umlauts) on a Windows Server; first, this is my setup:

  • Windows Server 2008 R2 Standard (OS is in German)
  • IIS 7.5
  • PHP Version 7.1.14 (x64)

So far, everything works just fine (mostly Laravel applications).

But as soon as I want to display a formatLocalized() w/ Carbon, nothing shows if the desired output contains an umlaut, e.g.:

// Given there is a $post with created_at = '2018-03-15 08:17:00';

$post->created_at->formatLocalized('%A, %e. %B %Y');
// expected output: Donnerstag, 15. März 2018

template code (show.blade.php)

<!-- USING {{  }}: -->

<p>{{ $post->created_at->formatLocalized('%A, %e. %B %Y') }}</p>
<!-- renders: -->
<p></p><!-- yup, null, nothing... -->
<!-- USING {!!  !!}: -->

<p>{!! $post->created_at->formatLocalized('%A, %e. %B %Y') !!}</p>
<!-- renders: -->
<p>Donnerstag, 15. M�rz 2018</p>
<!-- USING {{ utf8_encode() }} -->

<p>{{ utf8_encode($post->created_at->formatLocalized('%A, %e. %B %Y')) }}</p>
<!-- renders: -->
<p>Donnerstag, 15. März 2018</p>

With Homestead, I am able to to display everything as expected using the following snippet in my AppServiceProvider (I had to install the german locales first):

public function boot()
{
    setlocale(LC_ALL, 'de_DE.utf8');
}

Unfortunately, this does not work on a Windows server environment :(

I tried several values for the setlocale function, such as deu, german, de_DE, [email protected], but nothing worked...

Do you have any idea how I can display this properly w/o always using a utf8_encode()?!

Thanks in advance!

Please sign in or create an account to participate in this conversation.