WordPress contain language files that hold all of the messages and labels to translate into language.To convert text in another language is very easy in WordPress using the and also you can use multiple language translations.
I was developing WordPress application which language was not English and I wanted the date in another language.Specifically a month name and In that I want to localized month name and WordPress inbuilt functions does not support localized date format.
We can just simply handled this date issue with the use of setlocale() function.
Basic SYNTAX of setlocale
1 2 3 |
Parameters
$category : To convert a date into other language ,you need to set category parameter and its LC_TIME for date and time formatting with strftime() function
$locale : it’s for a different possible locale names
Let’s take one example which shows the difference if you switch from US locale (standard) to German locale.
1 2 3 | setlocale (LC_ALL, "de_DE"); //Setting the locale to German |
Above function may solve your issue with month names returned by the PHP date() function but produces much bigger and sometimes hidden problems.
It creates problems like, it may convert decimal float value into string values that can affect some calculation of site.
Here are the few more articles which you might like
Convert 12-hour datetime to 24-hour datetime in JavaScript
To create multiple date picker using jQuery
Once we set a locale, all the calls to the translator function will return strings according to the set locale value and we can set it with the use of strftime function.
Basic SYNTAX of strftime
1 2 3 |
Parameters
$category : format of the date you want
$locale : Here you require to pass timestamp so if you have date pass date with strtotime.
So, Let’s see one example for strftime which display date according to setlocale language
1 2 3 | echo strftime( "%h %y",strtotime("2011-12-22")); // Prints ‘Dez 2011’ month is in German |
strong>NOTE: The locale information(setlocale) is maintained per process, not per thread so maybe it is not working with your windows OS in the local server. If its not work with the local server, try it with the live server.
Comments (2)