# Titanium.Locale
The top level Locale module.
# Overview
The Locale
module works with localization files to which are generated during compilation
into the operating system specific localization formats. The Locale
module provides
locale-specific strings which can be referenced at runtime. Additionally, the module
contains a few methods and properties for querying device locale information.
The macro L
can be used as an alias for the Titanium.Locale.getString method.
# Properties
# currentCountry READONLY
Country of the current system locale, as an ISO 2-letter code.
This property holds a value such as US
or GB
. See the
ISO 3166-1 alpha-2
country codes section of wikipedia for reference.
# currentLanguage READONLY
Language of the current system locale, as an ISO 2-letter code.
This property holds a value such as en
or fr
. See the
ISO 639-1 section of wikipedia for reference.
# currentLocale READONLY
Current system locale, as a combination of ISO 2-letter language and country codes.
This property holds a value such as en-US
or en-GB
.
See the ISO 639-1 and
ISO 3166-1 alpha-2
sections of wikipedia for reference.
# Methods
# formatTelephoneNumber
Formats a telephone number according to the current system locale.
Parameters
Name | Type | Description |
---|---|---|
number | String | Phone number. |
Returns
- Type
- String
# getCurrencyCode
Returns the ISO 3-letter currency code for the specified locale.
This method returns one of the ISO 4217 currency codes. For example,
getCurrencyCode('en-US')
returns USD
. See the xe.com
website
Currency List section of the www.xe.com
website for
reference.
Parameters
Name | Type | Description |
---|---|---|
locale | String | Locale, as a combination of ISO 2-letter language and country codes. For example,
|
Returns
- Type
- String
# getCurrencySymbol
Returns the currency symbol for the specified currency code.
This method returns one of the international currency symbols. For example,
getCurrencySymbol('USD')
returns $
. See the
Currency Symbols section of the
www.xe.com
website for reference.
Parameters
Name | Type | Description |
---|---|---|
currencyCode | String | Currency, as an ISO 3-letter code. For example, |
Returns
- Type
- String
# getLocaleCurrencySymbol
Returns the currency symbol for the specified locale.
This method returns one of the international currency symbols. For example,
getLocaleCurrencySymbol('en-US')
returns $
. See the
Currency Symbols section of the
www.xe.com
website for reference.
Parameters
Name | Type | Description |
---|---|---|
locale | String | Locale, as a combination of ISO 2-letter language and country codes. For example,
|
Returns
- Type
- String
# getString
Returns a string, localized according to the current system locale using the appropriate
/i18n/LANG/strings.xml
localization file.
This method is functionaly identical to its alias L. For example,
Ti.Locale.getString('thisKey', 'missing key')
produces the same result as
L('thisKey', 'missing key')
.
When using with format to localize a phrase with multiple string
substitution placeholders, add the formatted="false"
directive to the relevant
strings.xml
element. See example for a demonstration.
Parameters
Name | Type | Description |
---|---|---|
key | String | Key of string. |
hint | String | Text to return if key does not exist in the localization file. |
Returns
- Type
- String
# parseDecimal
Parses a number from the given string using the current or given locale.
Parameters
Name | Type | Description |
---|---|---|
text | String | The string to be parsed. |
locale | String | Locale, as a combination of ISO 2-letter language and country codes. For example,
|
Returns
Returns the parsed number. Returns NaN
(Not-a-Number) if given string is invalid.
- Type
- Number
# setLanguage
Sets the current language of the application.
This property holds a value such as en
or fr
. See the
ISO 639-1 section of wikipedia for reference.
On Android you can also specify combination of a ISO 2-letter language and country codes. For example,
en-US
or en-GB
. See the ISO 639-1 and
ISO 3166-1 alpha-2
sections of wikipedia for reference.
When changing to a language with a different layout direction, such as English to Arabic or vice-versa, you will need to close and re-open the window in order to apply the new right-to-left setting.
Parameters
Name | Type | Description |
---|---|---|
language | String | The specified ISO 639-1 code. |
Returns
- Type
- void