- Qt 6.10
- Qt Qml
- QML Types
- Locale
- Qt 6.10.3 Reference Documentation

# Locale QML Type

Provides locale specific properties and formatted data. More...

Import Statement: | `import QtQml`

- List of all members, including inherited members
- Deprecated members

## Properties

- amText : string
- decimalPoint : string
- exponential : string
- firstDayOfWeek : enumeration
- groupSeparator : string
- measurementSystem : enumeration
- name : string
- nativeLanguageName : string
- nativeTerritoryName : string
- negativeSign : string
- numberOptions : enumeration
- percent : string
- pmText : string
- positiveSign : string
- textDirection : enumeration
- uiLanguages : Array<string>
- weekDays : Array<int>
- zeroDigit : string

## Methods

- string createSeparatedList(list<string> list) `(since 6.10)`
- string currencySymbol(format)
- string dateFormat(type)
- string dateTimeFormat(type)
- string dayName(day, type)
- string formattedDataSize(int bytes, int precision, DataSizeFormat format) `(since 6.2)`
- string monthName(month, type)
- string standaloneDayName(day, type)
- string standaloneMonthName(month, type)
- string timeFormat(type)
- string toString(int i) `(since 6.5)`
- string toString(Date date, FormatType format) `(since 6.5)`
- string toString(Date date, string format) `(since 6.5)`
- string toString(double f, char format, int precision) `(since 6.5)`

## Detailed Description

The Locale object may only be created via the Qt.locale() function. It cannot be created directly.

The Qt.locale() function returns a JS Locale object representing the locale with the specified name, which has the format "language[_territory][.codeset][@modifier]" or "C".

Locale supports the concept of a default locale, which is determined from the system's locale settings at application startup. If no parameter is passed to Qt.locale() the default locale object is returned.

The Locale object provides a number of functions and properties providing data for the specified locale.

The Locale object may also be passed to the Date and Number toLocaleString() and fromLocaleString() methods in order to convert to/from strings using the specified locale.

This example shows the current date formatted for the German locale:

     import QtQuick 2.0

     Text {
         text: "The date is: " + Date().toLocaleString(Qt.locale("de_DE"))
     }

The following example displays the specified number in the correct format for the default locale:

     import QtQuick 2.0

     Text {
         text: "The value is: " + Number(23443.34).toLocaleString(Qt.locale())
     }

Qt Quick Locale's data is based on Common Locale Data Repository v1.8.1.

### Locale String Format Types

The monthName(), standaloneMonthName(), dayName() and standaloneDayName() can use the following enumeration values to specify the formatting of the string representation for a Date object.

Constant | Description
--- | ---
`Locale.LongFormat` | The long version of day and month names; for example, returning "January" as a month name.
`Locale.ShortFormat` | The short version of day and month names; for example, returning "Jan" as a month name.
`Locale.NarrowFormat` | A special version of day and month names for use when space is limited; for example, returning "J" as a month name. Note that the narrow format might contain the same text for different months and days or it can even be an empty string if the locale doesn't support narrow names, so you should avoid using it for date formatting. Also, for the system locale this format is the same as ShortFormat.

Additionally the double-to-string and string-to-double conversion functions are covered by the following licenses:

Copyright (c) 1991 by AT&T.

Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software.

THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.

This product includes software developed by the University of California, Berkeley and its contributors.

See also Date and Number.

## Property Documentation

amText : string

The localized name of the "AM" suffix for times specified using the conventions of the 12-hour clock.

decimalPoint : string

Holds the decimal point character of this locale.

exponential : string

Holds the exponential character of this locale.

firstDayOfWeek : enumeration

Holds the first day of the week according to the current locale.

Constant | Description
--- | ---
`Locale.Sunday` | 0
`Locale.Monday` | 1
`Locale.Tuesday` | 2
`Locale.Wednesday` | 3
`Locale.Thursday` | 4
`Locale.Friday` | 5
`Locale.Saturday` | 6

Note: that these values match the JS Date API which is different from the Qt C++ API where Qt::Sunday = 7.

groupSeparator : string

Holds the group separator character of this locale.

measurementSystem : enumeration

This property defines which units are used for measurement.

Constant | Description
--- | ---
`Locale.MetricSystem` | This value indicates metric units, such as meters, centimeters and millimeters.
`Locale.ImperialUSSystem` | This value indicates imperial units, such as inches and miles as they are used in the United States.
`Locale.ImperialUKSystem` | This value indicates imperial units, such as inches and miles as they are used in the United Kingdom.
`Locale.ImperialSystem` | Provided for compatibility. The same as Locale.ImperialUSSystem.

name : string

Holds the language and territory of this locale as a string of the form "language_territory", where language is a lowercase, two-letter ISO 639 language code, and territory is an uppercase, two- or three-letter ISO 3166 territory code.

