internationalizationappcelerator-mobile

How do I do localization with Appcelerator?


I want to use strings so I don't have to have if statements for every language.


Solution

  • In every project, there is a directory called "i18n". In the subdirectory for "en", there is a file called "strings.xml".

    <?xml version="1.0" encoding="UTF-8"?>
    <resources>
    <string name="name">Hello</string>
    </resources>
    

    In your code, you can reference it like so:

    L('name');
    

    You can read more about the global L function here.