Re: I18Nv2 - get locale from language/country

From: Date: Wed, 02 Mar 2005 16:49:05 +0000
Subject: Re: I18Nv2 - get locale from language/country
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-36473@lists.php.net to get a copy of this message
Hi Andreas Korthaus, you wrote: > Is it possible to get a locale from a given language and a given > country? I need this for the date-format. I18Nv2 provides a locale map for windows for the most common locales; i.e. it will use "eng" for "en_GB" and "enu" for "en_US" as well as "en" (without territory suffix). One aim of I18Nv2 is to be able to use "standard" locale names like en_GB and en_US on Linux and Windows. > I have two users: > > 1. $lang = 'en'; $country = 'GB'; > 2. $lang = 'en'; $country = 'US'; > > Now I want to use: strftime('%x') > > For 'en_GB' this will output: 02/03/05 > For 'en_US' this will output: 03/02/2005 > > In this example I could simply use: > > $locale = $lang.'_'.$country; > setlocale (LC_TIME, $locale); > echo strftime('%x'); $locale = &I18Nv2::createLocale($lang .'_'. $country); echo $locale->date(); > But does this allways work, with all languages and countries in > PEAR::I18Nv2? As long as you're using locales which I18Nv2 knows of (only important for Windows -- or which are installed on your Linux machine) - yes. > Or what is the recommended way to get the correct locale? The value from > Accept-Language HTTP-Header could be correct, but is not allways > correct. The user must be able to change that. Most users do not know > what a "locale" is. So I hope the combination of $lang and $country > based on PEAR::I18Nv2 values could do the job. Is this correct? Well... AFAIK IE even don't let one define ones locale, but uses the system locale... I suppose, negotiating the locale at the first visit, providing a drop-down or similar and storing the preferred language/locale in the session/db, to be common practice. Regards, -- Michael - < mike(@)php.net >

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.pear.dev (#36473) next »