Languages Around The World

Locale Examples

Locale Currency Conventions

Application programs should not reset the default locale as a way of requesting an international object, because resetting default locale affects the other programs running in the same process. Use one of the factory methods instead, e.g. Collator::createInstance(Locale).

In general, a locale object or locale string is used for specifying the locale. Here is an example to specify the Belgium French with Euro currency locale:


C++

Locale loc("fr", "BE");
Locale loc2("fr_BE");


C

const char *loc = "fr_BE";

Note Java does not support the form Locale("xx_yy_ZZ"), instead use the form Locale("xx","yy","ZZ")

Locale Constants

A Locale is the mechanism for identifying the kind of object (NumberFormat) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves. For example, the following creates various number formatters for the "Germany" locale:


C++

UErrorCode status = U_ZERO_ERROR;
NumberFormat *nf;
nf = NumberFormat::createInstance(Locale::getGermany(), status);
delete nf;
nf = NumberFormat::createCurrencyInstance(Locale::getGermany(), status);
delete nf;
nf = NumberFormat::createPercentInstance(Locale::getGermany(), status);
delete nf;


C

UErrorCode status = U_ZERO_ERROR;
UNumberFormat *nf;
nf = unum_open(UNUM_DEFAULT, "de_DE", &status);
unum_close(nf);
nf = unum_open(UNUM_CURRENCY, "de_DE", &status);
unum_close(nf);
nf = unum_open(UNUM_PERCENT, "de_DE", &status);
unum_close(nf);

Querying Locale

Each class that performs locale-sensitive operations allows you to get all the available objects of that type. You can sift through these objects by language, country, or variant, and use the display names to present a menu to the user. For example, you can create a menu of all the collation objects suitable for a given language. For example, the following shows the display name of all available locales in English (US):


C++

int32_t count;
const Locale* list = 0;
UnicodeString result;
list = Locale::getAvailable(count);
for (int i = 0; i < count; i++)
{
    list[i].getDisplayName(Locale::getUS(), result);
    /* print result */
}


C

int32_t count;
UChar result[100];
int i = 0;
UErrorCode status = U_ZERO_ERROR;
count = uloc_countAvailable();
for (i = 0; i < count; i++)
{
    uloc_getDisplayname(uloc_getAvailable(i), "en_US", result, 100, &status);
    /* print result */
}


Copyright (c) 2000 - 2007 IBM and Others - PDF Version - Feedback: http://icu-project.org/contacts.html

User Guide for ICU v3.8 Generated 2007-09-14.