downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

sha1_file> <rtrim
[edit] Last updated: Fri, 23 Mar 2012

view this page in

setlocale

(PHP 4, PHP 5)

setlocaleYereli ayarlar

Açıklama

string setlocale ( int $sınıf , string $yerel [, string $... ] )
string setlocale ( int $sınıf , array $yerel )

Yerel bilgisini ayarlar.

Değiştirgeler

sınıf

sınıf olarak yerel ayarıyla ilgili belli bir işlevsellik belirten şu sabitlerden biri belirtilebilir:

  • LC_ALL - aşağıdakilerin hepsi.
  • LC_COLLATE - dizge karşılaştırması için; strcoll() işlevine bakınız.
  • LC_CTYPE - karakter sınıflaması ve dönüşümü için; bir örnek olarak strtoupper() işlevine bakınız.
  • LC_MONETARY - Para biçemlemesi için; bkz, localeconv().
  • LC_NUMERIC - ondalık ayraçlar için; bkz, localeconv().
  • LC_TIME - tarih ve saat biçemlemesi için; bkz, strftime()
  • LC_MESSAGES - sistem iletileri için (PHP libintl ile derlendiği takdirde kullanılabilir).

yerel

Eğer NULL belirtilirse veya "" şeklinde boş bir dizge belirtilmişse, yerel isimleri yukarıdaki sınıflarla aynı isimdeki ortam değişkenlerinden veya "LANG" ortam değişkeninden alınır.

Eğer yerel "0" ise, yerel ayarı değiştirilmeden mevcut ayar döndürülür.

Eğer yerel bir dizi ise veya ek değiştirgeler belirtilmişse, yeni yerel başarıyla ayarlanana kadar belirtilen her dizi elemanı veya her değiştirge tek tek denenir. Yerel isimlerinin farklı sistemlerde farklı isimlerde bulunması durumunda veya kullanılabilir yerelin bulunamaması olasılığına karşı son çareleri belirtmek için kullanılır.

...

Yerel ayarları başarılı olana kadar denenecek seçimlik dizi veya dizge.

Bilginize:

Windows'ta, setlocale(LC_ALL, '') kullanımında, sistemin bölgesel ayarlar/dil ayarlarında (Denetim Masasından erişilebilir) belirtilmiş yerelin ismi kullanılır.

Dönen Değerler

Ayarlama yapılabilmişse yeni yerel ismi, platformunuzda yereller işlevsel değilse, belirtilen yerel yoksa veya sınıf ismi geçersizse FALSE döner.

Geçersiz bir sınıf ismi ayrıca bir uyarı üretilmesine sebep olur. Sınıf ve yerel isimleri » RFC 1766 ve » ISO 639'da bulunabilir. Farklı sistemler yereller için farklı isimleme şemaları kullanırlar.

Bilginize:

setlocale() işlevinin dönüş değeri PHP'nin üzerinde çalıştığı sisteme bağlıdır. Sistemin setlocale işlevinin döndürdüğü değeri döndürür.

Sürüm Bilgisi

Sürüm: Açıklama
5.3.0 sınıf değiştirgesinde LC_* sabitlerinden biri yerine bir dizge aktarılırsa işlev artık bir E_DEPRECATED uyarısı çıktılamaktadır.
4.3.0 Çok sayıda yerel belirtilebilir oldu.
4.2.0 sınıf olarak bir dizge aktarılması artık önerilmiyor. Dizge değil yukarıdaki sabitlerin kullanılması gerekiyor. Bu sabitlerin bir dizge olarak (tırnak içinde) belirtilmesi artık bir uyarıya sebep olmaktadır.

Örnekler

Örnek 1 - setlocale() örnekleri

<?php
/* Yereli Türkçe yapalım */
setlocale(LC_ALL'tr_TR.UTF-8');

/* Çıktısı: 22 Aralık 1978 Cuma */
echo strftime("%e %B %Y %A\n"mktime(00012221978));

