Titanium.Locale
The top level Locale module.
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.
Extends: Titanium.Module · Since: 1.5
Properties #
apiName#
Type: String
The name of the API that this proxy corresponds to.
The value of this property is the fully qualified name of the API. For example, Button
returns Ti.UI.Button.
bubbleParent#
Type: Boolean
Indicates if the proxy will bubble an event to its parent.
Some proxies (most commonly views) have a relationship to other proxies, often
established by the add() method. For example, for a button added to a window, a
click event on the button would bubble up to the window. Other common parents are
table sections to their rows, table views to their sections, and scrollable views
to their views. Set this property to false to disable the bubbling to the proxy's parent.
currentCountry#
Type: String
Country of the app's current 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#
Type: String
Language of the app's current 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#
Type: String
Current app 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.
lifecycleContainer#
Type: Titanium.UI.Window, Titanium.UI.TabGroup
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks
will also be called on the proxy. Proxies that require the activity lifecycle will need this property set
to the appropriate containing Window or TabGroup.
Methods #
addEventListener #
Adds the specified callback as an event listener for the named event.
| Name | Type | Summary | Optional |
|---|---|---|---|
name | String | Name of the event. | No |
callback | Callback<Titanium.Event> | Callback function to invoke when the event is fired. | No |
applyProperties #
Applies the properties to the proxy.
Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that
myproxy[key] = value.
| Name | Type | Summary | Optional |
|---|---|---|---|
props | Dictionary | A dictionary of properties to apply. | No |
fireEvent #
Fires a synthesized event to any registered listeners.
| Name | Type | Summary | Optional |
|---|---|---|---|
name | String | Name of the event. | No |
event | Dictionary | A dictionary of keys and values to add to the Titanium.Event object sent to the listeners. | Yes |
formatTelephoneNumber #
Formats a telephone number according to the current system locale.
| Name | Type | Summary | Optional |
|---|---|---|---|
number | String | Phone number. | No |
Returns: 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.
| Name | Type | Summary | Optional |
|---|---|---|---|
locale | String | Locale, as a combination of ISO 2-letter language and country codes. For example,en-US or en-GB. See theISO 639-1 and ISO 3166-1 alpha-2 sections of wikipedia for reference. | No |
Returns: 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.
| Name | Type | Summary | Optional |
|---|---|---|---|
currencyCode | String | Currency, as an ISO 3-letter code. For example, USD or GBP. See theCurrency List section of the www.xe.com website forreference. | No |
Returns: 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.
| Name | Type | Summary | Optional |
|---|---|---|---|
locale | String | Locale, as a combination of ISO 2-letter language and country codes. For example,en-US or en-GB. See theISO 639-1 and ISO 3166-1 alpha-2 sections of wikipedia for reference. | No |
Returns: String
getString #
Returns a string, localized according to the current system locale using the appropriate
/i18n/LANG/strings.xml localization file.
This method is functionally identical to its alias <Global.L>. For example,
Ti.Locale.getString('thisKey', 'missing key') produces the same result as
L('thisKey', 'missing key').
When using with <Global.String.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.
| Name | Type | Summary | Optional |
|---|---|---|---|
key | String | Key of string. | No |
hint | String | Text to return if key does not exist in the localization file. | Yes |
Returns: String
parseDecimal #
Parses a number from the given string using the current or given locale.
| Name | Type | Summary | Optional |
|---|---|---|---|
text | String | The string to be parsed. | No |
locale | String | Locale, as a combination of ISO 2-letter language and country codes. For example,en-US or en-GB. See theISO 639-1 and ISO 3166-1 alpha-2 sections of wikipedia for reference. | Yes |
Returns: Number — Returns the parsed number. Returns `NaN` (Not-a-Number) if given string is invalid.
removeEventListener #
Removes the specified callback as an event listener for the named event.
Multiple listeners can be registered for the same event, so the
callback parameter is used to determine which listener to remove.
When adding a listener, you must save a reference to the callback function
in order to remove the listener later:
var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);
To remove the listener, pass in a reference to the callback function:
window.removeEventListener('click', listener);
| Name | Type | Summary | Optional |
|---|---|---|---|
name | String | Name of the event. | No |
callback | Callback<Titanium.Event> | Callback function to remove. Must be the same function passed to addEventListener. | No |
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.
This will restart the app internally to properly apply the new language setting. If you want to avoid
this behavior, you can listen for the change event and handle the language change manually.
When a custom language is set using this method, the SDK will persist this setting across app restarts.
| Name | Type | Summary | Optional |
|---|---|---|---|
language | String | The specified ISO 639-1 code. | No |