Locales: Difference between revisions
AutoSpider (talk | contribs) (Convert ExpressionEngine links) |
(Cleanup) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{LangSwitch}} | ||
[[Category:QtInternals]] | [[Category:QtInternals]] | ||
''Written By : Girish Ramakrishnan, ForwardBias Technologies'' | |||
== Basics == | |||
= | |||
A locale is a set of parameters that define language and other preferences a user may choose for their interface. [ | A locale is a set of parameters that define language and other preferences a user may choose for their interface. [[Basics of Locales]] explains the basics. In Qt, locales are implemented using {{DocLink|QLocale}} and {{DocLink|QSystemLocale}}. | ||
= QSystemLocale = | == QSystemLocale == | ||
QSystemLocale is an interface to query the user's locale information. | QSystemLocale is an interface to query the user's locale information. QSystemLocale::query() can be used to query the locale data including the name of a month, the negative sign for numbers etc. | ||
QSystemLocale provides locale information from the Operating System. On Windows, QSystemLocale::query() uses [http://msdn.microsoft.com/en-us/library/dd318101(v=vs.85).aspx GetLocaleInfo]. On the Mac OS X, QSystemLocale::query() uses CFLocaleGetValue. On Linux, query() returns only the measurement system by inspecting the LC_MEASUREMENT, LC_ALL and LANG environment variables (in that order). | QSystemLocale provides locale information from the Operating System. On Windows, QSystemLocale::query() uses [http://msdn.microsoft.com/en-us/library/dd318101(v=vs.85).aspx GetLocaleInfo]. On the Mac OS X, QSystemLocale::query() uses CFLocaleGetValue. On Linux, query() returns only the measurement system by inspecting the LC_MEASUREMENT, LC_ALL and LANG environment variables (in that order). | ||
Line 20: | Line 15: | ||
QSystemLocale::query() can be overridden by an application to provide further customizations to the user's locale. | QSystemLocale::query() can be overridden by an application to provide further customizations to the user's locale. | ||
= The default locale = | == The default locale == | ||
Qt programs can be run in any locale by setting the 'default' locale using QLocale::setDefault(). When the default locale is not set, Qt uses the information from QSystemLocale i.e the locale information from the Operating System. | Qt programs can be run in any locale by setting the 'default' locale using QLocale::setDefault(). When the default locale is not set, Qt uses the information from QSystemLocale i.e the locale information from the Operating System. | ||
= QLocale = | == QLocale == | ||
QLocale is the "front-end" class that helps in formatting data based on a locale id. QLocale uses the <language>_<country>.<codeset> format for the locale identifier. A QLocale that is created using no arguments (QLocale()) is equivalent to the default locale. When the default locale is not set, QLocale() is equivalent to the system locale. | QLocale is the "front-end" class that helps in formatting data based on a locale id. QLocale uses the <language>_<country>.<codeset> format for the locale identifier. A QLocale that is created using no arguments (QLocale()) is equivalent to the default locale. When the default locale is not set, QLocale() is equivalent to the system locale. | ||
Line 34: | Line 29: | ||
* When a default locale is set or a QLocale object is created with a locale id, formatting information is obtained from CLDR data. | * When a default locale is set or a QLocale object is created with a locale id, formatting information is obtained from CLDR data. | ||
= Fallback locale = | == Fallback locale == | ||
The Fallback locale ( | The Fallback locale (QSystemLocale::fallbackLocale) is a QLocale created with the locale id detected using environment variables (LC_ALL and LANG). If the environment variables are not set, GetUserDefaultLCID is used on Windows and CFLocaleGetIdentifier is used on Mac OS X. | ||
= Widgets and locales = | == Widgets and locales == | ||
Every widget can be set a locale individually using QWidget::setLocale(). Locales propagate from parent to children. When not set, it is the same as the default locale. Locale settings propagate to children. Qt sends a QEvent::LocaleChange event to a widget when it's locale changes. | Every widget can be set a locale individually using QWidget::setLocale(). Locales propagate from parent to children. When not set, it is the same as the default locale. Locale settings propagate to children. Qt sends a QEvent::LocaleChange event to a widget when it's locale changes. |
Latest revision as of 20:37, 28 June 2015
Written By : Girish Ramakrishnan, ForwardBias Technologies
Basics
A locale is a set of parameters that define language and other preferences a user may choose for their interface. Basics of Locales explains the basics. In Qt, locales are implemented using QLocale and QSystemLocale.
QSystemLocale
QSystemLocale is an interface to query the user's locale information. QSystemLocale::query() can be used to query the locale data including the name of a month, the negative sign for numbers etc.
QSystemLocale provides locale information from the Operating System. On Windows, QSystemLocale::query() uses GetLocaleInfo. On the Mac OS X, QSystemLocale::query() uses CFLocaleGetValue. On Linux, query() returns only the measurement system by inspecting the LC_MEASUREMENT, LC_ALL and LANG environment variables (in that order).
QSystemLocale::query() can be overridden by an application to provide further customizations to the user's locale.
The default locale
Qt programs can be run in any locale by setting the 'default' locale using QLocale::setDefault(). When the default locale is not set, Qt uses the information from QSystemLocale i.e the locale information from the Operating System.
QLocale
QLocale is the "front-end" class that helps in formatting data based on a locale id. QLocale uses the <language>_<country>.<codeset> format for the locale identifier. A QLocale that is created using no arguments (QLocale()) is equivalent to the default locale. When the default locale is not set, QLocale() is equivalent to the system locale.
There are two code paths that QLocale uses to determine the formatting information. The first case is when the default locale (QLocale::setDefault) has not been set and a QLocale object with no constructor arguments is used. In such a case, QLocale() queries all formatting information through QSystemLocale::query(). This results in QLocale formatting data as it has been configured in the Operating System. In the second case, a default locale has been set or a QLocale object is created with a language and country (locale id). In this case, Qt refers to qlocale_data_p.h to determine how to format data. qlocale_data_p.h is generated from CLDR using the cldr2qlocalexml.py and qlocalexml2cpp.py scripts at local_database.
To reiterate:
- When using the system locale, formatting information is queried from the OS and not CLDR data.
- When a default locale is set or a QLocale object is created with a locale id, formatting information is obtained from CLDR data.
Fallback locale
The Fallback locale (QSystemLocale::fallbackLocale) is a QLocale created with the locale id detected using environment variables (LC_ALL and LANG). If the environment variables are not set, GetUserDefaultLCID is used on Windows and CFLocaleGetIdentifier is used on Mac OS X.
Widgets and locales
Every widget can be set a locale individually using QWidget::setLocale(). Locales propagate from parent to children. When not set, it is the same as the default locale. Locale settings propagate to children. Qt sends a QEvent::LocaleChange event to a widget when it's locale changes.