/* Türkçe için farklı yerel isimleri deneyelim (PHP 4.3.0 ve sonrası) */
$loc_tr setlocale(LC_ALL'tr_TR.UTF-8''tr_TR''tr''turkish');
echo 
"Türkçe için tercih edilen yerel ismi: '$loc_tr\n'";
?>

Örnek 2 - Windows için setlocale() örnekleri

<?php
/* Yereli Felemenkçe yapalım */
setlocale(LC_ALL'nld_nld');

/* Çıktısı: vrijdag 22 december 1978 */
echo strftime("%A %d %B %Y"mktime(00012221978));

/* Almanca için farklı yerel isimleri deneyelim (PHP 4.3.0 ve sonrası) */
$loc_de setlocale(LC_ALL'de_DE@euro''de_DE''deu_deu');
echo 
"Almanca için tercih edilen yerel ismi: '$loc_de'";
?>

Notlar

Uyarı

Evre başına değil süreç başına yerel bilgisi ayarlanır. Windows üzerinde Apache veya IIS gibi çok evreli bir sunucu çalıştırıyorsanız, betiğinizde setlocale() işlevini hiç çağırmadığınız halde yerel ayarlarında ani değişiklikler olduğunu gözlemlemişsinizdir. Bunun sebebi aynı anda aynı süreç altında başka evrelerde başka betiklerin çalışması ve bunların süreç genelinde geçerli olan setlocale() kullanımlarıdır.

İpucu

Windows kullanıcıları Microsoft'un MSDN sitesinde yerel dizgeleri hakkında bilgi bulabilirler. Desteklenen dil dizgeleri »  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_language_strings.asp adresinde desteklenen ülke/bölge dizgeleri ise »  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_country_strings.asp adresinde bulunabilir.



sha1_file> <rtrim
[edit] Last updated: Fri, 23 Mar 2012
 
add a note add a note User Contributed Notes setlocale
qeremy 23-May-2012 11:20
Be careful when using this "demon" function, or it'll waste your time cos' of a hidden problem...

What?

If you use this function in a file that included to all project, and if you write functions like this getUID(), getMyImageSize, getIIIIII etc... then I think you have a problem at this point.

Let me explain;

the_master.php // included to all project and contains this line;

<?php
setlocale
(LC_ALL, "tr_TR.UTF-8");

// and after many function defined in these lines, i.e.;

function getUID() {
   return (int)
$_SESSION["user_id"];
}
?>
...
...

Let's call our function, but...
<?php
$user_id
= getUID();
?>

Fatal error: Call to undefined function getUID() in /var/www/...

Yes, we screw up all project. :)

Actually, I don't know what is the exact problem here but I know the solution.

SOLUTION:

1. Do not use "I" (capital "i") character in any function name
or
2. Simply use setlocale like this;  setlocale(LC_TIME, "tr_TR.UTF-8") // I need just locale time config and used this

So, why not use capital i?

I tested a few function name like getUİD(). Yes, it works! (capital i in Türkish İ). But İ thİnk, many programmer have not thİs char İn theİr keyboards. :)

Additionally, if you use this char in any const name or var name (such as $UID = getuid();) also your var's and const's will be undefined...
Ludovico Grossi 17-Apr-2012 01:15
Please note that LC_NUMERIC (or LC_ALL) will convert the decimal separator every time you put it in a string, EVEN IF THE STRING IS A QUERY.
This is a problem for every locale that uses the comma as a decimal separator. Look at this example:

<?php
setlocale
(LC_ALL, "it_IT"); // locale with comma for decimals
$decimal_number = 0.5;
$query = "SELECT * FROM Table WHERE decimal_field > ".(float)$decimal_number; // casting to float is useless, since the conversion to a string is done after
?>

Then, the query fill fail because it will be converted to:

SELECT * FROM Table WHERE decimal_field > 0,5
(note the comma!)

