Search code examples
androidlocalizationtitaniumtitanium-mobile

Localizing Titanium Android application


I have a completed Titanium Android application (that the developer was not me). I want to localize it but both the strings and the UI are hard coded in the source code. The application built in javascript.

The UI is also important because we also want a right-to-left version of the app.

Need to mention that I'm pretty new to the Titanium environment.

What is the best approach to this task?


Solution

  • You would need to take the source code and find all the hard coded strings and move them to the il8n/ folder's string.xml file. You would need to create one of these files in the appropriate language directory with the string that corresponds to the particular hard coded value you want to represent.

    For example:

    var mystring = L('hi_text');
    

    In Titanium, this code would go to the language folder (of the device's setting, i.e. English or en folder) and look for an entry like this:

    il8n/en folder:

    <string name="hi_text">Hello</string>
    

    If the device was in Spanish language mode, that same code would then look to the il8n/es folder:

    <string name="hi_text">Hola<string>
    

    That would allow you to switch the language, but changing the UI would likely be a significant change to the source code. In the app.js file, you may attempt to detect the language of the device and branch to completely different logic for the screens. You could also do this in the particular screen javascript files as well, where you call one creation function for each different language. You will likely be changing the architecture of the application if it didn't already have that requirement built-in.