# Changing language with xml

**URL:** <https://forum.kirupa.com/t/changing-language-with-xml/61147>\
**Category:** Uncategorized\
**Created:** [August 16, 2004, 2:39pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147 "2004-08-16T14:39:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ubik](https://avatars.discourse-cdn.com/v4/letter/u/b38774/32.png) [@Ubik](https://forum.kirupa.com/u/Ubik)\
**Post date:** [August 16, 2004, 2:39pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/1 "2004-08-16T14:39:08Z")

</div>

I followed this thread[http://www.kirupaforum.com/forums/showthread.php?t=53675&highlight=change+language+dynamically](http://www.kirupaforum.com/forums/showthread.php?t=53675&highlight=change+language+dynamically) to learn how to change the language dynamically. I have 2 buttons and one swf loaded into another. My problem is that it works very partially : text doesn’t show if i don’t click a button (button are here just to change the language) and if i click a button it doesn’t affect the loaded swf.  
It is my first attempt with xml, so be indulgent 😊  
Files are here :[www.artefakt.be/xml.zip](http://www.artefakt.be/xml.zip)  
Thanks !

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 16, 2004, 8:20pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/2 "2004-08-16T20:20:07Z")

</div>

Hi Ubik, I’ve used the following in my own site:

[COLOR=RoyalBlue]\_global.language = System.capabilities.language;[/COLOR]  
This will give to you the language that uses the visitors machine,  
then you will put your xml texts in different language folders (es,en,it, etc.)  
and with this actions you create the path to the correct xml folder:

[COLOR=RoyalBlue]// External XML file to load.  
var xmlFileToLoad:String = language + “/main.xml”;  
// Load External XML file  
contentXML.load(xmlFileToLoad);;[/COLOR]

Otherwise, if you want a button to change the language, when the button is clicked you must set the “language” variable to the desired language and then force to reload your xml files.

Hope this helps

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 9:13am UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/3 "2004-08-17T09:13:47Z")

</div>

Thanks for you answer penmig,  
In fact i would like people to be able to click a button to change the language. When you click a button it also has to change the text of the loaded swf, that’s what i’m trying to do in my file (with no success ☹ )

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 12:24pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/4 "2004-08-17T12:24:43Z")

</div>

Hi Ubik, here you will find an example of what you want to do:

[COLOR=Blue][http://www.flashkit.com/movies/Scripting/XML/XML\_\_FL-Ed\_Reyes-7930/index.php](http://www.flashkit.com/movies/Scripting/XML/XML__FL-Ed_Reyes-7930/index.php)[/COLOR]

Have a nice day

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 12:38pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/5 "2004-08-17T12:38:48Z")

</div>

Oh that’s fine ! Thanks Penmig !  
Hum, sorry,Do you know how can i apply it to loaded movie ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 1:02pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/6 "2004-08-17T13:02:34Z")

</div>

Sorry Ubik, but I don’t understand what you mean for “loaded movie”.  
If the visitor click a button to change the language then you must reload the movie with the new language parameter or simply load again the xml with the requested language in the loaded movie.  
Another way is to define a global variable [COLOR=Blue](var \_global.language = “nl”;)[/COLOR], in your main movie, when you load a new movie, this one gets the actual language from the “language” variable and in this way reads the correct XML file.  
If your xml file for dutch is [COLOR=Blue]txtnl[/COLOR] and the requested language is french, you will change the file name:  
[COLOR=Blue]var fileToLoad = “txt”+language+".xml"  
xmlData.load(fileToLoad ); [/COLOR]

Hope you understand my explanation.

Regards

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 1:21pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/7 "2004-08-17T13:21:21Z")

</div>

May be now will be more clear:  
This is the script for your main movie:  
[COLOR=Blue][COLOR=Red]// Set de default language  
var \_global.language = “nl”;[/COLOR]  
// Load XML file  
function loadXML(loaded) {  
if (loaded) {  
this.titre = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;  
this.txt = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;  
titr.text = this.titre;  
texte.text = this.txt;  
} else {  
trace(“file not loaded!”);  
}  
}  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
[COLOR=Red]// Build the XML file name  
var fileToLoad = “txt”+language+".xml"  
xmlData.load(fileToLoad );[/COLOR] [/COLOR]  
This is the script for the second movie:  
[COLOR=Blue]function loadXML(loaded) {  
if (loaded) {  
this.titre = this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;  
this.txt = this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;  
titre2.text = this.titre;  
texte2.text = this.txt;  
} else {  
trace(“file not loaded!”);  
}  
}  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
[COLOR=Red]// Build the XML file name  
var fileToLoad = “txt”+language+".xml"  
xmlData.load(fileToLoad );[/COLOR]  
//[/COLOR]

If you use a button to change language the action for the button will be:

[COLOR=Blue]btn\_dutch.onRelease = function () {  
language = “nl”;  
};  
btn\_french.onRelease = function () {  
language = “fr”;  
};[/COLOR]

It’s important you create a function to reload the XML when the visitors press a button to change the language.

Hope now it’s clear :}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 1:27pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/8 "2004-08-17T13:27:54Z")

</div>

I was just replying 🙂 but you’re too quick, i’ll test that immediatly ! Thanks you very much Penmig:) !  
oh and it is var \_global.language = “fr”; 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 1:45pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/9 "2004-08-17T13:45:16Z")

</div>

Don’t forget to reload your second movie when you change the language, otherwise it will not work as you want.  
So create this function to reload the XML:  
[COLOR=Blue]function reloadXML() {  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
// Build the XML file name  
var fileToLoad = “txt”+language+".xml"  
xmlData.load(fileToLoad );  
}:[/COLOR]

And then, the button action will be:

[COLOR=Blue]btn\_dutch.onRelease = function () {  
language = “nl”;  
reloadXML()  
ici.loadMovie (“testXml2.swf”)  
};[/COLOR]

I think this is what you want. 😛

Note: It’s a good practice to use folders to contain all the xml files for each language you use in complex projects, in this way the document has the same name (main.xml, 1stmovie, 2ndmovie, etc.) and the location for the language is the folders name (fr,nl, es,en,it,etc.) and you will build the path in this way:

[COLOR=Blue]fileToLoad = language+"/main.xml";[/COLOR]

have a nice time

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 1:56pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/10 "2004-08-17T13:56:20Z")

</div>

Hey thanks Penmig !!!  
I was trying to build this reload function but you’re smarter than me ! This still has a problem everything works but i lcik my button to change the language it only change the main movie and not the loaded one while it still reloading it (i implemented the reload function in this one too) any idea ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 2:02pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/11 "2004-08-17T14:02:35Z")

</div>

Did you get my last msg ?

Otherwise send me a zip file to [info@miguelpena.com](mailto:info@miguelpena.com) and I will check it for you.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 2:13pm UTC](https://forum.kirupa.com/t/changing-language-with-xml/61147/12 "2004-08-17T14:13:30Z")

</div>

Yep, i saw your last post, i sent you the files. thanks for the good advice regarding folders, it’s the first time i’m using xml and it seems it can be very helpful, !  
Thanks !🙂