I suggest to be sure that LC_NUMERIC is set to a standard locale, then use other formatting functions to display formatted numbers when needed.

<?php
setlocale
(LC_ALL, 'it_IT');
setlocale(LC_NUMERIC, 'en_US'); // let's overwrite the decimal separator
?>
russ at eatmymonkeydust dot com 08-Dec-2011 03:45
If you are looking for a getlocale() function simply pass 0 (zero) as the second parameter to setlocale().

Beware though if you use the category LC_ALL and some of the locales differ as a string containing all the locales is returned:

<?php
echo setlocale(LC_ALL, 0);

// LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;
// LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C

echo setlocale(LC_CTYPE, 0);

// en_US.UTF-8

setlocale(LC_ALL, "en_US.UTF-8");
echo
setlocale(LC_ALL, 0);

// en_US.UTF-8

?>

If you are looking to store and reset the locales you could do something like this:

<?php

$originalLocales
= explode(";", setlocale(LC_ALL, 0));
setlocale(LC_ALL, "nb_NO.utf8");

// Do something

foreach ($originalLocales as $localeSetting) {
  if (
strpos($localeSetting, "=") !== false) {
    list (
$category, $locale) = explode("=", $localeSetting);
  }
  else {
   
$category = LC_ALL;
   
$locale   = $localeSetting;
  }
 
setlocale($category, $locale);
}

?>

The above works here (Ubuntu Linux) but as the setlocale() function is just wrapping the equivalent system calls, your mileage may vary on the result.
ts at websafe dot pl 09-Oct-2011 05:54
If Your linux box returns false on setlocale (so setlocale is not working as expected):

var_dump(setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8'));

make sure the glibc package is installed :-)
phcorp 26-Jul-2011 06:16
To find the locale of a Unix system:
<?php system('locale -a') ?>
flavioacvalverde at gmail dot com 15-Jun-2011 09:28
For Portugal I had to use

<?php setlocale(LC_ALL, 'Portuguese_Portugal.1252'); ?>

using php with IIS on Windows server.
tomas dot hampl at gmail dot com 23-Apr-2011 01:35
On Linux, setlocale() depends on the installed locales. To see which locales are available to PHP, run this from the terminal:

"locale -a"

Provided list are all locales that are available on your server for PHP to use. To add a new one, run

locale-gen <locale name> (this may need sudo / root permissions), for example to add a Czech locale, run something like this:

"sudo locale-gen cs_CZ.utf8"

Then you can use this locale declaration:

setlocale(LC_ALL, 'cs_CZ.utf8');
leif at neland dot dk 16-Aug-2010 04:38
Regarding dash'es in locale, it appears they should be omitted entirely.

In /etc/locale.gen I have

da_DK.ISO-8859-15 ISO-8859-15

but locale -a gives

da_DK.iso885915

which is the format setlocale()  wants.

(Debian)
garygendron at yahoo dot com 28-Jun-2010 08:04
For a php Mysql query, you could also use, for french canadian, in this example :

$query = 'SET lc_time_names = "fr_CA"';
$result = mysql_query($query) or die("Query failed");

$query = 'SELECT @@lc_time_names';
$result = mysql_query($query) or die("Query failed");

$query = 'SELECT id, created, YEAR(created) as year, MONTH(created) as month,' .
' CONCAT_WS(" ", MONTHNAME(created), YEAR(created)) as archive' .           
' FROM #__TABLE as e' .
' GROUP BY archive' .
' ORDER BY id DESC';

Your data will be displayed in any locale setting you want. You may even $_GET[lc_time_name] from your multilanguage website.
Omer Sabic 21-Mar-2010 07:27
On Linux/Apache, when you install and try to use a new locale, the setlocale() function with the new locale will fail sometimes, but not always. To furthermore complicate, setlocale() will always complete with any of the previously installed locales. This would seem a really weird behaviour, which you can fix by restarting Apache, as Kari Sderholm aka Haprog mentioned, but I felt it needed to be properly pointed out.
Kari Sderholm aka Haprog 16-May-2009 04:28
It took me a while to figure out how to get a Finnish locale correctly set on Ubuntu Server with Apache2 and PHP5.

