Appcelerator Blog

The Leading Resource for All Things Mobile

Getting your app ready for international markets

1 Flares 1 Flares ×

If you’re writing an app that could potentially be downloaded from anywhere on the planet, you should probably think about internationalizing it. This process allows you to set all the screen prompts and messages in language-specific files.

When your user sets the language of his/her phone, this language is available to Titanium via the Ti.Locale module as a two-letter code following the ISO 639-1 standard. Titanium provides you a very easy mechanism that will allow your app to adjust its language according to the language of your user’s phone.

Adding localization support to your app

Your Titanium app is already capable of doing this. To start, create a folder named i18n (I and N are the first and last letters of the word Internationalization, and 18 is the amount of letters between them). This folder should live in the root of your app, that is, at the same level as /app and /Resources. Inside this folder create a subfolder with the two-letter code for the language you wish to support. Finally, create a file named strings.xml and save it into each of the language-specific subfolders.


The strings.xml file contains a definition of strings used throughout your app. Here you’ll add label captions, button captions, tab names, window names, message boxes, etc. This is an example file:


< ?xml version="1.0" encoding="UTF-8"?>

    My app's title
    The platform is %1$ and the language is %2$


< ?xml version="1.0" encoding="UTF-8"?>

    El título de mi app
    La plataforma es %1$ y el idioma es %2$

Localizing your app’s name

You can also change the actual name of your app using the special app.xml file.


< ?xml version="1.0" encoding="UTF-8"?>

    My App Name

Using your localized files

Now that you have your platform-specific string files, it’s time to use them on your app. The Ti.Locale provides you with the getString method, which goes to the strings.xml file for the current locale, and returns the specified string, for example:


GetString has a second argument for the default text, in case there is not translation for the selected locale:

Ti.Locale.getString('welcome_message','Welcome to my app');

You can also add variables to your strings. For example:

The time is %s

You can call this string like:

var d = new Date();
var theTime=d.getHours() + ":" + d.getMinutes()
var timeString=String.format(Ti.Locale.getString('dynamic_string'),theTime);

Note: The String.format function uses the IEEE printf specification.

Titanium provides you with a convenience macro named L that can be used instead of Ti.Locale.getString.

var timeString=String.format(L('dynamic_string'),theTime);

Another way of assigning localized strings to your Titanium objects is by using the titleid property available in most controls such as buttons, windows and tabs. For example:

var myButton=Ti.UI.createButton({
    titleid: 'send_button'    

In this example, send_button is the name of the string inside your strings.xml file.

If you’re using Alloy, the examples above will work in your controllers. However you can also use the L macro from your TSS file like so:

'#myButton': {
    title: L('hello_world')

Finally, it’s also accesible from Alloy’s XML views:

This methodology not only provides a higher level of accessibility to your app when working with international markets, but should be considered a best practice event when building an app for a single language, as it provides you with a way of decoupling language specific settings from the actual code.

1 Flares Twitter 0 Facebook 0 Google+ 1 LinkedIn 0 Email -- 1 Flares ×

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
1 Flares Twitter 0 Facebook 0 Google+ 1 LinkedIn 0 Email -- 1 Flares ×