- Locales and Languages
- Mapping Locale Data
- Map Locale Data on Windows Vista and Later
- Map Locale Data on Pre-Windows Vista Operating Systems
- Calling the «Locale Name» Functions
- Example
- Table of locales
- Contents
- Introduction
- Support in operating systems
- openSUSE
- Ubuntu based
- Debian based
- RHEL/CentOS
- MoodleBox
- FreeBSD
- MacOS
- MS Windows
- Table
Locales and Languages
The term «language» indicates a collection of properties used in spoken and written communication. Each language has a language name and a language identifier that indicate the particular code page (ANSI, DOS, Macintosh) used to represent the geographical location for the language on the operating system. A neutral language is indicated by a name such as «en» for English. A more geographically specific language can be indicated by a name that includes both locale and country/region information. For example, the locale English (United States) has the language name «en-US».
A «locale» is a collection of language-related user preference information represented as a list of values. WindowsВ XP supports more than 150 locales, and WindowsВ Vista supports about 200. Each locale is defined by a language and a sort order, and has both a locale name and a locale identifier. An example of a locale name for German (Germany) is «de-DE_phonebook».
Each operating system has at least one installed locale and often has many locales from which the user can select. Each locale has a variety of information associated with it, other than its name and identifier. Locale information types are described in Locale Information Constants.
The operating system assigns a locale to each thread, initially assigning the «system default locale,» defined by LOCALE_SYSTEM_DEFAULT. This locale is set when the operating system is installed or when the user selects it using the regional and language options portion of the Control Panel. When running a thread in a process belonging to the user, the operating system assigns the «user default locale» to the thread. This locale is defined by LOCALE_USER_DEFAULT. An application can override either default by using the SetThreadLocale function to explicitly set the locale for a thread.
Implementation of a language requires a corresponding locale. The operating system implements a neutral language by selecting the data for the locale associated with a specific version of the language, usually the most widespread locale.
Starting with WindowsВ Vista, it is possible for a particular language to correspond to a supplemental locale, which is a type of custom locale. Since supplemental locales all share a single locale identifier, your applications should handle these locales and the corresponding languages by name instead of by identifier.
Language concepts are closely related to locale concepts, but the two terms are not interchangeable. As a general rule, functions related to the Multilingual User Interface deal with languages, while the NLS functions act upon locales.
The following topics are covered in this section:
Mapping Locale Data
NLS includes a number of API functions that your applications can use to map locale data between locale identifiers and locale names, and list neutral locales. This topic discusses the use of these functions on Windows Vista and later and on pre-WindowsВ Vista operating systems (sometimes called «downlevel systems»).
Map Locale Data on Windows Vista and Later
NLS provides several locale mapping functions for use by applications that you develop to run on WindowsВ Vista and later. It also includes functions that your applications can use to enumerate neutral locales.
Use the Standard Conversion Functions for Data Mapping
To map between a locale name and a locale identifier, your application can call the LocaleNameToLCID function. The application uses LCIDToLocaleName to map between a locale identifier and a locale name.
List Neutral Locales
To enumerate neutral locales for WindowsВ 7 and later, your application can call EnumSystemLocalesEx with dwFlags set to LOCALE_NEUTRALDATA. It can also use GetLocaleInfoEx with LCType set to LOCALE_INEUTRAL.
Map Locale Data on Pre-Windows Vista Operating Systems
NLS includes a direct-link library (DLL) to use for applications that you develop to run on pre-WindowsВ Vista operating systems. The DLL supports both conversion and listing functions for data mapping.
Applications that only run on WindowsВ Vista and later should not use the downlevel mapping or listing functions.
Use the Downlevel Conversion Functions for Data Mapping
Your application targeted at a downlevel system can call the DownlevelLCIDToLocaleName function to convert a locale identifier to a locale name. If it needs to convert a locale name to a locale identifier, it should call DownlevelLocaleNameToLCID.
Use the Downlevel Listing Functions to Enumerate Neutral Locales
Your application should call the DownlevelGetParentLocaleLCID to retrieve the locale identifier of the parent for a locale. If the application needs to get the locale name of the parent for the locale, it should call DownlevelGetParentLocaleName.
Calling the «Locale Name» Functions
WindowsВ Vista introduces a large number of functions that use locale names instead of locale identifiers. These new functions provide good support for supplemental locales, and several of them provide additional functionality not available in the older NLS functions. Some of them, such as the new enumeration functions, also represent design improvements.
Applications that are intended to run only on WindowsВ Vista and later should use the «locale name» functions in preference to the NLS functions that use locale identifiers.
The following table lists the locale name functions along with the older functions that they can replace.
Functions using locale names | Functions using locale identifiers |
---|---|
CompareStringEx | CompareString |
EnumCalendarInfoExEx | EnumCalendarInfo, EnumCalendarInfoEx |
EnumDateFormatsExEx | EnumDateFormats, EnumDateFormatsEx |
EnumSystemLocalesEx | EnumSystemLocales |
EnumTimeFormatsEx | EnumTimeFormats |
FindNLSStringEx | FindNLSString |
GetCalendarInfoEx | GetCalendarInfo |
GetCurrencyFormatEx | GetCurrencyFormat |
GetDateFormatEx | GetDateFormat |
GetDurationFormatEx | GetDurationFormat |
GetLocaleInfoEx | GetLocaleInfo |
GetNLSVersionEx | GetNLSVersion |
GetNumberFormatEx | GetNumberFormat |
GetSystemDefaultLocaleName | GetSystemDefaultLCID |
GetTimeFormatEx | GetTimeFormat |
GetUserDefaultLocaleName | GetUserDefaultLCID |
IsValidLocaleName | IsValidLocale |
LCMapStringEx | LCMapString |
Example
An example showing the use of several functions based on locale names can be found in NLS: Name-based APIs Sample.
Table of locales
Contents
Introduction
Definition: (from Wikipedia) Locale is a set of parameters that defines the user’s language, country and any special variant preferences that the user wants to see in their user interface. Usually a locale identifier consists of at least a language identifier and a region identifier.
Actually, the one and only place where Moodle requires some locales to be installed on the machine is when handling date translation (according to this information).
Currently such locales are named differently under Unix-based and Win32-based platforms so we need to have them defined separately to allow Moodle to use them as necessary. For each lang package’ available for Moodle, we must specify the locale value (Unix locale) and the localewin value (Win32 locale). Both those strings should be (no mandatory) defined inside each Moodle 1.6 and upwards langpack to be able to display locale strings properly.
The general syntax for locales is:
(with information under brackets being optional)
While the .charset part seems to work properly under Unix, it seems that is not working under Win32 (at least from PHP), and strings returned from some PHP functions aren’t in the charset specified but in some sort of default charset. Let’s call it localewincharset. This forces us to convert from this charset to the current_charset() being used by the user.
Support in operating systems
Just in case you freshly installed some new locales and they don’t seem to work don’t forget to restart your webserver.
openSUSE
- SUSE linux 10.1 contains all necessary locales in default installation
Ubuntu based
The default installation contains only limited number of locales. You can generate all locales on server from command line:
Debian based
The default installation contains only a limited number of locales. You can generate the locales you need on your server from the command line. Login as root and execute:
choose the ones you need and press OK, next select the default locale for your server and press OK.
RHEL/CentOS
Since RHEL/CentOS 8 you may need install additional language supports manually by dnf/yum (more info):
or, for saving disk space:
or, for all languages:
Then check that the locale appeared on the system:
MoodleBox
You can add locales by typing in the MoodleBox console:
FreeBSD
All 5.x and later versions should already contain a large number of supported locales with utf-8 charset.
MacOS
Mac OS support for many locales is very poor. There is no easy way to add new locales to a Mac OS.
You can find the installed locales by issuing the following command in a Mac:
Some people have attempted digital surgery to install a needed Mac locale, by copying an existing locale into a new file. You should really edit the newly copied file in order to make the changes needed from the source file in order to adapt to your real local settings (like currency). See this site and this one and this one too.
MS Windows
There is no way to add new locales, see following table for list of supported locales.
Table
So, for each 1.6 Moodle language pack, we’ll describe below this columns:
- package_name: name of the language pack as shown in http://download.moodle.org/lang16/.
- lang_name: name of the language as shown in http://download.moodle.org/lang16/.
- locale: locale string to be used under Unix platforms. This will be stored in each language langconfig.php file.
- localewin: locale string to be used under Win32 platforms. This will be stored in each language langconfig.php file.
- localewincharset: charset in which PHP is retrieving information from locale-dependent functions (strftime. ). This will allow us to convert such strings to the final charset properly. This will be stored in each language langconfig.php file.
package_name | lang_name | locale | localewin | localewincharset |
---|---|---|---|---|
af_utf8 | Afrikaans | af_ZA.UTF-8 | Afrikaans_South Africa.1252 | WINDOWS-1252 |
sq_utf8 | Albanian | sq_AL.UTF-8 | Albanian_Albania.1250 | WINDOWS-1250 |
ar_utf8 | Arabic | ar_SA.UTF-8 | Arabic_Saudi Arabia.1256 | WINDOWS-1256 |
eu_utf8 | Basque | eu_ES.UTF-8 | Basque_Spain.1252 | WINDOWS-1252 |
be_utf8 | Belarusian | be_BY.UTF-8 | Belarusian_Belarus.1251 | WINDOWS-1251 |
bs_utf8 | Bosnian | bs_BA.UTF-8 | Bosnian (Latin) | WINDOWS-1250 |
bg_utf8 | Bulgarian | bg_BG.UTF-8 | Bulgarian_Bulgaria.1251 | WINDOWS-1251 |
ca_utf8 | Catalan | ca_ES.UTF-8 | Catalan_Spain.1252 | WINDOWS-1252 |
hr_utf8 | Croatian | hr_HR.UTF-8 | Croatian_Croatia.1250 | WINDOWS-1250 |
zh_cn_utf8 | Chinese (Simplified) | zh_CN.UTF-8 | Chinese_China.936 | CP936 |
zh_tw_utf8 | Chinese (Traditional) | zh_TW.UTF-8 | Chinese_Taiwan.950 | CP950 |
cs_utf8 | Czech | cs_CZ.UTF-8 | Czech_Czech Republic.1250 | WINDOWS-1250 |
da_utf8 | Danish | da_DK.UTF-8 | Danish_Denmark.1252 | WINDOWS-1252 |
nl_utf8 | Dutch | nl_NL.UTF-8 | Dutch_Netherlands.1252 | WINDOWS-1252 |
en_utf8 | English | en.UTF-8 | English_Australia.1252 | -empty string- |
en_us_utf8 | English (US) | -parent en_utf8 used- | -parent en_utf8 used- | -parent en_utf8 used- |
et_utf8 | Estonian | et_EE.UTF-8 | Estonian_Estonia.1257 | WINDOWS-1257 |
fa_utf8 | Farsi | fa_IR.UTF-8 | Farsi_Iran.1256 | WINDOWS-1256 |
fil_utf8 | Filipino | fil_PH.UTF-8 | Filipino_Philippines.1252 | WINDOWS-1252 |
fi_utf8 | Finnish | fi_FI.UTF-8 | Finnish_Finland.1252 | WINDOWS-1252 |
fr_utf8 | French | fr_FR.UTF-8 or fr_CH.UTF-8 or fr_BE.UTF-8 | French_France.1252 | WINDOWS-1252 |
fr_ca_utf8 | French (Canada) | fr_CA.UTF-8 | French_Canada.1252 | -parent fr_utf8 used- |
ga_utf8 | Gaelic | ga.UTF-8 | Gaelic; Scottish Gaelic | WINDOWS-1252 |
gl_utf8 | Gallego | gl_ES.UTF-8 | Galician_Spain.1252 | WINDOWS-1252 |
ka_utf8 | Georgian | ka_GE.UTF-8 | Georgian_Georgia.65001 | -empty string- |
de_utf8 | German | de_DE.UTF-8 | German_Germany.1252 | WINDOWS-1252 |
de_du_utf8 | German (Personal) | de_DE.UTF-8 | -parent de_utf8 used- | -parent de_utf8 used- |
el_utf8 | Greek | el_GR.UTF-8 | Greek_Greece.1253 | WINDOWS-1253 |
gu_utf8 | Gujarati | gu.UTF-8 | Gujarati_India.0 | |
he_utf8 | Hebrew | he_IL.utf8 | Hebrew_Israel.1255 | WINDOWS-1255 |
hi_utf8 | Hindi | hi_IN.UTF-8 | Hindi.65001 | -empty string- |
hu_utf8 | Hungarian | hu.UTF-8 | Hungarian_Hungary.1250 | WINDOWS-1250 |
is_utf8 | Icelandic | is_IS.UTF-8 | Icelandic_Iceland.1252 | WINDOWS-1252 |
id_utf8 | Indonesian | id_ID.UTF-8 | Indonesian_indonesia.1252 | WINDOWS-1252 |
it_utf8 | Italian | it_IT.UTF-8 | Italian_Italy.1252 | WINDOWS-1252 |
ja_utf8 | Japanese | ja_JP.UTF-8 | Japanese_Japan.932 | CP932 |
kn_utf8 | Kannada | kn_IN.UTF-8 | Kannada.65001 | -empty string- |
km_utf8 | Khmer | km_KH.UTF-8 | Khmer.65001 | -empty string- |
ko_utf8 | Korean | ko_KR.UTF-8 | Korean_Korea.949 | EUC-KR |
lo_utf8 | Lao | lo_LA.UTF-8 | Lao_Laos.UTF-8 | WINDOWS-1257 |
lt_utf8 | Lithuanian | lt_LT.UTF-8 | Lithuanian_Lithuania.1257 | WINDOWS-1257 |
lv_utf8 | Latvian | lat.UTF-8 | Latvian_Latvia.1257 | WINDOWS-1257 |
ml_utf8 | Malayalam | ml_IN.UTF-8 | Malayalam_India.x-iscii-ma | x-iscii-ma |
ms_utf8 | Malaysian | ms_MY.UTF-8 | Malay_malaysia.1252 | WINDOWS-1252 |
mi_tn_utf8 | Maori (Ngai Tahu) | mi_NZ.UTF-8 | Maori.1252 | WINDOWS-1252 |
mi_wwow_utf8 | Maori (Waikoto Uni) | mi_NZ.UTF-8 | Maori.1252 | WINDOWS-1252 |
mn_utf8 | Mongolian | mn.UTF-8 | Cyrillic_Mongolian.1251 | |
no_utf8 | Norwegian | no_NO.UTF-8 | Norwegian_Norway.1252 | WINDOWS-1252 |
no_gr_utf8 | Norwegian (Primary) | no_NO.UTF-8 | -parent no_utf8 used- | -parent no_utf8 used- |
nn_utf8 | Nynorsk | nn_NO.UTF-8 | Norwegian-Nynorsk_Norway.1252 | WINDOWS-1252 |
pl_utf8 | Polish | pl.UTF-8 | Polish_Poland.1250 | WINDOWS-1250 |
pt_utf8 | Portuguese | pt_PT.UTF-8 | Portuguese_Portugal.1252 | WINDOWS-1252 |
pt_br_utf8 | Portuguese (Brazil) | pt_BR.UTF-8 | Portuguese_Brazil.1252 | WINDOWS-1252 |
ro_utf8 | Romanian | ro_RO.UTF-8 | Romanian_Romania.1250 | WINDOWS-1250 |
ru_utf8 | Russian | ru_RU.UTF-8 | Russian_Russia.1251 | WINDOWS-1251 |
sm_utf8 | Samoan | mi_NZ.UTF-8 | Maori.1252 | WINDOWS-1252 |
sr_utf8 | Serbian | sr_CS.UTF-8 | Bosnian(Cyrillic), Serbian (Cyrillic) | WINDOWS-1251 |
sk_utf8 | Slovak | sk_SK.UTF-8 | Slovak_Slovakia.1250 | WINDOWS-1250 |
sl_utf8 | Slovenian | sl_SI.UTF-8 | Slovenian_Slovenia.1250 | WINDOWS-1250 |
so_utf8 | Somali | so_SO.UTF-8 | not found! | not found! |
es_utf8 | Spanish (International) | es_ES.UTF-8 | Spanish_Spain.1252 | WINDOWS-1252 |
sv_utf8 | Swedish | sv_SE.UTF-8 | Swedish_Sweden.1252 | WINDOWS-1252 |
tl_utf8 | Tagalog | tl.UTF-8 | not found! | not found! |
ta_utf8 | Tamil | ta_IN.UTF-8 | English_Australia.1252 | |
th_utf8 | Thai | th_TH.UTF-8 | Thai_Thailand.874 | WINDOWS-874 |
to_utf8 | Tongan | mi_NZ.UTF-8′ | Maori.1252 | WINDOWS-1252 |
tr_utf8 | Turkish | tr_TR.UTF-8 | Turkish_Turkey.1254 | WINDOWS-1254 |
uk_utf8 | Ukrainian | uk_UA.UTF-8 | Ukrainian_Ukraine.1251 | WINDOWS-1251 |
vi_utf8 | Vietnamese | vi_VN.UTF-8 | Vietnamese_Viet Nam.1258 | WINDOWS-1258 |
Note: Some locales for windows in red could be incorrect (technically or geographically but they are the only way I’ve found to show dates properly in my XP box). Also some other coloured cells must be revised because they are not working.