At first the output for "locale -a" was this:
C
en_US.utf8
POSIX

I had to install a finnish language pack with
"sudo apt-get install language-pack-fi-base"

Now the output for "locale -a" is:
C
en_US.utf8
fi_FI.utf8
POSIX

The last thing you need to do after installing the correct language pack is restart Apache with "sudo apache2ctl restart". The locale "fi_FI.utf8" can then be used in PHP5 after restarting Apache.

For setting Finnish timezone and locale in PHP use:
<?php
date_default_timezone_set
('Europe/Helsinki');
setlocale(LC_ALL, array('fi_FI.UTF-8','fi_FI@euro','fi_FI','finnish'));
?>
wisborg 27-Apr-2009 05:06
It is correct as stated below that it is common that the UTF-8 should be used without the dash. However on some systems (e.g. MacOS 10.4) the dash is essential.
brice/axice/be 20-Feb-2009 05:19
Pay attention to the syntax.
- UTF8 without dash ('-')
- locale.codeset and not locale-codeset.

Stupid newbie error but worth knowing them when starting with gettext.

<?php
$codeset
= "UTF8"// warning ! not UTF-8 with dash '-'
       
// for windows compatibility (e.g. xampp) : theses 3 lines are useless for linux systems

putenv('LANG='.$lang.'.'.$codeset);
putenv('LANGUAGE='.$lang.'.'.$codeset);
bind_textdomain_codeset('mydomain', $codeset);

// set locale
bindtextdomain('mydomain', ABSPATH.'/locale/');
setlocale(LC_ALL, $lang.'.'.$codeset);
textdomain('mydomain');
?>

where directory structure of locale is (for example) :
locale/fr_FR/LC_MESSAGES/mydomain.mo
locale/en_US/LC_MESSAGES/mydomain.mo

and ABSPATH is the absolute path to the locale dir

further note, under linux systems, it seems to be necessary to create the locale at os level using 'locale-gen'.
bardouty at gmail dot com 06-Jan-2009 03:44
For Apache on Windows (wamp), or Linux RedHat (lampp):
if you expect the locale from the environment of PHP process instead of defining it by your code, you shall request the value of locale with setlocale and a null value.
On windows it is defined in system, not as an env variable, so you cannot see it with getenv(), but the behavior is the same : print with a decimal number with "," if requesting the locale, with "." otherwise.

This is different from the red warning above about locale set by another thread.
It seems that unless you request the setlocale, the locale conv array is not set with the environment. As a result the formatting of numbers is not following the locale in environment.

<?php
print getenv("LANG");
print
$_ENV['LANG'];
print
"calling localeconv() directly\n";
print_r(localeconv());
printf("%f",-123.456);
print
"\ncalling setlocale() before localeconv()\n";
print(
setlocale(LC_ALL,null));
print_r(localeconv());
printf("%f",-123.456);
?>
calling localeconv() directly
Array
(
    [decimal_point] => .
    [thousands_sep] =>
    [int_curr_symbol] =>
    [currency_symbol] =>
    [mon_decimal_point] =>
    [mon_thousands_sep] =>
    [positive_sign] =>
    [negative_sign] =>
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
        )

)
-123.456000
calling setlocale() before localeconv()
French_France.1252
Array
(
    [decimal_point] => ,
    [thousands_sep] => 
    [int_curr_symbol] => EUR
    [currency_symbol] => €
    [mon_decimal_point] => ,
    [mon_thousands_sep] => 
    [positive_sign] =>
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 0
    [p_sep_by_space] => 1
    [n_cs_precedes] => 0
    [n_sep_by_space] => 1
    [p_sign_posn] => 1
    [n_sign_posn] => 1
    [grouping] => Array
        (
            [0] => 3
        )

    [mon_grouping] => Array
        (
            [0] => 3
        )

)
-123,456000
Un_passant 16-Nov-2008 03:56
For debian/ubuntu, don't forget the charset UFT8.

