Changing language with xml

I followed this threadhttp://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 :blush:
Files are here :www.artefakt.be/xml.zip
Thanks !

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

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 :frowning: )

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[/COLOR]

Have a nice day

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

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

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 :}

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

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. :stuck_out_tongue:

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

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 ?

Did you get my last msg ?

Otherwise send me a zip file to [email protected] and I will check it for you.

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 !:slight_smile: