setlocale


word apg

LOCALE is a set of parameters used to prioritize the use of a given language, culture or regional data, within a given API, (Application Programming Interface).

Is, also, defined as the geographic place at which there is or was human settlement.

Consists, usually a locale identifier of at least a language identifier and a region identifier.



FIRST STRUCTURE


In the following, the FIRST STRUCTURE of -  setlocale :



<?php

str
|false setlocale int $category str $locale str $loc01, ... , str $locN  )


where,

$category CONSTANT  to specify the 
                    category of the functions affected by the locale setting
                    
SEE the below TABLE )

$locale STRING to configure how the value is returned by the environment

$loc01
, ... , $locN The locale names as STRINGS

?>

SECOND STRUCTURE


In the following, the SECOND STRUCTURE of -  setlocale :



<?php

str
|false setlocale int $category arr $locale )

where,

int $category named constant specifying the 
                        category of the functions affected
                        by the locale setting

arr $locale 
=> each array element must be used as settings for locale.

?>

$category & $locale


LOCALEs are organized and identified according to RFC 5646.

Not all PHP functions are compatible with LOCALE.

Whenever possible, this will be considered.

$mix_category Windows UNIX like USUAL CONSTANTS
LC_ALL 0 6 FOR ALL VARIABLES
LC_COLLATE 1 3 Comparisons with STRINGS
See, strcoll
LC_CTYPE 2 0 Conversion and Classification of Characters
See, strtoupper
LC_MONETARY 3 4 Monetary Standards
See, localeconv
LC_NUMERIC 4 1 Decimal Separator
See, localeconv
LC_TIME 5 2 Date and Time Formatting with strftime
LC_MESSAGES   5 System Responses
Available if PHP was compiled with libintl
$str_locale(s) ELEMENTS OF ARRAY OR SIMPLE STRINGS
NULL LOCALEs set by the environment variables
"" LOCALEs set by the environment variables
0 LOCALEs are not affected, only the current values are returned
"0" LOCALEs are not affected, only the current values are returned
LOCALE ID(S) STRING(S) or ARRAY
ed48

If $locale = NULL or $locale = "" the locale names will be set from the values of environment variables.

If $locale = "0" the locale setting is not affected, only the current setting is returned.

If If $locale is an ARRAY, each element of the ARRAY must be used as settings for the function locale.

On Windows,  setlocale(LC_ALL, '')  sets the locale names from the system's regional/language settings, (accessible via Control Panel).

The return value of setlocale depends on the system that PHP is running.

It returns exactly what the system setlocale function returns.

Since PHP 7.0.0 only  LC_*  constants can be used as of this version, because the support for the category parameter passed as a STRING has been removed.

In the following table, we show some usual  LOCALEs  generated from information at Microsoft Windows Encodings and Code Pages and additional resources listed below:

locale Language code LCID string LCID Dec LCID Hex Win Codepage
Afrikaans af af 1078 436 1252
Albanian sq sq 1052 1250
Amharic am am 1118
Arabic - Algeria ar ar-dz 5121 1401 1256
Arabic - Bahrain ar ar-bh 15361 1256
Arabic - Egypt ar ar-eg 3073 1256
Arabic - Iraq ar ar-iq 2049 801 1256
Arabic - Jordan ar ar-jo 11265 1256
Arabic - Kuwait ar ar-kw 13313 3401 1256
Arabic - Lebanon ar ar-lb 12289 3001 1256
Arabic - Libya ar ar-ly 4097 1001 1256
Arabic - Morocco ar ar-ma 6145 1801 1256
Arabic - Oman ar ar-om 8193 2001 1256
Arabic - Qatar ar ar-qa 16385 4001 1256
Arabic - Saudi Arabia ar ar-sa 1025 401 1256
Arabic - Syria ar ar-sy 10241 2801 1256
Arabic - Tunisia ar ar-tn 7169 1256
Arabic - United Arab Emirates ar ar-ae 14337 3801 1256
Arabic - Yemen ar ar-ye 9217 2401 1256
Armenian hy hy 1067
Assamese as as 1101
Azeri - Cyrillic az az-az 2092 1251
Azeri - Latin az az-az 1068 1254
Basque eu eu 1069 1252
Belarusian be be 1059 423 1251
Bengali - Bangladesh bn bn 2117 845
Bengali - India bn bn 1093 445
Bosnian bs bs 5146
Bulgarian bg bg 1026 402 1251
Burmese my my 1109 455
Catalan ca ca 1027 403 1252
Chinese - China zh zh-cn 2052 804
Chinese - Hong Kong SAR zh zh-hk 3076
Chinese - Macau SAR zh zh-mo 5124 1404
Chinese - Singapore zh zh-sg 4100 1004
Chinese - Taiwan zh zh-tw 1028 404
Croatian hr hr 1050 1250
Czech cs cs 1029 405 1250
Danish da da 1030 406 1252
Divehi Dhivehi Maldivian dv dv
Dutch - Belgium nl nl-be 2067 813 1252
Dutch - Netherlands nl nl-nl 1043 413 1252
Edo 1126 466
English - Australia en en-au 3081 1252
English - Belize en en-bz 10249 2809 1252
English - Canada en en-ca 4105 1009 1252
English - Caribbean en en-cb 9225 2409 1252
English - Great Britain en en-gb 2057 809 1252
English - India en en-in 16393 4009
English - Ireland en en-ie 6153 1809 1252
English - Jamaica en en-jm 8201 2009 1252
English - New Zealand en en-nz 5129 1409 1252
English - Phillippines en en-ph 13321 3409 1252
English - Southern Africa en en-za 7177 1252
English - Trinidad en en-tt 11273 1252
English - United States en en-us 1033 409 1252
English - Zimbabwe en 12297 3009 1252
Estonian et et 1061 425 1257
FYRO Macedonia mk mk 1071 1251
Faroese fo fo 1080 438 1252
Farsi - Persian fa fa 1065 429 1256
Filipino 1124 464
Finnish fi fi 1035 1252
French - Belgium fr fr-be 2060 1252
French - Cameroon fr 11276
French - Canada fr fr-ca 3084 1252
French - Congo fr 9228
French - Cote d'Ivoire fr 12300
French - France fr fr-fr 1036 1252
French - Luxembourg fr fr-lu 5132 1252
French - Mali fr 13324
French - Monaco fr 6156 1252
French - Morocco fr 14348
French - Senegal fr 10252
French - Switzerland fr fr-ch 4108 1252
French - West Indies fr 7180
Frisian - Netherlands 1122 462
Gaelic - Ireland gd gd-ie 2108
Gaelic - Scotland gd gd 1084
Galician gl 1110 456 1252
Georgian ka 1079 437
German - Austria de de-at 3079 1252
German - Germany de de-de 1031 407 1252
German - Liechtenstein de de-li 5127 1407 1252
German - Luxembourg de de-lu 4103 1007 1252
German - Switzerland de de-ch 2055 807 1252
Greek el el 1032 408 1253
Guarani - Paraguay gn gn 1140 474
Gujarati gu gu 1095 447
HID (Human Interface Device) 1279
Hebrew he he 1037 1255
Hindi hi hi 1081 439
Hungarian hu hu 1038 1250
Icelandic is is 1039 1252
Igbo - Nigeria 1136 470
Indonesian id id 1057 421 1252
Italian - Italy it it-it 1040 410 1252
Italian - Switzerland it it-ch 2064 810 1252
Japanese ja ja 1041 411
Kannada kn kn 1099
Kashmiri ks ks 1120 460
Kazakh kk kk 1087 1251
Khmer km km 1107 453
Konkani 1111 457
Korean ko ko 1042 412
Kyrgyz - Cyrillic 1088 440 1251
Lao lo lo 1108 454
Latin la la 1142 476
Latvian lv lv 1062 426 1257
Lithuanian lt lt 1063 427 1257
Malay - Brunei ms ms-bn 2110 1252
Malay - Malaysia ms ms-my 1086 1252
Malayalam ml ml 1100
Maltese mt mt 1082
Manipuri 1112 458
Maori mi mi 1153 481
Marathi mr mr 1102
Mongolian mn mn 2128 850
Mongolian mn mn 1104 450 1251
Nepali ne ne 1121 461
Norwegian - Bokml nb no-no 1044 414 1252
Norwegian - Nynorsk nn no-no 2068 814 1252
Oriya or or 1096 448
Polish pl pl 1045 415 1250
Portuguese - Brazil pt pt-br 1046 416 1252
Portuguese - Portugal pt pt-pt 2070 816 1252
Punjabi pa pa 1094 446
Raeto-Romance rm rm 1047 417
Romanian - Moldova ro ro-mo 2072 818
Romanian - Romania ro ro 1048 418 1250
Russian ru ru 1049 419 1251
Russian - Moldova ru ru-mo 2073 819
Sami Lappish 1083
Sanskrit sa sa 1103
Serbian - Cyrillic sr sr-sp 3098 1251
Serbian - Latin sr sr-sp 2074 1250
Sesotho (Sutu) 1072 430
Setsuana tn tn 1074 432
Sindhi sd sd 1113 459
Sinhala Sinhalese si si 1115
Slovak sk sk 1051 1250
Slovenian sl sl 1060 424 1250
Somali so so 1143 477
Sorbian sb sb 1070
Spanish - Argentina es es-ar 11274 1252
Spanish - Bolivia es es-bo 16394 1252
Spanish - Chile es es-cl 13322 1252
Spanish - Colombia es es-co 9226 1252
Spanish - Costa Rica es es-cr 5130 1252
Spanish - Dominican Republic es es-do 7178 1252
Spanish - Ecuador es es-ec 12298 1252
Spanish - El Salvador es es-sv 17418 1252
Spanish - Guatemala es es-gt 4106 1252
Spanish - Honduras es es-hn 18442 1252
Spanish - Mexico es es-mx 2058 1252
Spanish - Nicaragua es es-ni 19466 1252
Spanish - Panama es es-pa 6154 1252
Spanish - Paraguay es es-py 15370 1252
Spanish - Peru es es-pe 10250 1252
Spanish - Puerto Rico es es-pr 20490 1252
Spanish - Spain (Traditional) es es-es 1034 1252
Spanish - Uruguay es es-uy 14346 1252
Spanish - Venezuela es es-ve 8202 1252
Swahili sw sw 1089 441 1252
Swedish - Finland sv sv-fi 2077 1252
Swedish - Sweden sv sv-se 1053 1252
Syriac 1114
Tajik tg tg 1064 428
Tamil ta ta 1097 449
Tatar tt tt 1092 444 1251
Telugu te te 1098
Thai th th 1054
Tibetan bo bo 1105 451
Tsonga ts ts 1073 431
Turkish tr tr 1055 1254
Turkmen tk tk 1090 442
Ukrainian uk uk 1058 422 1251
Unicode UTF-8 0
Urdu ur ur 1056 420 1256
Uzbek - Cyrillic uz uz-uz 2115 843 1251
Uzbek - Latin uz uz-uz 1091 443 1254
Venda 1075 433
Vietnamese vi vi 1066 1258
Welsh cy cy 1106 452
Xhosa xh xh 1076 434
Yiddish yi yi 1085
Zulu zu zu 1077 435
ed48

   Locale Model FAQ  !      National Language Reference  !      LCID, Language Code Identifier  !      Code Pages  !



$category & $locale


LOCALEs are organized and identified according to RFC 5646.

Not all PHP functions are compatible with LOCALE.

Considering the LOCALE of a given system, we will have the following predefined constants if the extension  php_intl  is installed:

CONSTANT TYPE VALUE

DESCRIPTION
Locale::DEFAULT_LOCALE NULL

Used as locale parameter with the methods of the various locale affected classes, such as NumberFormatter.
This constant would make the methods to use default locale.
Locale::ACTUAL_LOCALE STRING 0

This is locale the data actually comes from.
Locale::VALID_LOCALE STRING 1

This is the most specific locale supported by ICU.
These constants define how the Locales are parsed or composed.
They should be used as keys in the argument array to locale_compose and are returned from locale_parse as keys of the returned associative array.
Locale::LANG_TAG STRING language

Language subtag.
Locale::EXTLANG_TAG STRING extlang

Extended Language subtag.
Locale::SCRIPT_TAG STRING script

Script subtag.
Locale::REGION_TAG STRING region

Region subtag.
Locale::VARIANT_TAG STRING variant

Variant subtag.
Locale::GRANDFATHERED_LANG_TAG STRING grandfathered

Grandfathered Language subtag.
Locale::PRIVATE_TAG STRING private

Private subtag.
ed48




In general, for systems other than Windows the main LOCALEs, can be seen in the below table:

LANGUAGE LOCALE ZONE
Afar aa ---
aa_DJ Djibouti
aa_ER Eritrea
aa_ET Ethiopia
Afrikaans af ---
af_NA Namibia
af_ZA South Africa
Akan ak ---
ak_GH Ghana
Amharic am ---
am_ET Ethiopia
Arabic ar ---
ar_AE United Arab Emirates
ar_BH Bahrain
ar_DZ Algeria
ar_EG Egypt
ar_IQ Iraq
ar_JO Jordan
ar_KW Kuwait
ar_LB Lebanon
ar_LY Libya
ar_MA Morocco
ar_OM Oman
ar_QA Qatar
ar_SA Saudi Arabia
ar_SD Sudan
ar_SY Syria
ar_TN Tunisia
ar_YE Yemen
Assamese as ---
as_IN India
Azerbaijani az ---
az_AZ Azerbaijan
Belarusian be ---
be_BY Belarus
Bulgarian bg ---
bg_BG Bulgaria
Bengali bn ---
bn_BD Bangladesh
bn_IN India
Tibetan bo ---
bo_CN China
bn_IN India
Bosnian bs ---
bs_BA Bosnia and Herzegovina
Blin byn ---
byn_ER Eritrea
Catalrn ca ---
ca_ES Spain
Atsam cch ---
cch_NG Nigeria
Coptic cop ---
Czech cs ---
cs_CZ Czech Republic
Welsh cy ---
cy_GB United Kingdom
Danish da ---
da_DK Denmark
German de ---
de_AT Austria
de_BE Belgium
de_CH Switzerland
de_DE Germany
de_LI Liechtenstein
de_LU Luxembourg
Divehi dv ---
dv_MV Maldives
Dzongkha dz ---
dz_BT Bhutan
Ewe ee ---
ee_GH Ghana
ee_TG Togo
Greek el ---
el_CY Cyprus
el_GR Greece
English en ---
en_AS American Samoa
en_AU Australia
en_BE Belgium
en_BW Botswana
en_BZ Belize
en_CA Canada
en_GB United Kingdom
en_GU Guam
en_HK Hong Kong
en_IE Ireland
en_IN India
en_JM Jamaica
en_MH Marshall Islands
en_MP Northern Mariana Islands
en_MT Malta
en_NA Namibia
en_NZ New Zealrnd
en_PH Philippines
en_PK Pakistan
en_SG Singapore
en_TT Trinidad and Tobago
en_UM United States Minor Outlying Islands
en_US United States
en_VI U.S. Virgin Islands
en_ZA South Africa
en_ZW Zimbabwe
Esperanto eo ---
Spanish es ---
es_AR Argentina
es_BO Bolivia
es_CL Chile
es_CO Colombia
es_CR Costa Rica
es_DO Dominican Republic
es_EC Ecuador
es_ES Spain
es_GT Guatemalr
es_HN Honduras
es_MX Mexico
es_NI Nicaragua
es_PA Panama
es_PE Peru
es_PR Puerto Rico
es_PY Paraguay
es_SV El Salvador
es_US United States
es_UY Uruguay
es_VE Venezuela
Estonian et ---
et_EE Estonia
Basque eu ---
eu_ES Spain
Persian fa ---
fa_AF Afghanistan
fa_IR Iran
Finnish fi ---
fi_FI Finland
Filipino fil ---
fil_PH Philippines
Faroese fo ---
fo_FO Faroe Islands
French fr ---
fr_BE Belgium
fr_CA Canada
fr_CH Switzerland
fr_FR France
fr_LU Luxembourg
fr_MC Monaco
fr_SN Senegal
Friulian fur ---
fur_IT Italy
Irish ga ---
ga_IE Ireland
Ga gaa ---
gaa_GH Ghana
Geez gez ---
gez_ER Eritrea
gez_ET Ethiopia
Gallegan gl ---
gl_ES Spain
Swiss German gsw ---
gsw_CH Swiss
Gujarati gu ---
gu_IN India
Manx gv ---
gv_GB United Kingdom
Hausa ha ---
ha_GH Ghana
ha_NE Niger
ha_NG Nigeria
ha_SD Sudan
Hawaiian haw ---
haw_US United States
Hebrew he ---
he_IL Israel
Hindi hi ---
hi_IN India
Croatian hr ---
hr_HR Croatia
Hungarian hu ---
hu_HU Hungary
Armenian hy ---
Interlingua ia ---
Indonesian id ---
id_ID Indonesia
Igbo ig ---
ig_NG Nigeria
Sichuan Yi ii ---
ii_CN China
Indonesian in ---
Icelandic is ---
is_IS Iceland
Italian it ---
it_CH Switzerland
it_IT Italy
Inuktitut iu ---
Hebrew iw ---
Japanese ja ---
ja_JP Japan
Georgian ka ---
ka_GE Georgia
Jju kaj ---
kaj_NG Nigeria
Kamba kam ---
kam_KE Kenya
Tyap kcg ---
kcg_NG Nigeria
Koro kfo ---
kfo_CI Ivory Coast
Kazakh kk ---
kk_KZ Kazakhstan
Kalrallisut kl ---
kl_GL Greenland
Khmer km ---
km_KH Cambodia
Kannada kn ---
kn_IN India
Korean ko ---
ko_KR South Korea
Konkani kok ---
kok_IN India
Kpelle kpe ---
kpe_GN Guinea
kpe_LR Liberia
Kurdish ku ---
ku_IQ Iraq
ku_IR Iran
ku_SY Syria
ku_TR Turkey
Cornish kw ---
kw_GB United Kingdom
Kirghiz ky ---
ky_KG Kyrgyzstan
Lingalr ln ---
ln_CD Congo - Kinshasa
ln_CG Congo - Brazzaville
Lao lo ---
lo_LA Laos
Lithuanian lt ---
lt_LT Lithuania
Latvian lv ---
lv_LV Latvia
Macedonian mk ---
mk_MK Macedonia
Malryalrm ml ---
ml_IN India
Mongolian mn ---
mn_CN China
mn_MN Mongolia
Romanian mo ---
Marathi mr ---
mr_IN India
Malry ms ---
ms_BN Brunei
ms_MY Malrysia
Maltese mt ---
mt_MT Malta
Burmese my ---
my_MM Myanmar
Norwegian Bokmal nb ---
nb_NO Norway
Low German nds ---
nds_DE Germany
Nepali ne ---
ne_IN India
ne_NP Nepal
Dutch nl ---
nl_BE Belgium
nl_NL Netherlands
Norwegian Nynorsk nn ---
nn_NO Norway
Norwegian no ---
South Ndebele nr ---
nr_ZA South Africa
Northern Sotho nso ---
nso_ZA South Africa
Nyanja ny ---
ny_MW Malrwi
Occitan oc ---
oc_FR France
Oromo om ---
om_ET Ethiopia
om_KE Kenya
Oriya or ---
or_IN India
Punjabi pa ---
pa_IN India
pa_PK Pakistan
Polish pl ---
pl_PL Poland
Pashto ps ---
ps_AF Afghanistan
Portuguese pt ---
pt_BR Brazil
pt_PT Portugal
Romanian ro ---
ro_MD Moldova
ro_RO Romania
Russian ru ---
ru_RU Russia
ru_UA Ukraine
Kinyarwanda rw ---
rw_RW Rwanda
Sanskrit sa ---
sa_IN India
Northern Sami se ---
se_FI Finland
se_NO Norway
Serbo-Croatian sh ---
sh_BA Bosnia and Herzegovina
sh_CS Serbia and Montenegro
sh_YU Serbia
Sinhalr si ---
si_LK Sri Lanka
Sidamo sid ---
sid_ET Ethiopia
Slovak sk ---
sk_SK Slovakia
Slovenian sl ---
sl_SI Slovenia
Somali so ---
so_DJ Djibouti
so_ET Ethiopia
so_KE Kenya
so_SO Somalia
Albanian sq ---
sq_AL Albania
Serbian sr ---
sr_BA Bosnia and Herzegovina
sr_CS Serbia and Montenegro
sr_ME Montenegro
sr_RS Serbia
sr_YU Serbia
Swati ss ---
ss_SZ Swaziland
ss_ZA South Africa
Southern Sotho st ---
st_LS Lesotho
st_ZA South Africa
Swedish sv ---
sv_FI Finland
sv_SE Sweden
Swahili sw ---
sw_KE Kenya
sw_TZ Tanzania
Syriac syr ---
syr_SY Syria
Tamil ta ---
ta_IN India
Telugu te ---
te_IN India
Tajik tg ---
tg_TJ Tajikistan
Thai th ---
th_TH Thailand
Tigrinya ti ---
ti_ER Eritrea
ti_ET Ethiopia
Tigre tig ---
tig_ER Eritrea
Tagalog tl ---
Tswana tn ---
tn_ZA South Africa
Tonga to ---
to_TO Tonga
Turkish tr ---
tr_TR Turkey
Taroko trv ---
trv_TW Taiwan
Tsonga ts ---
ts_ZA South Africa
Tatar tt ---
tt_RU Russia
Uighur ug ---
ug_CN China
Ukrainian uk ---
uk_UA Ukraine
Urdu ur ---
ur_IN India
ur_PK Pakistan
Uzbek uz ---
uz_AF Afghanistan
uz_UZ Uzbekistan
Venda ve ---
ve_ZA South Africa
Vietnamese vi ---
vi_VN Vietnam
Walrmo wal ---
wal_ET Ethiopia
Wolof wo ---
wo_SN Senegal
Xhosa xh ---
xh_ZA South Africa
Yoruba yo ---
yo_NG Nigeria
Chinese zh ---
zh_CN China
zh_HK Hong Kong
zh_MO Macau
zh_SG Singapore
zh_TW Taiwan
Zulu zu ---
zu_ZA South Africa
ed48


  1 EXERCISE   

 <?php