// Works on Ubuntu 8.04 Server
setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8');
benny at bennyborn dot de 09-Oct-2008 04:24
I had the problem (Debian), that the language de_DE was installed, but setlocale always returned false. I installed the language AFTER compiling PHP - that was the point. If you add some languages afterwards, you have to recompile php ;)
Charlo Dante 07-Oct-2008 02:23
Edwin Martin wrote already a note for Debian users, but it didn't work for me.

What DID work was this:

apt-get install locales-all

which installs more than the same apt-get without the '-all'

With 'locales-all' I got all languages running well.
Leigh Morresi 01-Oct-2008 11:27
Setting locale that is not supported by your system will result in some string operations returning a question mark "?" in your strings where it needs to perform transliteration.

1) Always check the return of setlocale() to ensure it has set to something supported

2) on Linux you can use the "locale -a" command to find a list of supported locales
alvaro at demogracia dot com 22-Sep-2008 09:33
A generalization for mk (26-Jan-2004) and totu (09-Sep-2002). The issue is not restricted to MySQL. For instance, when PHP needs to cast a floating point variable to string, it obeys the LC_NUMERIC settings:

<?php

$foo
= 29.95;

echo
"Locale: " . setlocale(LC_NUMERIC, 0) . "\n";
echo
"Foo: $foo\n";

setlocale(LC_NUMERIC, 'Spanish_Spain.28605');
echo
"Locale: " . setlocale(LC_NUMERIC, 0) . "\n";
echo
"Foo: $foo\n";

?>

Under Windows, this code prints:

Locale: C
Foo: 29.95
Locale: Spanish_Spain.28605
Foo: 29,95
buana95 at yahoo dot com 21-Aug-2008 10:30
This will works for Indonesian on all platform (Windows, Linux and others Nix server):

<?php
echo '<pre>' . "\n";

//Add english as default (if all Indonesian not available)

setlocale(LC_ALL, 'id_ID.UTF8', 'id_ID.UTF-8', 'id_ID.8859-1', 'id_ID', 'IND.UTF8', 'IND.UTF-8', 'IND.8859-1', 'IND', 'Indonesian.UTF8', 'Indonesian.UTF-8', 'Indonesian.8859-1', 'Indonesian', 'Indonesia', 'id', 'ID', 'en_US.UTF8', 'en_US.UTF-8', 'en_US.8859-1', 'en_US', 'American', 'ENG', 'English');

//will output something like: Minggu, 17 Agustus 2008
echo strftime("%A, %d %B %Y") . "\n";

echo
'</pre>' . "\n";
?>
Arjon 27-Jul-2008 09:12
Please take heed and read the warning above if you are running on a XAMPP or any other Windows apache server! It just took me far too long to figure this out; and all the while there was a warning right on the page.

If you're experiencing shifting locale settings (check with setlocale(LC_ALL,0), returning the current locale stuff) and you're running a windows server, then it's not just you! Again, I urge everyone to read the red, but oh so easy not to read, warning message on this page.
michal dot kocarek at brainbox dot cz 27-Jul-2008 08:33
Note about using UTF-8 locale charset on Windows systems:

According to MSDN, Windows setlocale()'s implementation does not support UTF-8 encoding.

