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

toby's avatar
Level 31

German locale on Windows Server 2008 causes problems w/ umlauts

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, de_DE@euro, but nothing worked...

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

Thanks in advance!

0 likes
3 replies
ahmeddabak's avatar
Level 47

I had this problem in one of my projects, i only had a problem with März .

I used this method formatLocalized to display the date {!! $month->start_date->formatLocalized('%d. %B') !!}

In my AppServiceProvider i configured Carbon with the new local and encoding.

 Carbon::setLocale('de');
 Carbon::setUtf8(true);

And i worte this in the top of my bootstrap/app.php i don't remember why, i think it can work just fine in AppServiceProvider

setlocale(LC_TIME, "de",'german');

MfG

toby's avatar
Level 31

Perfect, thanks! Carbon::setUtf8(true); did the trick!

PS: Beste Grüße aus Duisburg ;)

1 like
Henrykarn's avatar

I also have a Problem with Locale and german umlauts, but not with Carbon.

I translated a string with umlauts from a form-input-field to lowercase with strtolower to search the database.

On my local dev-server it worked find and I found several results.

On my test-server I didn't find anything.

After some research I found, that strtolower doesn't convert umlauts if the locale isn't set correct.

So when I changed my code to mb_strtolower the problem was gone.

I'm a bit suprised, that setting the locale in config\app.php isn't enough to solve this problem.

1 like

Please or to participate in this conversation.