Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Locales: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[QtLocales Bulgarian|Български]]
'''English''' [[QtLocales_Bulgarian|Български]]<br />[[Category:QtInternals]]
 
[toc align_right=&quot;yes&amp;quot; depth=&quot;1&amp;quot;]


Written By : Girish Ramakrishnan, ForwardBias Technologies
Written By : Girish Ramakrishnan, ForwardBias Technologies


=Basics=
= Basics =
 
A locale is a set of parameters that define language and other preferences a user may choose for their interface. [http://developer.qt.nokia.com/wiki/BasicsOfLocales Basics of Locales] ''[developer.qt.nokia.com]'' explains the basics. In Qt, locales are implemented using QLocale and QSystemLocale.
 
=QSystemLocale=
 
QSystemLocale is an interface to query the user’s locale information. [http://doc.qt.nokia.com/qsystemlocale.html#query QSystemLocale::query()] ''[doc.qt.nokia.com]'' 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 GetLocaleInfo] ''[msdn.microsoft.com]'').aspx. 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 <span class="caps">LANG</span> environment variables (in that order).
A locale is a set of parameters that define language and other preferences a user may choose for their interface. &quot;Basics of Locales&amp;quot;:http://developer.qt.nokia.com/wiki/BasicsOfLocales explains the basics. In Qt, locales are implemented using QLocale and QSystemLocale.


QSystemLocale::query() can be overridden by an application to provide further customizations to the user’s locale.
= QSystemLocale =


=The default locale=
QSystemLocale is an interface to query the user's locale information. &quot;QSystemLocale::query()&quot;:http://doc.qt.nokia.com/qsystemlocale.html#query can be used to query the locale data including the name of a month, the negative sign for numbers etc.


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.
QSystemLocale provides locale information from the Operating System. On Windows, QSystemLocale::query() uses &quot;GetLocaleInfo&amp;quot;:http://msdn.microsoft.com/en-us/library/dd318101(v=vs.85).aspx. 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).


=QLocale=
QSystemLocale::query() can be overridden by an application to provide further customizations to the user's locale.


QLocale is the “front-end” class that helps in formatting data based on a locale id. QLocale uses the &lt;language&gt;_&lt;country&gt;.&lt;codeset&gt; 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.
= The default 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 [http://qt.gitorious.org/+qt-developers/qt/releases/blobs/0d00798f6bdd098dbb59c6f1da5be5efd6c283fa/src/corelib/tools/qlocale_data_p.h qlocale_data_p.h] ''[qt.gitorious.org]'' to determine how to format data. qlocale_data_p.h is generated from [http://cldr.unicode.org/index/downloads <span class="caps">CLDR</span>] ''[cldr.unicode.org]'' using the cldr2qlocalexml.py and qlocalexml2cpp.py scripts at [http://qt.gitorious.org/qt/qt/trees/169099b5e9c77c6633deb3c7bb949800a5f80ec2/util/local_database local_database] ''[qt.gitorious.org]''.
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.


To reiterate:
= QLocale =


* When using the system locale, formatting information is queried from the OS and not <span class="caps">CLDR</span> data.
QLocale is the &quot;front-end&amp;quot; class that helps in formatting data based on a locale id. QLocale uses the &lt;language&amp;gt;_&lt;country&amp;gt;.&lt;codeset&amp;gt; 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.
* When a default locale is set or a QLocale object is created with a locale id, formatting information is obtained from <span class="caps">CLDR</span> data.


=Fallback 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 &quot;qlocale_data_p.h&amp;quot;:http://qt.gitorious.org/+qt-developers/qt/releases/blobs/0d00798f6bdd098dbb59c6f1da5be5efd6c283fa/src/corelib/tools/qlocale_data_p.h to determine how to format data. qlocale_data_p.h is generated from &quot;CLDR&amp;quot;:http://cldr.unicode.org/index/downloads using the cldr2qlocalexml.py and qlocalexml2cpp.py scripts at &quot;local_database&amp;quot;:http://qt.gitorious.org/qt/qt/trees/169099b5e9c77c6633deb3c7bb949800a5f80ec2/util/local_database.


The Fallback locale ([http://doc.qt.nokia.com/qsystemlocale.html#fallbackLocale QSystemLocale::fallbackLocale] ''[doc.qt.nokia.com]'') is a QLocale created with the locale id detected using environment variables (LC_ALL and <span class="caps">LANG</span>). If the environment variables are not set, GetUserDefaultLCID is used on Windows and CFLocaleGetIdentifier is used on Mac OS X.
To reiterate:<br />* When using the system locale, formatting information is queried from the OS and not CLDR data.<br />* When a default locale is set or a QLocale object is created with a locale id, formatting information is obtained from CLDR data.


=Widgets and locales=
= Fallback locale =


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.
The Fallback locale (&quot;QSystemLocale::fallbackLocale&amp;quot;:http://doc.qt.nokia.com/qsystemlocale.html#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.


===Categories:===
= Widgets and locales =


* [[:Category:QtInternals|QtInternals]]
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.

Revision as of 09:04, 24 February 2015

English Български

[toc align_right="yes&quot; depth="1&quot;]

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&quot;:http://developer.qt.nokia.com/wiki/BasicsOfLocales 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()":http://doc.qt.nokia.com/qsystemlocale.html#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&quot;:http://msdn.microsoft.com/en-us/library/dd318101(v=vs.85).aspx. 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&quot; class that helps in formatting data based on a locale id. QLocale uses the <language&gt;_<country&gt;.<codeset&gt; 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&quot;:http://qt.gitorious.org/+qt-developers/qt/releases/blobs/0d00798f6bdd098dbb59c6f1da5be5efd6c283fa/src/corelib/tools/qlocale_data_p.h to determine how to format data. qlocale_data_p.h is generated from "CLDR&quot;:http://cldr.unicode.org/index/downloads using the cldr2qlocalexml.py and qlocalexml2cpp.py scripts at "local_database&quot;:http://qt.gitorious.org/qt/qt/trees/169099b5e9c77c6633deb3c7bb949800a5f80ec2/util/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&quot;:http://doc.qt.nokia.com/qsystemlocale.html#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.