Citation from "MSDN setlocale, _wsetlocale" page (http://msdn.microsoft.com/en-us/library/x99tb11d.aspx):
The set of available languages, country/region codes, and code pages includes all those supported by the Win32 NLS API except code pages that require more than two bytes per character, such as UTF-7 and UTF-8. If you provide a code page like UTF-7 or UTF-8, setlocale will fail, returning NULL.

So basically, code like
<?php setlocale(LC_ALL, 'Czech_Czech Republic.65001'); // 65001 is UTF-8 codepage ?>
does not work on Windows at all.

(written in time of PHP 5.2.4)
de ronino at kde (reverse it) 25-Jun-2008 02:43
I experienced the behavior stated in the above Warning box: Running PHP5 on a multithreaded Apache made the current locale change sometimes all of a sudden within a script, so strftime() output wasn't in the required format.

I recompiled Apache with the prefork MPM and now it works like a charm. Took me a long time to find out the reason as I overlooked the warning box searching for either a bug report or a programming error of mine...
jonas at jonashaag dot de 27-May-2008 12:11
On Ubuntu, you have to take p.e. "de_DE.utf8", all available languages you can get with:
    locale -a
Georg 04-Apr-2008 01:31
To set locale to 'de_DE' on my Debian 4 machine I had to:
- uncomment 'de_DE' in file /etc/locale.gen and afterwards
- run locale-gen from the shell
bryn AT lunarvis DOT com 21-Jan-2008 05:04
Posting this in the hope it might be useful to others, as I could find very little info anywhere. If you want to use a Welsh locale and have the suitable language support installed, you pass 'cym' (abbreviated form of Cymraeg) to setlocale:

<?php
setlocale
(LC_TIME, 'cym');
$welsh= gmstrftime("%A, %B %Y - %H:%M",time());
echo
$welsh;
?>

The above certainly applies to Windows systems, but should also apply to Unix if the required support is installed.

Cheers,

Bryn.
ostapk 27-Dec-2007 02:39
There is a new PECL extension under development called intl (it will be available in PHP5.3). Meanwhile all who rely on the setlocale() and friends should be aware about the limitations of them as covered in this post on the onPHP5.com blog: http://www.onphp5.com/article/22
Periklis 13-Sep-2007 02:33
In *some* Windows systems, setting LC_TIME only will not work, you must either set LC_ALL or both LC_CTYPE and LC_TIME. BUT if you have already set LC_TIME using setlocale earlier in the script, dates will not be affected! For example:
<?php
setlocale
(LC_TIME, 'greek');
setlocale(LC_CTYPE, 'greek');
?>
will not work, while
<?php
setlocale
(LC_CTYPE, 'greek');
setlocale(LC_TIME, 'greek');
?>
will do the job.
mvanbaak 09-May-2007 05:03
To complement Sven K's tip about debian:

You can also install the package locales-all
That one holds all the locales there are in compiled form.
szepeshazi at gmail dot com 18-Feb-2007 07:11
For those of you who are unfortunate enough (like me) to work in Windows environment, and try to set the locale to a language _and_ to UTF-8 charset, and were unable to do it, here is a workaround.

For example to output the date in hungarian with UTF-8 charset, this will work:

    $dateString = "%B %d., %A";
    setlocale(LC_ALL,'hungarian');
    $res=strftime($dateString);
    echo(iconv('ISO-8859-1', 'UTF-8', $res));

If anybody knows how to set the locale on Windows to the equivalent of "hu_HU.UTF-8" on unix, please do tell me.
lifeless 20-Nov-2006 09:40
if your server is an ubuntu (debian like)
you need to install the locales you want (default is english and your language) go to aptitude and install -language-pack-*-base it will resolve dependencies and will try to install a suggested package, remove it if you don't care and proceed.
Clayton Smith 26-Sep-2006 11:15
If you already have all the locales installed and "locale -a" is only showing a few languages, then edit /etc/locale.gen and add a line, e.g., es_MX ISO-8859-1.  After you add the line, run the command locale-gen for it to generate the locales based on those settings.
Sven K 07-Jun-2006 03:08
If your system doesn't show any installed locales by "locale -a", try installing them by "dpkg-reconfigure locales" (on debian).
08-Mar-2006 12:17
The example from bruno dot cenou at revues dot org below shows the possibility, but I want to spell it out: you can add charset info to setlocale.

Example:

Into my utf-8-encoded page I want to insert the name of the current month, which happens to be March, in German "März" - with umlaut. If you use

   setlocale(LC_TIME, 'de_DE');
   echo strftime("%B");

this will return "M&auml;rz", but that html-entity will look like this on a utf-8 page: "M?rz". Not what I want.

But if you use

   setlocale(LC_TIME, 'de_DE.UTF8');  // note the charset info !
   echo strftime("%B");

this returns "M√§rz", which, on utf-8, looks like it should: "März".
bruno dot cenou at revues dot org 20-Feb-2006 06:31
A little function to test available locales on a sytem :

<?php
function list_system_locales(){
   
ob_start();
   
system('locale -a');
   
$str = ob_get_contents();
   
ob_end_clean();
    return
split("\\n", trim($str));
}

$locale = "fr_FR.UTF8";
$locales = list_system_locales();

if(
in_array($locale, $locales)){
        echo
"yes yes yes....";
}else{
        echo
"no no no.......";
}

?>
Edwin Martin 20-Feb-2006 04:29
Debian users: Addition to Gabor Deri's note: if setlocale doesn't work in your locale and you're on Debian, and Gabor Deri's note doesn't work, you have to install the locales package.

As root, type: "apt-get install locales" and it will be installed.
glenn at europlan dot no 29-Nov-2005 11:55
In most Unix/Linux system, you could use:

locale -a

This will list all available locales on the server.
birkholz at web dot de 14-Aug-2005 08:42
When i tried to get the current locale (e.g. after i set the lang to german with setlocale(LC_ALL, 'de_DE'); ), the following did not work on my suse linux 9.0-box:
$currentLocale = setlocale(LC_ALL, NULL);
This code did a reset to the server-setting.

$currentLocale = setlocale(LC_ALL, 0); works perfectly for me, but the manual says NULL and 0 are equal in this case, but NULL seems to act like "".
pigmeu at pigmeu dot net 18-Oct-2004 01:42
!!WARNING!!

The "locale" always depend on the server configuration.

i.e.:
When trying to use "pt_BR" on some servers you will ALWAYS get false. Even with other languages.

The locale string need to be supported by the server. Sometimes there are diferents charsets for a language, like "pt_BR.utf-8" and "pt_BR.iso-8859-1", but there is no support for a _standard_ "pt_BR".

This problem occours in Windows platform too. Here you need to call "portuguese" or "spanish" or "german" or...

Maybe the only way to try to get success calling the function setlocale() is:
setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese", ...);

But NEVER trust on that when making functions like date conversions or number formating. The best way to make sure you are doing the right thing, is using the default "en_US" or "en_UK", by not calling the setlocale() function. Or, make sure that your server support the lang you want to use, with some tests.

Remember that: Using the default locale setings is the best way to "talk" with other applications, like dbs or rpc servers, too.

[]s

Pigmeu
dv at josheli dot com 12-Aug-2004 04:04
On Novell Netware, the language codes require hyphens, not underscores, and using anything other than LC_ALL doesn't work directly.

So... (from their support list)....

You have to set TIME, NUMERIC etc. info in two steps as given below rather than one. This is due to the limitation of setlocale function of LibC.
<?php
   setlocale
(LC_ALL, 'es-ES');
  
$loc = setlocale(LC_TIME, NULL);
   echo
strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
 
// jeuves 22 diciembre 1978
?>
This should work.

or of course, reset LC_ALL...
<?php
setlocale
(LC_ALL, 'es-ES');
echo
strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
setlocale(LC_ALL, '');
// jeuves 22 diciembre 1978
?>
bogdan at iHost dot ro 02-Mar-2004 02:53
On some systems (at least FreeBSD 4.x) the format for a `locale' is, for example, ro_RO.ISO8859-2. If you use ro_RO instead setlocale will return FALSE. Just browse in /usr/share/locale and see what is the name of the directory holding your `locale' and use that name in your scripts:

<?php
  clearstatcache
();
 
$pos = strrpos ($_SERVER["PHP_SELF"], "/");
 
$fisier = substr ($_SERVER["PHP_SELF"], $pos + 1);
 
$result = filemtime ($fisier);
 
$local = setlocale (LC_TIME, 'ro_RO.ISO8859-2');
  if (
$local == "ro_RO.ISO8859-2") {
   
$modtime = strftime '%e&nbsp;%B&nbsp;%Y&nbsp;%H:%M', $result);
  } else {
   
$modtime = strftime ('%d.%m.%Y&nbsp;%H:%M', $result);
  }
 
