Jump to content

Recommended Posts

Posted

Hi,

I'm using

$date = utf8_encode(strftime('%d. %B %Y', $child->getUnformatted('date')));

to render dates from a datefield in German. If the date contains umlauts like "March" which is "März" in German it renders a weird charakter and capitalises the "Ä":

<span class="date">14. März 2014</span>

The admin is not localised, the entry in the datefield is: 14 March 2014 3:23 pm

Any ideas? Thanks.

Posted

I'm not sure if you already are using setlocale somewhere, But you could try setting it like this:

setlocale(LC_ALL, "de_DE.UTF-8");

instead of:

setlocale(LC_ALL, "de_DE");
Posted

Many thanks for your reply Raymond,

I already have 

setlocale(LC_ALL, "de_DE.UTF-8");

in my config.php. Sorry for not mentioning it.

  • Like 1
Posted

It's a guess here, maybe it's helpfull.

Looks like it has something to do with encodings. Did you copy & paste in some codes as that could leave some artefacts.

If you're on the mac, use TextWrangler/BBedit and use the command 'Zap Gremlins'.

Or what is also worth trying:

1. copy the code to a textarea.

2. create a new document.

3. copy the code from the textarea to the new document.

Posted
I and another developer friend have also struggled with this problem on a few sites with different hosting companies. There was a previous post about issues with umlauts and dates but I never found a workable solution. It is either a bug with Processwire or an issue with the hosting company and how they have configured the server (from what I remember, it does not seem to happen in local development). 

My hack around it was to create a little function that checked for March and assigned it the correct März - something like this :



$monthNumber = strftime("%m", $child->getUnformatted("dates"));

if($monthNumber == 3){
$monthName = 'März';
}
else {
$monthName = strftime("%B", $child->getUnformatted("dates"));
}

Posted

Did you copy & paste in some codes as that could leave some artefacts.

I did import a XML file with the new wordpress importer. As I have > 80 posts I can't correct them by hand.

What leaves me clueless is that even if I set the date say to today, save the page, and then set it agin to somewhere in march the problem remains the same.

@michael

you posted while I was replying to Martijn. I'll give your solution a try. Sounds promising. Thanks.

Posted

Why do you use utf8_encode? Should be working without it. Or try htmlentities()

Edit:

Only for you a special service:

Bildschirmfoto 2014-05-27 um 16.21.32.png

The code of this:

<html>
<head>
    <meta charset="utf-8">
    <title></title>

    
</head>
<body>
    
    

<?php 

setlocale(LC_ALL, "de_DE.UTF-8");
echo 'Using utf8_encode:<br>';

$date = utf8_encode(strftime('%d. %B %Y', 1395929985));
echo $date;

echo '<br><br>Without utf8_encode:<br>';

$date = strftime('%d. %B %Y', 1395929985);
echo $date;

echo '<br><br>Without utf8_encode and with htmlentities():<br>';

$date = htmlentities(strftime('%d. %B %Y', 1395929985));
echo $date;

?>

    </body>
    </html>

Edit 2:

Here is the resulting source code:


<html>
<head>
    <meta charset="utf-8">
    <title></title>

    
</head>
<body>
    
    

Using utf8_encode:<br>27. März 2014<br><br>Without utf8_encode:<br>27. März 2014<br><br>Without utf8_encode and with htmlentities():<br>27. März 2014

    </body>
    </html>

post-140-0-19453400-1401200526_thumb.png

  • Like 5
Posted

@nico

Why do you use utf8_encode? Should be working without it.

Thanks, that does the trick!

  • Like 1
  • 2 years later...
Posted

Very strange.

On one site it works using:

<? setlocale(LC_ALL, "de_DE.UTF-8"); ?>
<?=strftime('%e. %B %Y', $page->getUnformatted('mydate')); ?>

on the other site i have to use:

<?=utf8_encode(strftime('%e. %B %Y', $page->getUnformatted('mydate'))); ?>

 

Is that an error in processwire? Or a matter of the webserver settings?

Posted
2 hours ago, matjazp said:

Is de_DE.UTF-8 locale installed on the other site?

What do you mean by "installed" ... where can i check this?
 

Posted
42 minutes ago, tires said:

What do you mean by "installed" ... where can i check this?
 

On the command line, type: 

locale -a

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...