Saturday
3
April
2010

Using countries for localization

Hy interested ones,

I did not find a correct heading for what I want to describe you today.
But there is a new feature which has been implemented by me so let’s see some details:

Most of you are already using Zend_Locale. Give a language and get a locale in return.
You used this for translation, currency, date or other purposes.

Now the idea for this new feature is simple… why should a user not be able to give a country instead of a language to get a locale in return. For example “austria”… when I give “AT” then I could expect that the locale “de_AT” is being used.

And exactly this feature is available as with ZF 1.10.4 or ZF 2.0.

Of course there are much other usecases where this feature could be used.
For example, when your user selects a flag which represents his country. Then you could use only the region/country to get a locale with language in return.

$locale = new Zend_Locale('US');
// returns "en_US"

Or think of currencies. You could just give the country and get the currency for this country.

$currency = new Zend_Currency(array('locale' => 'AT'));
// uses "EUR" which is the currency for the locale "de_AT"

Generally you can use this feature everywhere within the whole framework where you used only languages or locales before.

But of course there is one thing to note:
You have to uppercase countries when you want to use them. The reason is that there are countries which are equal to languages. For example “om”… you could mean the country Oman and expect “ar_OM” as locale, or you could mean the language “Oromo” and expect “or_KE” as locale.

When you find this feature useful, feel free to use it yourself. :-)

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
  1. Pencil

    Saturday, April 3, 2010 - 14:48:29

    What about countries with multiple locales (Switzerland: de_CH, fr_CH, it_CH…)?

  2. thomasw

    Saturday, April 3, 2010 - 14:53:31

    The language which is spoken by the biggest population of this country is being used.

  3. pamela

    Tuesday, April 6, 2010 - 13:36:36

    This is not acceptable, some countries have multiple official national languages, if you return the language that the biggest part of the population speaks its just unfair for minorities in that country. In these case you should return an array.

  4. thomasw

    Tuesday, April 6, 2010 - 15:36:15

    Sorry, but when a feature is not acceptable for you, then just don’t use it.

    As before you are free to set the language/locale which you want to use yourself. Just because Zend_Locale provides a way to return the most spoken language of a country, does not mean that you must use this language for your application.

  5. Pencil

    Wednesday, April 7, 2010 - 16:21:00

    This may lead to confusion as not everyone is aware about the fact, that there are countries with multiple languages. I think, it should definitely be mentioned in the documentation…

  6. scs

    Thursday, April 22, 2010 - 22:47:27

    Thomas,
    Giving the country will be enough for locale and language initiation?
    If not misunderstood, this is a greate feature. I am sure it will make things easier.

    Thanks.

  7. emploi domicile

    Tuesday, April 17, 2012 - 02:50:53

    I agree with you, but dont be too rude !
    whatever, great site !

Add comment

Fill out the form below to add your own comments

User data




Add your comment