php setlocale arabic strftime - php

I've run locale -a on my server and can see that it's got Arabic locale settings installed:
ar_AE
ar_AE.iso88596
ar_AE.utf8
However, if I set the locale via:
$locale = array('ar_AE', 'ar_AE.iso88596', 'ar_AE.utf8', 'ar');
setlocale(LC_TIME, $locale);
and output it:
strftime('%A %d %B', $current_date)
The displayed date is in English, not Arabic.
Arabic is the only language this isn't working for: the site I'm working on is in 15 languages and all the others display a translated date.
What's going wrong?

This worked for me with no problems at all.
setlocale(LC_ALL, 'ar_AE.utf8');
If this does not work, then there is another code in your PHP file that interferes with the language.

Related

Dates in spanish App Engine Standard PHP 5.5

In my environment (App Engine Standard PHP 5.5) I have a problem with the language of the dates. I need to show them in Spanish, but I can not make it work.
In my local environment it is translated without problems, but in production it shows the dates in English.
In my php.ini I already put this:
date.timezone = "America / Argentina / Cordoba"
extension = "intl.so"
And in the code where I need to show the dates in Spanish (Argentina) I tried this:
setlocale(LC_TIME, 'es_AR.UTF-8', 'es_AR', 'es-AR');
echo strftime("%d de %B", strtotime($event_date));
and in this way also:
setlocale(LC_TIME, 'es_ES.UTF-8', 'es_ES', 'es-ES');
echo strftime("%d de %B", strtotime($event_date));
Am I doing something the wrong way?
Thank you very much

how to set date and time to dutch