printf ("Ultima&nbsp;actualizare: %s\\n", $modtime);
?>
mk at totu dot com 26-Jan-2004 04:59
Be carefull - setting a locale which uses commas instead of dots in numbers may cause a mysql db not to understand the query:
<?php
setlocale
(LC_ALL,"pl");
$price = 1234 / 100; // now the price looks like 12,34
$query = mysql_query("SELECT Id FROM table WHERE price='".$price."'");
?>
Even if there is a price 12.34 - nothing will be found
r dot nospam dot velseboer at quicknet dot nospam dot nl 08-Sep-2002 07:02
be careful with the LC_ALL setting, as it may introduce some unwanted conversions. For example, I used

setlocale (LC_ALL, "Dutch");

to get my weekdays in dutch on the page. From that moment on (as I found out many hours later) my floating point values from MYSQL where interpreted as integers because the Dutch locale wants a comma (,) instead of a point (.) before the decimals. I tried printf, number_format, floatval.... all to no avail. 1.50 was always printed as 1.00 :(

When I set my locale to :

 setlocale (LC_TIME, "Dutch");

my weekdays are good now and my floating point values too.

I hope I can save some people the trouble of figuring this out by themselves.

Rob
jorg-spamm at omnimedia dot no 03-Jul-2002 11:23
I needed to compile and install some extra locales to get this to work on RH7.3. Probably just me not doing a proper installation, but this is what it took to fix it:

localedef -ci no_NO -f ISO_8859-1 no_NO
elindset at hoved dot net 12-May-2002 02:59
In FreeBSD I had to use no_NO.ISO8859-1 instead of just no_NO..

<?PHP
    setlocale
(LC_ALL, 'no_NO.ISO8859-1');
    echo
strftime ("%A %e %B %Y", time());
?>
misc dot anders at feder dot dk 19-Jun-2001 06:13
Under FreeBSD, locale definitions are stored in the /usr/share/locale/ directory. Danish time formats and weekdays, for instance, are stored in /usr/share/locale/da_DK.ISO_8859-1/LC_TIME.
noog at libero dot it 23-Nov-2000 03:13
On windows:
Control Panel->International Settings
You can set your locale and customize it
And locale-related PHP functions work perfectly
Morgan Christiansson &lt;mog at linux dot nu&gt; 29-Mar-2000 12:56
check /usr/share/locale/ if you want more info about the locale available with your *NIX box

there is also a file called /usr/share/locale/locale.alias with a list of aliases
such as swedish for sv_SE

so on all boxes i have accounts on (rh 6.0 and slack 3.4) you can just use setlocale("LC_ALL","swedish"); or other prefered language in plain english.

However, the weekdays were in all lowercase :(

Note: export LC_ALL=swedish made a lot of programs swedish for me, it's also possible to make them russian or japanese :)
Lucas Thompson <lucas at slf dot cx> 31-Jan-2000 02:57
The Open Group has an excellent document available on the setlocale() library function, most of which applies to the PHP function of the same name.

http://www.opengroup.org/onlinepubs/7908799/xbd/locale.html

WARNING: This document might be a little too complex for people who came from HTML to PHP.

If you migrated from the world of C programming you'll be a locale master after reading this document.

 
show source | credits | sitemap | contact | advertising | mirror sites