Titanium.Locale
> 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 getString method.

  • 1.5
  • 1.5
  • 1.5
Defined By

Properties

apiName : Stringreadonly

The name of the API that this proxy corresponds to.

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.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Indicates if the proxy will bubble an event to its parent. ...

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.

Default: true

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.Locale
currentCountry : Stringreadonly

Country of the current system locale, as an ISO 2-letter code.

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.

Titanium.Locale
currentLanguage : Stringreadonly

Language of the current system locale, as an ISO 2-letter code.

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.

Titanium.Locale
currentLocale : Stringreadonly

Current system locale, as a combination of ISO 2-letter language and country codes.

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.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

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.

  • 3.6.0
Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

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.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Titanium.Locale
( number ) : String
Formats a telephone number according to the current system locale. ...

Formats a telephone number according to the current system locale.

  • 1.5

Parameters

  • number : String

    Phone number.

Returns

  • String
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Locale
( locale ) : String
Returns the ISO 3-letter currency code for the specified locale. ...

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

  • locale : String

    Locale, as a combination of 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.

Returns

  • String
Titanium.Locale
( currencyCode ) : String
Returns the currency symbol for the specified currency code. ...

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

  • currencyCode : String

    Currency, as an ISO 3-letter code. For example, USD or GBP. See the Currency List section of the www.xe.com website for reference.

Returns

  • String
Titanium.Locale
( ) : String
Gets the value of the currentCountry property. ...

Gets the value of the currentCountry property.

Returns

  • String
Titanium.Locale
( ) : String
Gets the value of the currentLanguage property. ...

Gets the value of the currentLanguage property.

Returns

  • String
Titanium.Locale
( ) : String
Gets the value of the currentLocale property. ...

Gets the value of the currentLocale property.

Returns

  • String
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Locale
( locale ) : String
Returns the currency symbol for the specified locale. ...

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

  • locale : String

    Locale, as a combination of 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.

Returns

  • String
Titanium.Locale
( key, [hint] ) : String
Returns a string, localized according to the current system locale using the appropriate /i18n/LANG/strings.xml loca...

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 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.

Examples

String Localization Demonstration

Localize two strings, "hello" and "goodbye" (using the keys "greeting" and "signoff") for English and Spanish system locales.

Note: use the device's system settings to change locales and test this code.

/i18n/en/strings.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <string name="phrase" formatted="false">You say %2$s and I say %1$s!</string>
  <string name="greeting">hello</string>
  <string name="signoff">goodbye</string>
</resources>

/i18n/es/strings.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <string name="phrase" formatted="false">You say %2$s and I say %1$s!</string>
  <string name="greeting">hola</string>
  <string name="signoff">adios</string>
</resources>

/Resources/app.js

var i18nMissingMsg = '<no translation available>';

// for English locales, displays "You say goodbye and I say hello!"
// for Spanish locales, displays "You say adios and I say hola!"
Ti.API.info('You say ' + Ti.Locale.getString('signoff', i18nMissingMsg) + ' and I say ' + Ti.Locale.getString('greeting', i18nMissingMsg) + '!');

// uses alias L() instead of Ti.Locale.getString()
// formatted="false" is used in the strings.xml element for multiple string substitution
// for English locales, displays "You say goodbye and I say hello!"
// for Spanish locales, displays "You say adios and I say hola!"
Ti.API.info(String.format(L('phrase'), L('greeting', i18nMissingMsg), L('signoff', i18nMissingMsg)));

Parameters

  • key : String

    Key of string.

  • hint : String (optional)

    Text to return if key does not exist in the localization file.

Returns

  • String
Removes the specified callback as an event listener for the named event. ...

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);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Titanium.Locale
( language )
Sets the current language of the application. ...

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.

Parameters

  • language : String

    The specified ISO 639-1 code.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void