Change date language

Is there a way to specify the language echoed by $page->date() ?

You can use

<?php echo strftime('%d/%m/%Y', $page->date()) ?>

http://php.net/manual/de/function.strftime.php

to set the format for the date, the language used by strftime depends on the locale settings . Also, Kirby 2.1 now allows to set the date handler to strftime as default in your config.php

c::set('date.handler', 'strftime');
1 Like

Wow! Thanks! Got that working (showing the month by it’s name) but it still shows in English, this setting in my config.php is supposed to default my locale to spanish right??

c::set('languages', array(
  array(
    'code'    => 'es',
    'name'    => 'Español',
    'default' => true,
    'locale'  => 'es_LA',
    'url'     => '/',
  ),
  array(
    'code'    => 'en',
    'name'    => 'English',
    'locale'  => 'en_US',
    'url'     => '/en',
  ),
));

Yes, with those settings you should automatically get the Spanisch name when on the Spanish site and English when in the English version.

Damn, then something’s not working right, is there a PHP function I can use to check if the locale is being set correctly?

I’m just trying to find out why it works on my site …

You can check the locale settings like so:

<?php echo setlocale(LC_ALL, 0); ?>

You could try to set the locale manually like so and check if this makes a difference:

<?php setlocale(LC_ALL, 'es_LA'); ?>

I couldn’t find any other settings than yours in my multi language sites.

Also, in your language settings, you can now set set each locale individually, from the changelog:

More flexible locale settings

You can now pass an array to Kirby's locale option to change each locale individually:

c::set('locale', array(
  LC_COLLATE  => 'tr_TR.utf8',
  LC_MONETARY => 'tr_TR.utf8',
  LC_NUMERIC  => 'tr_TR.utf8',
  LC_TIME     => 'tr_TR.utf8',
  LC_MESSAGES => 'tr_TR.utf8',
  LC_CTYPE    => 'en_US.utf8'
));
This also works for the locale setting in language setups.
<?php echo setlocale(LC_ALL, 0); ?>

This echoes a letter C, would you happen to know what it means?

Thanks a lot for your help!

Maybe the language is not supported on your server and you have to install it first. Is the result for the above the same no matter if you are on the Spanish or English version of the site?

Thanks for pointing that out! In English it does shows en_US, I’ll check the hosting settings.

Would you happen to know if this particular hosting problem has to do with the actual PHP software or is it more like a hosting issue?

No sorry, I can’t really help you with that. Hopefully, someone else here does.

Thanks a lot for your help!

One thing I would try just to make sure is what happens if you change your language settings to es_ES.

You can also try to add this to your .htaccess, at least it’s worth a try:

AddLanguage es .la

Changing my locale to Spanish Spanish like this…

'locale' => 'es_ES'

…did the trick for me.

Ideally, it would have been set to es_MX, but since the only locale-related code I have has to do with dates (which are exactly the same in MX and ES) I’m fine with it.

Or am I missing out on a consequence of having this inaccurately set?

2 Likes

Just to add that I later had to change my locale to:

'locale' => 'es_ES.UTF-8'

because accented characters weren’t displaying correctly in PHP 5.6 (PHP 7 was handling them fine with just es_ES)