Jump to content

Dates on my website are in German instead of Italian, how do I change this?


Recommended Posts

Hi, I am not a professional programmer and this is the first time I use pw.
I also did not create the website in the first place so I wonder if I should have pw downloaded on my laptop instead of just editing from the admin webpage.

The website is in English and Italian. Dates in English work fine but when I switch to Italian the dates are shown in German (15 Juli instead of 15 Luglio).
I read other topics including this one https://processwire.com/talk/topic/4469-output-date-language/
However, I do not know how to reach config.php to try and solve it that way, since I am a beginner.

Does anybody happen to know how to fix this?
Thank you.

Link to comment
Share on other sites

You have to set and use the correct locale for italian. Please read this post 

 and set the C setting to "it_IT" or the locale that you found with the script from the first post. How to do it is written in the comment "Warning about Server Locale after update from 3.0.52 > 3.0.53 - Help! - Page 2 - General Support - ProcessWire Support Forums" .

Link to comment
Share on other sites

On 6/13/2021 at 3:45 AM, dotnetic said:

You have to set and use the correct locale for italian. Please read this post 

 and set the C setting to "it_IT" or the locale that you found with the script from the first post. How to do it is written in the comment "Warning about Server Locale after update from 3.0.52 > 3.0.53 - Help! - Page 2 - General Support - ProcessWire Support Forums" .

Hi, first of all thank you for your reply.
I will attach the screenshots of what I tried after reading the posts.
I must have done something wrong because nothing changes when I save.

Screenshot (20).png

Screenshot (22).png

Link to comment
Share on other sites

As I mentioned you have to check if the correct locale is installed first. Because if you set it in ProcessWires "C" setting to it_IT or it_IT@euro and the locale is not installed, then you don't get the localized dates. And I forgot that you have to use strftime to get a localized date. You can find a description later in this post.

The easiest way to check what locales are installed is to run `locales -a` if you have shell access (SSH for example).

If this is not possible, then you have to modify my script from the first post and insert different values for italian there.

<?php
echo '<h1>test for locales</h1>';

/* try different possible locale names for italian GB as of PHP 4.3.0 */
echo '<p>';
$loc_it = setlocale(LC_ALL, 'it_IT', 'it_IT@euro', 'it_IT.UTF-8');
echo "Preferred locale for italian on this system is '$loc_it'";
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));

function smarty_modifier_number_format( $string, $decimals = 2 )
{
	$locale = localeconv();
	// setlocale( LC_NUMERIC, null );
	$string = str_replace(',', '.', $string);
	$thousand_separator = ( $locale['thousands_sep'] == '' ) ? '.' : $locale['thousands_sep'];
	$decimal_separator = $locale['decimal_point'];
	return @utf8_encode(number_format( $string, $decimals, $decimal_separator, $thousand_separator ));
}

echo "<br>";

echo smarty_modifier_number_format('12,90 g');

If you run it then, and the preferred locale is not an italian one, then an italian locale might be missing on the system and you have to tell your host to install it, if that is possible.

When switching languages, you have to set the locale for example in your _init.php

setlocale(LC_ALL, 'it_IT', 'it_IT.UTF-8', 'it_IT@euro');

and then to get a localized date you have to use the strftime function or ProcessWire's date method (which can be formatted using strftime) for output.

If the italian locale is missing, you could use a custom PHP function that returns dates in your language.

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...