$locale01 
setlocale (LC_MONETARYNULL);

// the same as 

$locale02 setlocale (LC_MONETARY"");

echo 
'<br>' $locale01 '<br><br>' $locale02;

?> 

  2 EXERCISE   

 <?php

$locale03 
setlocale (LC_MONETARY0);

// the same as 

$locale04 setlocale (LC_MONETARY"0");

echo 
'<br>' $locale03 '<br><br>' $locale04;

?> 

  3 EXERCISE   

<?php

$locale05 
setlocale (LC_ALL'he_IL.utf-8''he_IL''he');

echo 
'<br>' $locale05 '<br><br>';

?> 

  4 EXERCISE   

<?php

$locale06 
setlocale (LC_ALL'pt_PT''pt');

echo 
'<br>' $locale06 '<br><br>';

?> 

  5 EXERCISE   

<?php

$locale07 
setlocale(LC_ALL"en_US""american"
                                              
"american english"
                                              
"american-english"
                                              
"english-american"
                                              
"english-us"
                                              
"english-usa"
                                              
"enu""us""usa");

echo 
'<br>' $locale07 '<br><br>';

?> 

  6 EXERCISE   

<?php

$locale08 
setlocale (LC_TIME'pt_BR''portuguese-brazil''ptb');

echo 
'<br>' $locale08 '<br><br>';

?> 

  7 EXERCISE   

<?php

// This implementation may present 
// some problems with IPV6 localhost

$lang substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 02);
$locale Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
$tz date_default_timezone_get();

$en 'LANGUAGE = [ ' $lang ' ]<br>
LOCALE obtained dynamically = ' 
.  $locale;

echo 
$en '<br>' $tz ;

?> 

 RESULT   

LANGUAGE = [ ]
LOCALE obtained dynamically =
America/Fortaleza