nativeLanguageName : string

Holds a native name of the language for the locale. For example "Schwiizertüütsch" for Swiss-German locale.

See also nativeTerritoryName.

nativeTerritoryName : string

Holds a native name of the territory for the locale. For example "España" for Spanish/Spain locale.

See also nativeLanguageName.

negativeSign : string

Holds the negative sign character of this locale.

numberOptions : enumeration

Holds a set of options for number-to-string and string-to-number conversions.

See also Number::toLocaleString() and Number::fromLocaleString().

percent : string

Holds the percent character of this locale.

pmText : string

The localized name of the "PM" suffix for times specified using the conventions of the 12-hour clock.

positiveSign : string

Holds the positive sign character of this locale.

textDirection : enumeration

Holds the text direction of the language:

Constant | Description
--- | ---
`Qt.LeftToRight` | Text normally begins at the left side.
`Qt.RightToLeft` | Text normally begins at the right side.

uiLanguages : Array<string>

Returns an ordered list of locale names for translation purposes in preference order.

The return value represents locale names that the user expects to see the UI translation in.

The first item in the list is the most preferred one.

weekDays : Array<int>

Holds an array of days that are considered week days according to the current locale, where Sunday is 0 and Saturday is 6.

See also firstDayOfWeek.

zeroDigit : string

Holds Returns the zero digit character of this locale.

## Method Documentation

`[since 6.10]` string createSeparatedList(list<string> list)

Returns a string that represents a join of a given list of strings with a separator defined by the locale.

This method was introduced in Qt 6.10.

See also QLocale::createSeparatedList().

string currencySymbol(format)

Returns the currency symbol for the specified format:

Constant | Description
--- | ---
`Locale.CurrencyIsoCode` | a ISO-4217 code of the currency.
`Locale.CurrencySymbol` | a currency symbol.
`Locale.CurrencyDisplayName` | a user readable name of the currency.

See also Number::toLocaleCurrencyString().

string dateFormat(type)

Returns the date format used for the current locale. type specifies the FormatType to return.

See also Date.

string dateTimeFormat(type)

Returns the date time format used for the current locale. type specifies the FormatType to return.

See also Date.

string dayName(day, type)

Returns the localized name of the day (where 0 represents Sunday, 1 represents Monday and so on), in the optional FormatType specified by type.

See also monthName() and standaloneDayName().

`[since 6.2]` string formattedDataSize(int bytes, int precision, DataSizeFormat format)

Converts a size in bytes to a human-readable localized string, comprising a number and a quantified unit.

The precision and format arguments are optional.

For more information, see QLocale::formattedDataSize().

This method was introduced in Qt 6.2.

See also QLocale::DataSizeFormats.

string monthName(month, type)

Returns the localized name of month (0-11), in the optional FormatType specified by type.

Note: the QLocale C++ API expects a range of (1-12), however Locale.monthName() expects 0-11 as per the JS Date object.

See also dayName() and standaloneMonthName().

string standaloneDayName(day, type)

Returns the localized name of the day (where 0 represents Sunday, 1 represents Monday and so on) that is used as a standalone text, in the FormatType specified by type.

If the locale information does not specify the standalone day name then return value is the same as in dayName().

See also dayName() and standaloneMonthName().

string standaloneMonthName(month, type)

Returns the localized name of month (0-11) that is used as a standalone text, in the optional FormatType specified by type.

If the locale information doesn't specify the standalone month name then return value is the same as in monthName().

Note: the QLocale C++ API expects a range of (1-12), however Locale.standaloneMonthName() expects 0-11 as per the JS Date object.

See also monthName() and standaloneDayName().

string timeFormat(type)

Returns the time format used for the current locale. type specifies the FormatType to return.

See also Date.

`[since 6.5]` string toString(int i)

Returns a localized string representation of i.

This method was introduced in Qt 6.5.

See also QLocale::toString(int).

`[since 6.5]` string toString(Date date, FormatType format = LongFormat)

Returns a localized string representation of the given date in the specified format. If `format` is omitted, `Locale.LongFormat` is used.

This is an overloaded function.

This method was introduced in Qt 6.5.

See also QLocale::toString(QDate, QLocale::FormatType).

`[since 6.5]` string toString(Date date, string format)

Returns a localized string representation of the given date in the specified format. If `format` is an empty string, an empty string is returned.

This is an overloaded function.

This method was introduced in Qt 6.5.

See also QLocale::toString(QDate, QStringView).

`[since 6.5]` string toString(double f, char format = 'g', int precision = 6)

Returns a string representing the floating-point number f.

The form of the representation is controlled by the optional format and precision parameters.

See QLocale::toString(double, char, int) for more information.

This is an overloaded function.

This method was introduced in Qt 6.5.