Supporting Multiple Languages

  • 69 favourites

Attached Files

The following files have been attached to this tutorial:



Download now 132.85 KB


Download now 301.54 KB


5,487 visits, 8,895 views


This tutorial hasn't been translated.



This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Here is a method for supporting multiple languages using XML and project files.

[Note: XML doesn't work on CocoonJS - there is a capx using JSON instead on the left]


Each language will have it’s own file called strings.xx.xml where xx is the two letter ISO 639-1 code for that language.



The English xml file (strings.en.xml) looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
       <string id='world'>World</string>
       <string id='level'>Level</string>
       <string id='begin'>Press 'Enter' to begin.</string>

Each piece of text has an ID (world/level/begin) and a value (World/Level/Press ‘Enter’ to begin.)

Other languages will have the same file structure with the same IDs but different values

eg. German (

    <?xml version="1.0" encoding="UTF-8"?>
       <string id='world'>Welt</string>
       <string id='level'>Stufe</string>
       <string id='begin'>Drücken Sie die Eingabetaste, um zu beginnen.</string>

The xml files are added as project files. (Adding project files.)

Changing the Language


We will store the current language in a global variable called language. And we’ll add a function called “changeLanguage” which will change the language to whatever value we pass to the function.


f.Call(“changeLanguage”, “en”) will change the language to English.

The “changeLanguage” function will update the global variable and then load the appropriate file.

Loading the XML File


When the AJAX request has completed we load the file (AJAX.LastData) into an XML object. Then we call the “updateText” function to change the text on-screen.

Updating the Text


The “updateText” function simply sets the text for all text objects. We get the correct text for the current language by calling the “getText” function and passing it the string ID as a parameter.

You might also want to change the animations on some sprites to match the new language.

Getting the Correct String From the XML File


The “getText” function takes a string id (eg. “begin”) and returns the value in the XML file that matches. To get the value from the XML we use the XML.StringValue(XPath) expression.

There is more info about XPath on the XML manual page.

To get the value of the string node with id=’begin’ we use the XPath expression:


“/strings” chooses all the “strings” nodes (there’s only one)

“/strings/string” chooses all the “string” nodes that are children (sub-nodes) of “strings” (3 nodes in this example)

“/strings/string chooses the “string” node with attribute ‘id’ equal to ‘begin’

and finally

“/strings/string/text()” gives us the value at that node

Adding More Languages

To add a new language eg. Dutch, you just copy one of the XML files to and change all the values to their Dutch equivalent. And then use

     f.Call(“changeLanguage”, “nl”)

Simple as that.



Download now 132.85 KB


Download now 301.54 KB

  • Order by
Want to leave a comment? Login or Register an account!