I am using this simple script to test on my host which runs on php version 5.6.
The script gives the output "Wednesday" instead off "Woensdag"(dutch)
Why is the day of the week still in English and not in Dutch?
Is this because the server is not correct configured?
<?php
/* Set locale to Dutch */
date_default_timezone_set("Europe/Amsterdam");
setlocale(LC_ALL, 'nl_NL');
echo date("l"); // output: Wednesday instead off "Woensdag" (dutch)
?>
Unfortunately date is not multilingual. If you want to format a language in another language you need to set locale (as you did in your example) and use strftime
Formatting options for strftime do result in "Woensdag" (or "mittwoch in German, etc):
setlocale(LC_TIME, 'en_EN');
echo strftime('%A', time()); // for a Wednesday will output: Wednesday
setlocale(LC_TIME, 'nl_NL');
echo strftime('%A', time()); // for a Wednesday will output: woensdag
Unless you want al lot of things to be influenced by setlocale you might want to specify that you're doing this for time only (as in the example above). Read on setlocale for more info: http://php.net/manual/en/function.setlocale.php
Keep in mind you need to have the locales available on your machine for this to work. Check with locale -a on linux. setlocale has a return value. If it is false something went wrong and you're most likely missing the specified locale.

Set the Date / Time locale to de_AT instead of de_DE on Microsoft Azure Website (PHP)

I am currently developing a a Website that will be hosted on Microsoft Azure Websites. The client (as well as I) live in Austria and thus we would like to have the Austrian (German) locale for time and date - there is a small difference in the dates as we say "Jänner" instead of "Januar" for "January" and "Januar" sounds somewhat strange to an austrian. The standard snippet for returning a german date would be like so:
function ger_date($date){
date_default_timezone_set("Europe/Vienna");
setlocale (LC_ALL, 'de_DE.utf8','de_DE', 'de_DE#euro', 'german');
$longdate = strftime('%d. %B %Y', strtotime($date));
return $longdate;
}
The answer to this question is acutlly fairly simple. To have austrian or swiss date formats, you can change the locales to the corresponding languages.
function ger_date($date){
date_default_timezone_set("Europe/Vienna");
setlocale (LC_ALL, 'de_AT.utf8','de_AT', 'de_AT#euro', 'german_austria');
$longdate = strftime('%d. %B %Y', strtotime($date));
return $longdate;
}
for austrian
or
function ger_date($date){
date_default_timezone_set("Europe/Vienna");
setlocale (LC_ALL, 'de_CH.utf8','de_CH', 'de_CH#euro', 'german_switzerland');
$longdate = strftime('%d. %B %Y', strtotime($date));
return $longdate;
}
for swiss german. (note that there is not much difference in the regional format between german and switzerland)
But please note, that german_austria outputs Jänner, which sometimes can render as J�nner as the last locale ('german_austria', 'german' or 'german_switzerland') is not an UTF8 Locale and 'german-austria.utf8' is not available on my host.
If your system has no UTF-8 compatible locale installed and you can not install a nother one, you can simply wrap the strftime function into the utf8_encode() function from PHP and everything should work like a charm.

How do you translate the timezone abbreviation in PHP

When using the PHP to return the timezone abbreviation with either date('T') or strftime('%Z') the result does not translate to the localized version of these abbreviations.
In french I have been told the following at the correct translations:
EDT == HAE
EST == HNE
I have tried the following code example:
<?php
setlocale(LC_ALL, 'fr_FR');
echo strftime('%Z');
echo date('T');
?>
All attempts produce EST/EDT rather than the translated versions.
I get the same on Mac and Linux.
I inspected the Gettext MO file for French, like this:
/usr/local/bin/msgunfmt /usr/share/locale/fr/LC_MESSAGES/texinfo.mo
This shows all the translations for things like months and days.
So you should get translations if you do:
echo strftime("%A %e %B %Y\n");
// gives "Vendredi 27 juin 2014"
But the translation file does not appear to contain translations for EST, or EDT - or in fact any others I looked for.
So I guess the answer is that these strings are simply not translated in the standard locale packages.

Dreaded ???? instead of characters when displaying chinese text. Simplified Chinese Character issue

I am trying to produce a multilingual using Drupal 6. My site is hosted on a Windows IIS 7.5 Server.
I have gotten my .po files uploaded and everything works great. Im now at the stage where I am going through the site piece by piece to try and weed out anything that escaped my notice when I first translated teh site.
The problem I am having is in trying to display dates in locale formats.
Here is the php code I use to display a local date:
$format = "%A, %b %#d, %Y : %H:%M%p"
if($language->language == 'zh-hans')
{
$loc=setlocale(LC_TIME, 'chs');
}else{
$loc=setlocale(LC_TIME, 'de');
}
$mytime = strftime($format, $time);
$mytime = iconv(mb_detect_encoding($mytime), 'utf-8', $mytime);
echo $mytime;
The above code should display the date in the local format of the current language (chinese of german)
The german displays as expected:
Freitag, Jun 21, 2013 : 16:48
but the chinese output looks like this:
???, ?? 21, 2013 : 16:48??
Any ideas on how to fix this?
The first problem is that setting the LC_TIME category is not enough by itself. The strftime function will attempt to format the time in the appropriate language, but it seems to use the 1252 codepage by default, so it will be incapable of producing the necessary characters for something like Chinese.
I would have expected that setting LC_TIME and maybe LC_CTYPE would be enough, but the only way I could get it to work was with LC_ALL. So your setlocale calls should look like this:
if($language->language == 'zh-hans')
{
$loc=setlocale(LC_ALL, 'chs');
}else{
$loc=setlocale(LC_ALL, 'de');
}
The next problem is that mb_detect_encoding won't always detect the correct encoding. What works for me on Windows is to use setlocale(LC_CTYPE, 0) to get back the current code page.
$codepage = explode('.',setlocale(LC_CTYPE, 0));
$codepage = 'cp'.$codepage[1];
The value returned from the call to setlocale(LC_CTYPE, 0) is a combination of the language name and the codepage number separated by a dot. We split the two parts with explode and then prefix the number with cp to get the code page in a form that iconv can understand.
We can then simply convert the string to utf-8 like this:
$mytime = iconv($codepage, 'utf-8', $mytime);

Categories