1--- 2layout: default 3title: Locales and Resources 4nav_order: 5 5has_children: true 6--- 7<!-- 8© 2020 and later: Unicode, Inc. and others. 9License & terms of use: http://www.unicode.org/copyright.html 10--> 11 12# Locale 13{: .no_toc } 14 15## Contents 16{: .no_toc .text-delta } 17 181. TOC 19{:toc} 20 21--- 22 23## Overview 24 25This chapter explains **locales**, a fundamental concept in ICU. ICU services 26are parameterized by locale, to allow client code to be written in a 27locale-independent way, but to deliver culturally correct results. 28 29## The Locale Concept 30 31A locale identifies a specific user community - a group of users who have 32similar culture and language expectations for human-computer interaction (and 33the kinds of data they process). 34 35A community is usually understood as the intersection of all users speaking the 36same language and living in the same country. Furthermore, a community can use 37more specific conventions. For example, an English/United States/Military locale 38is separate from the regular English/United States locale since the US military 39writes times and dates differently than most of the civilian community. 40 41A program should be localized according to the rules specific for the target 42locale. Many ICU services rely on the proper locale identification in their 43function. 44 45The locale object in ICU is an identifier that specifies a particular locale and 46has fields for language, country, and an optional code to specify further 47variants or subdivisions. These fields also can be represented as a string with 48the fields separated by an underscore. 49 50In the C++ API, the locale is represented by the `Locale` class, which provides 51methods for finding language, country and variant components. In the C API the locale 52is defined simply by a character string. In the Java API, the locale is represented by 53`ULocale` which is analogous to the `Locale` class but provide additional support 54for ICU protocol. All the locale-sensitive ICU services use the locale information 55to determine language and other locale specific parameters of their function. 56The list of locale-sensitive services can be found in the Introduction to ICU 57section. Other parts of the library use the locale as an indicator to 58customize their behavior. 59 60For example, when the locale-sensitive date format service needs to format a 61date, it uses the convention appropriate to the current locale. If the locale is 62English, it uses the word "Monday" and if it is French, it uses the word 63"Lundi". 64 65The locale object also defines the concept of a default locale. The default 66locale is the locale, used by many programs, that regulates the rest of the 67computer's behavior by default and is usually controlled by the user in a 68control panel window. The locale mechanism does not require a program to know 69which locale the user is using and thus makes most programming simpler. 70 71Since locale objects can be passed as parameters or stored in variables, the 72program does not have to know specifically which locales they identify. Many 73applications enable a user to select a locale. The resulting locale object is 74passed as a parameter, which then produces the customized behavior for that 75locale. 76 77A locale provides a means of identifying a specific region for the purposes of 78internationalization and localization. 79 80> :point_right: **Note**: An ICU locale is frequently confused with a Portable 81> Operating System Interface (POSIX) locale ID. An ICU locale ID is not a POSIX 82> locale ID. ICU locales do not specify the encoding and specify variant locales 83> differently. 84 85A locale consists of one or more pieces of ordered information: 86 87### Language code 88 89The languages are specified using a two- or three-letter lowercase code for a 90particular language. For example, Spanish is "es", English is "en" and French is 91"fr". The two-letter language code uses the 92[ISO-639](https://www.loc.gov/standards/iso639-2/) standard. 93 94### Script code 95 96The optional four-letter script code follows the language code. If specified, it 97should be a valid script code as listed on the 98[Unicode ISO 15924 Registry](https://www.unicode.org/iso15924/iso15924-codes.html). 99 100### Country code 101 102There are often different language conventions within the same language. For 103example, Spanish is spoken in many countries in Central and South America but 104the currencies are different in each country. To allow for these differences 105among specific geographical, political, or cultural regions, locales are 106specified by two-letter, uppercase codes. For example, "ES" represents Spain and 107"MX" represents Mexico. The two letter country code uses the 108[ISO-3166](https://www.iso.org/iso-3166-country-codes.html) standard. 109 110Java supports two letter country codes that uses ISO-3166 and UN M.49 code. 111 112### Variant code 113 114Differences may also appear in language conventions used within the same 115country. For example, the Euro currency is used in several European countries 116while the individual country's currency is still in circulation. Variations 117inside a language and country pair are handled by adding a third code, the 118variant code. The variant code is arbitrary and completely application-specific. 119ICU adds "_EURO" to its locale designations for locales that support the Euro 120currency. Variants can have any number of underscored key words. For example, 121"EURO_WIN" is a variant for the Euro currency on a Windows computer. 122 123Another use of the variant code is to designate the Collation (sorting order) of 124a locale. For instance, the "es__TRADITIONAL" locale uses the traditional 125sorting order which is different from the default modern sorting of Spanish. 126 127Collation order and currency can be more flexibly specified using keywords 128instead of variants; see below. 129 130### Keywords 131 132The final element of a locale is an optional list of keywords together with 133their values. Keywords must be unique. Their order is not significant. Unknown 134keywords are ignored. The handling of keywords depends on the specific services 135that utilize them. Currently, the following keywords are recognized: 136 137Keyword | Possible Values | Description 138--------|-----------------|------------ 139calendar | A calendar specifier such as "gregorian", "islamic", "chinese", "islamic-civil", "hebrew", "japanese", or "buddhist". See the Key/Type Definitions table in the [Locale Data Markup Language](http://www.unicode.org/reports/tr35/) for a list of recognized values. | If present, the calendar keyword specifies the calendar type that the `Calendar` factory methods create. See the calendar locale and keyword handling section (§) of the [Calendar Classes](../datetime/calendar/index.md) chapter for details. 140collation | A collation specifier such as "phonebook", "pinyin", "traditional", "stroke", "direct", or "posix". See the Key/Type Definitions table in the [Locale Data Markup Language](http://www.unicode.org/reports/tr35/) for a list of recognized values. | If present, the collation keyword modifies how the collation service searches through the locale data when instantiating a collator. See the collation locale and keyword handling section (§) of the [Collation Services Architecture](../collation/architecture.md) chapter for details. 141currency | Any standard three-letter currency code, such as "USD" or "JPY". See the LocaleExplorer [currency list](http://demo.icu-project.org/icu-bin/locexp?_=en&SHOWCurrencies=1#Currencies) for a list of currently recognized currency codes. | If present, the currency keyword is used by `NumberFormat` to determine the currency to use to format a currency value, and by `ucurr_forLocale()` to specify a currency. 142numbers | A numbering system specifier such as "latn", "arab", "deva", "hansfin" or "thai". See the Key/Type Definitions table in the [Locale Data Markup Language](http://www.unicode.org/reports/tr35/) for a list of recognized values. | If present, the numbers keyword is used by `NumberFormat` to determine the numbering system to be used for formatting and parsing numbers. The numbering system defines the set of digits used for decimal formatting, such as "latn" for western (ASCII) digits, or "thai" for Thai digits. The numbering system may also define complex algorithms for number formatting, such as "hansfin" for simplified Chinese numerals using financial ideographs. 143 144If any of these keywords is absent, the service requesting it will typically use 145the rest of the locale specifier in order to determine the appropriate behavior 146for the locale. The keywords allow a locale specifier to override or refine this 147default behavior. 148 149### Examples 150 151Locale ID | Language | Script | Country | Variant | Keywords | Definition 152----------|----------|--------|---------|---------|----------|----------- 153en_US | en | | US | | | English, United States of America. <br>Browse in [LocaleExplorer](http://demo.icu-project.org/icu-bin/locexp?_=en_US) 154en_IE_PREEURO | en | | IE | | | English, Ireland. <br>Browse in [LocaleExplorer](http://demo.icu-project.org/icu-bin/locexp?_=en_IE_PREEURO) 155en_IE@currency=IEP | en | | IE | | currency=IEP | English, Ireland with Irish Pound. <br>Browse in [LocaleExplorer](http://demo.icu-project.org/icu-bin/locexp?_=en_IE@currency=IEP) 156eo | eo | | | | | Esperanto. <br>Browse in [LocaleExplorer](http://demo.icu-project.org/icu-bin/locexp?_=eo) 157fr@collation=phonebook;calendar=islamic-civil | fr | | | | collation=phonebook <br>calendar=islamic-civil | French (Calendar=Islamic-Civil Calendar, Collation=Phonebook Order). <br>Browse in [LocaleExplorer](http://demo.icu-project.org/icu-bin/locexp?_=fr@collation=phonebook;calendar=islamic-civil) 158sr_Latn_RS_REVISED@currency=USD | sr | Latn | RS | REVISED | currency=USD | Serbian (Latin, Yugoslavia, Revised Orthography, Currency=US Dollar) <br>Browse in [LocaleExplorer](http://demo.icu-project.org/icu-bin/locexp?d_=en&_=sr_Latn_RS_REVISED@currency=USD) 159 160 161### Default Locales 162 163Default locales are available to all the objects in a program. If you set a new 164default locale for one section of code, it can affect the entire program. 165Application programs should not set the default locale as a way to request an 166international object. The default locale is set to be the system locale on that 167platform. 168 169For example, when you set the default locale, the change affects the default 170behavior of the `Collator` and `NumberFormat` instances. When the default locale is 171not wanted, you can set the desired locale using a factory method supplied with 172the classes such as `Collator::createInstance()`. 173 174Using the ICU C functions, `NULL` can be passed for a locale parameter to specify 175the default locale. 176 177## Locales and Services 178 179ICU is implemented as a set of services. One example of a service is the 180formatting of a numeric value into a string. Another is the sorting of a list of 181strings. When client code wants to use a service, the first thing it does is 182request a service object for a given locale. The resulting object is then 183expected to perform the its operations in a way that is culturally correct for 184the requested locale. 185 186### Requested Locale 187 188The **requested** locale is the one specified by the client code when the 189service object is requested. 190 191### Valid Locale 192 193A **populated** locale is one for which ICU has data, or one in which client 194code has registered a service. If the requested locale is not populated, then 195ICU will fallback until it reaches a populated locale. The first populated 196locale it reaches is the **valid** locale. The 197valid locale is reachable from the requested locale via zero or more fallback 198steps. 199 200### Fallback 201 202Locale **fallback** proceeds as follows: 203 2041. The variant is removed, if there is one. 205 2062. The country is removed, if there is one. 207 2083. The script is removed, if there is one. 209 2104. The ICU default locale is examined. The same set of steps is performed for 211 the default locale. 212 213At any point, if the desired data is found, then the fallback procedure stops. 214Keywords are not altered during fallback until the default locale is reached, at 215which point all keywords are replaced by those assigned to the default locale. 216 217### Actual Locale 218 219Services request specific resources within the valid locale. If the valid locale 220directly contains the requested resource, then it is the **actual** locale. If 221not, then ICU will fallback until it reaches a locale that does directly contain 222the requested resource. The first such locale is the actual locale. The actual 223locale is reachable from the valid locale via zero or more fallback steps. 224 225### getLocale() 226 227Client code may wish to know what the valid and actual locales are for a given 228service object. To support this, ICU services provide the method `getLocale()`. 229The `getLocale()` method takes an argument specifying whether the actual or 230valid locale is to be returned. 231 232Some service object will have an empty or null return from `getLocale()`. This 233indicates that the given service object was not created from locale data, or 234that it has since been modified so that it no longer reflects locale data, 235typically through alteration of the pattern (but not localized symbol changes -- 236such changes do not reset the actual and valid locale settings). 237 238Currently, the services that support the `getLocale()` API are the following 239classes and their subclasses: 240 241### Functional Equivalence 242 243Various services provide the API `getFunctionalEquivalent` to allow callers 244determine the **functionally equivalent locale** for a requested locale. For 245example, when instantiating a collator for the locale `en_US_CALIFORNIA`, the 246functionally equivalent locale may be `en`. 247 248The purpose of this is to allow applications to do intelligent caching. If an 249application opens a service object for locale A with a functional equivalent Q 250and caches it, then later when it requires a service object for locale B, it can 251first check if locale B has the **same functional equivalent** as locale A; if 252so, it can reuse the cached A object for the B locale, and be guaranteed the 253same results as if it has instantiated a service object for B. In other words, 254 255``` 256Service.getFunctionalEquivalent(A) == Service.getFunctionalEquivalent(B) 257``` 258 259implies that the object returned by `Service.getInstance(A)` will behave 260equivalently to the object returned by `Service.getInstance(B)`. 261 262Here is a pseudo-code example: 263 264The functional equivalent locale returned by a service has no meaning beyond 265what is stated above. For example, if the functional equivalent of Greek is 266Hebrew for collation, that makes no statement about the linguistic relation of 267the languages -- it only means that the two collators are functionally 268equivalent. 269 270While two locales with the same functional equivalent are guaranteed to be 271equivalent, the converse is **not** true: If two locales are in fact equivalent, 272they may **not** return the same result from `getFunctionalEquivalent`. That is, 273if the object returned by `Service.getInstance(A)` behaves equivalently to the 274object returned by `Service.getInstance(B)`, `Service.getFunctionalEquivalent(A)` 275**may or may not** be equal to `Service.getFunctionalEquivalent(B)`. Take again 276the example of Greek and Hebrew, with respect to collation. These locales may 277happen to be functional equivalents (since they each just turn on full 278normalization), but it may or may not be the case that they return the same 279functionally equivalent locale. This depends on how the data is structured 280internally. 281 282The functional equivalent for a locale may change over time. Suppose that Greek 283were enhanced to change sorting of additional ancient Greek characters. In that 284case, it would diverge; the functional equivalent of Greek would no longer be 285Hebrew. 286 287## Canonicalization 288 289ICU works with **ICU format locale IDs**. These are strings that obey the 290following character set and syntax restrictions: 291 2921. The only permitted characters are ASCII letters, hyphen ('-'), underscore 293 ('_'), at-sign ('@'), equals sign ('='), and semicolon (';'). 294 2952. IDs consist of either a base name, keyword list, or both. If a keyword list 296 is present it must be preceded by an at-sign. 297 2983. The base name must precede the keyword list, if both are present. 299 3004. The base name defines the language, script, country, and variant, and can 301 contain only ASCII letters, hyphen, or underscore. 302 3035. The keyword list consists of keyword/value pairs. Each keyword or value 304 consists of one or more ASCII letters, hyphen, or underscore. Keywords and 305 values are separated by a single equals sign. Multiple keyword/value pairs, 306 if present, are separated by a single semicolon. A keyword may not appear 307 without a value. The same keyword may not appear twice. 308 309ICU performs two kinds of canonicalizing operations on 'ICU format' locale IDs. 310Level 1 canonicalization is performed routinely and automatically by ICU APIs. 311The recommended procedure for client code using locale IDs from outside sources 312(e.g., POSIX, user input, etc.) is to pass such "foreign IDs" through level 2 313canonicalization before use. 314 315**Level 1 canonicalization**. This operation performs minor, isolated changes, 316such as changing "en-us" to "en_US". Level 1 canonicalization is **not** 317designed to handle "foreign" locale IDs (POSIX, .NET) but rather IDs that are in 318ICU format, but which do not have normalized case and delimiters. Level 1 319canonicalization is accomplished by the ICU functions `uloc_getName`, 320`Locale::createFromName`, and `Locale::Locale`. The latter two APIs exist in both 321C++ and Java. 322 3231. Level 1 canonicalization is defined only on ICU format locale IDs as defined 324 above. Behavior with any other kind of input is unspecified. 325 3262. Case is normalized. Elements interpreted as **language** strings will be 327 converted to lowercase. **Country** and **variant** elements will be 328 converted to uppercase. **Script** elements will be title-cased. **Keywords** 329 will be converted to lowercase. **Keyword values** will remain unchanged. 330 3313. Hyphens are converted to underscores. 332 3334. All 3-letter country codes are converted to 2-letter equivalents. 334 3355. Any 3-letter language codes are converted to 2-letter equivalents if 336 possible. 3-letter language codes with no 2-letter equivalent are kept as 337 3-letter codes. 338 3396. Keywords are sorted. 340 341**Level 2 canonicalization**. This operation may make major changes to the ID, 342possibly replacing entire elements of the ID. An example is changing 343"fr-fr@EURO" to "fr_FR@currency=EUR". Level 2 canonicalization is designed to 344translate POSIX and .NET IDs, as well as nonstandard ICU locale IDs. Level 2 is 345a **superset** of level 1; every operation performed by level 1 is also 346performed by level 2. Level 2 canonicalization is performed by `uloc_canonicalize` 347and `Locale::createCanonical`. The latter API exists in both C++ and Java. 348 3491. Level 2 canonicalization operates on ICU format locale IDs with the 350 following additions: 351 352 1. The period ('.') is also a valid input character. 353 354 2. An at-sign may be followed by text that is not a keyword/value pair. If 355 present, such text is added to the variant. 356 3572. POSIX variants are normalized, e.g., "en_US@VARIANT" => "en_US_VARIANT". 358 3593. POSIX charset specifiers are **deleted**, e.g. "en_US.utf8" => "en_US". 360 3614. The variant "EURO" is converted to the keyword specifier "currency=EUR". 362 This conversion applies to both "fr_FR_EURO" and "fr_FR@EURO" style IDs. 363 3645. The variant "PREEURO" is converted to the keyword specifier "currency=K", 365 where K is the 3-letter currency code for the country's national currency in 366 effect at the time of the euro transitiion. This conversion applies to both 367 "fr_FR_PREURO" and "fr_FR@PREURO" style IDs. This mapping is only performed 368 for the following locales: ca_ES (ESP), de_AT (ATS), de_DE (DEM), de_LU 369 (EUR), el_GR (GRD), en_BE (BEF), en_IE (IEP), es_ES (ESP), eu_ES (ESP), 370 fi_FI (FIM), fr_BE (BEF), fr_FR (FRF), fr_LU (LUF), ga_IE (IEP), gl_ES 371 (ESP), it_IT (ITL), nl_BE (BEF), nl_NL (NLG), pt_PT (PTE). 372 3736. The following IANA registered ISO 3066 names are remapped: art_LOJBAN => 374 jbo, cel_GAULISH => cel__GAULISH, de_1901 => de__1901, de_1906 => de__1906, 375 en_BOONT => en__BOONT, en_SCOUSE => en__SCOUSE, sl_ROZAJ => sl__ROZAJ, 376 zh_GAN => zh__GAN, zh_GUOYU => zh, zh_HAKKA => zh__HAKKA, zh_MIN => zh__MIN, 377 zh_MIN_NAN => zh__MINNAN, zh_WUU => zh__WUU, zh_XIANG => zh__XIANG, zh_YUE 378 => zh__YUE. 379 3807. The following .NET identifiers are remapped: "" (empty string) => 381 en_US_POSIX, az_AZ_CYRL => az_Cyrl_AZ, az_AZ_LATN => az_Latn_AZ, sr_SP_CYRL 382 => sr_Cyrl_SP, sr_SP_LATN => sr_Latn_SP, uz_UZ_CYRL => uz_Cyrl_UZ, 383 uz_UZ_LATN => uz_Latn_UZ, zh_CHS => zh_Hans, zh_CHT => zh_Hant. The empty 384 string is not remapped if a keyword list is present. 385 3868. Variants specifying collation are remapped to collation keyword specifiers, 387 as follows: de__PHONEBOOK => de@collation=phonebook, es__TRADITIONAL => 388 es@collation=traditional, hi__DIRECT => hi@collation=direct, zh_TW_STROKE => 389 zh_TW@collation=stroke, zh__PINYIN => zh@collation=pinyin. 390 3919. Variants specifying a calendar are remapped to calendar keyword specifiers, 392 as follows: ja_JP_TRADITIONAL => ja_JP@calendar=japanese, th_TH_TRADITIONAL 393 => th_TH@calendar=buddhist. 394 39510. Special case: C => en_US_POSIX. 396 397Certain other operations are not performed by either level 1 or level 2 398canonicalization. These are listed here for completeness. 399 4001. Language identifiers that have been superseded will not be remapped. In 401 particular, the following transformations are not performed: 402 403 1. no => nb 404 405 2. iw => he 406 407 3. id => in 408 409 4. nb_no_NY => nn_NO 410 4112. The behavior of level 2 canonicalization when presented with a remapped ID 412 combined together with keywords is not defined. For example, 413 fr_FR_EURO@currency=FRF has an undefined level 2 canonicalization. 414 415All APIs (with a few exceptions) in ICU4C that take a `const char* locale` 416parameter can be assumed to automatically peform level 1 canonicalization before 417using the locale ID to do resource lookup, keyword interpretation, etc. 418Specifically, the static API `getLanguage`, `getScript`, `getCountry`, and `getVariant` 419behave exactly like their non-static counterparts in the class `Locale`. That is, 420for any locale ID `loc`, `new Locale(loc).getFoo() == Locale::getFoo(loc)`, where 421Foo is one of Language, Script, Country, or Variant. 422 423The `Locale` constructor (in C++ and Java) taking multiple strings behaves exactly 424as if those strings were concatenated, with the '_' separator inserted between 425two adjacent non-empty strings, and the result passed to `uloc_getName`. 426 427> :point_right: **Note**: Throughout this discussion `Locale` refers to both the 428> C++ `Locale` class and the ICU4J `com.ibm.icu.util.ULocale` class. Although C++ 429> notation is used, all statements made regarding `Locale` apply equally to 430> `com.ibm.icu.util.ULocale`. 431 432## Usage: Creating Locales 433 434If you are localizing an application to a locale that is not already supported, 435you need to create your own `Locale` object. New `Locale` objects are created using 436one of the three constructors in this class: 437 438```c++ 439Locale( const char * language); 440Locale( const char * language, const char * country); 441Locale( const char * language, const char * country, const char * variant); 442``` 443 444Because a locale object is just an identifier for a region, no validity check is 445performed. If you want to verify that the particular resources are available for 446the locale you construct, you must query those resources. For example, you can 447query the `NumberFormat` object for the locales it supports using its 448`getAvailableLocales()` method. 449 450New `ULocale` objects in Java are created using one the following three 451constructor in this class: 452 453```java 454ULocale( String localeID) 455ULocale( String a, String b) 456ULocale( String a, String b, String c) 457``` 458 459The locale ID passed in the constructor consists of optional languages, scripts, 460country and variant fields in that oder, separated by underscore, followed by an 461optional keywords. For example, "en_US", "sy_Cyrl_YU", "zh__pinyin", 462"es_ES@currency=EUR,collation=traditional". The fields a, b, c in the other two 463constructors are the components of the locale ID. For example, the following two 464locale object are same: 465 466```java 467ULocale ul = new Ulocale("sy_Cyrl_YU"); 468ULocale ul = new ULocale("sy", "Cyrl", "YU"); 469``` 470 471In C++, the `Locale` class provides a number of convenient constants that you can 472use to create locales. For example, the following refers to a `NumberFormat` object 473for the United States: 474 475```c++ 476Locale::getUS() 477``` 478 479In C, a string with the language country and variant concatenated together with 480an underscore '_' describe a locale. For example, "en_US" is a locale that is 481based on the English language in the United States. The following can be used as 482equivalents to the locale constants: 483 484```c 485ULOC_US 486``` 487 488In Java, the `ULocale` provides a number of convenient constants that can be used 489to create locales. 490 491```java 492ULocale.US; 493``` 494 495## Usage: Retrieving Locales 496 497Locale-sensitive classes have a `getAvailableLocales()` method that returns all of 498the locales supported by that class. This method also shows the other methods 499that get locale information from the resource bundle. For example, the following 500shows that the `NumberFormat` class provides three convenience methods for 501creating a default `NumberFormat` object: 502 503```c++ 504NumberFormat::createInstance(); 505NumberFormat::createCurrencyInstance(); 506NumberFormat::createPercentInstance(); 507``` 508 509Locale-sensitive classes in Java also have a `getAvailableULocales()` method that 510returns all of the locales supported by that class. 511 512### Displayable Names 513 514Once you've created a `Locale` in C++ and a `ULocale` in java, you can perform a 515query of the locale for information about itself. The following shows the 516information you can receive from a locale: 517 518Method | Description 519-------|------------ 520`getCountry()` | Retrieves the ISO Country Code 521`getLanguage()` | Retrieves the ISO Language 522`getDisplayCountry()` | Shows the name of the country suitable for displaying information to the user 523`getDisplayLanguage()` | Shows the name of the language suitable for displaying to the user 524 525> :point_right: **Note**: The `getDisplayXXX` methods are themselves locale-sensitive 526> and have two versions in C++: one that uses the default locale and one that takes a 527> locale as an argument and displays the name or country in a language appropriate to 528> that locale. 529 530> :point_right: **Note**: In Java, the `getDisplayXXX` methods have three versions: 531> one that uses the default locale, the other takes a locale as an argument and the 532> third one which takes locale ID as an argument. 533 534Each class that performs locale-sensitive operations allows you to get all the 535available objects of that type. You can sift through these objects by language, 536country, or variant, and use the display names to present a menu to the user. 537For example, you can create a menu of all the collation objects suitable for a 538given language. 539 540### HTTP Accept-Language 541 542ICU provides functions to negotiate the best locale to use for an operation, 543given a user's list of acceptable locales, and the application's list of 544available locales. For example, a browser sends the web server the HTTP 545"`Accept-Language`" header indicating which locales, with a ranking, are 546acceptable to the user. The server must determine which locale to use when 547returning content to the user. 548 549Here is an example of selecting an acceptable locale within a CGI application: 550 551C: 552 553```c 554char resultLocale[200]; 555UAcceptResult outResult; 556available = ures_openAvailableLocales("myBundle", &status); 557int32_t len = uloc_acceptLanguageFromHTTP(resultLocale, 200, &outResult, 558 getenv("HTTP_ACCEPT_LANGUAGE"), available, &status); 559if(U_SUCCESS(status)) { 560 printf("Using locale %s\n", outResult); 561} 562``` 563 564Here is an example of selecting an acceptable locale within a Java application: 565 566Java: 567 568```java 569ULocale[] availableLocales = ULocale.getAvailableLocales(); 570boolean[] fallback = { false }; 571ULocale result = ULocale.acceptLanguage(availableLocales, fallback); 572 573System.out.println("Using locale " + result); 574``` 575 576> :point_right: **Note**: As of this writing, this functionality is available in 577> both C and Java. Please read the following two linked documents for important 578> considerations and recommendations when using this header in a web application. 579 580> *For further information about the Accept-Language HTTP header:* <br> 581> https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 <br> 582> *Notes and cautions about the use of this header:* <br> 583> https://www.w3.org/International/questions/qa-accept-lang-locales 584 585## Programming in C vs. C++ vs. Java 586 587See Programming for Locale in [C, C++ and Java](examples.md) for more information. 588