Skip to main content
ZZWWBUG
Participant
Nov 6, 2021 11:16 AM UTC
Answered

Multi language banner load variables from text question (AS3)

Hey,

I have a banner example and want to make it multilingual.

I would prefer to load words from 1 external text file (language_txt.txt) for each translation.

I have dynamic text fields with instance names. (Header_001, Slogan_001, Button_001)

With what code do I load the variables from (language_txt.txt) ?
And in which frame do I put that code in the *.fla? (970x250-multi-language-banner.fla)

What code do I put in the *.text (language_txt.txt) files to link the translated words to the dynamic text fields.

 

Goal: An explanation and tuturiol for many creative people who can't program very well 😉

 

----------------------------------------------------------------
this.Header_001 = new cjs.Text("Sun is shining the weather is sweet", "normal 700 44px 'Roboto'", "#FFFFFF");
this.Slogan_001 = new cjs.Text("Make you want to move your dancing feet", "normal 700 28px 'Roboto'");
this.Button_001 = new cjs.Text("CLICK HERE", "normal 700 28px 'Roboto'", "#FFFFFF");
----------------------------------------------------------------

Files: Attachments - Github
970x250-multi-language-banner.fla
970x250-multi-language-banner.html
970x250-multi-language-banner.js
Multi-language-banner-load-variables-from-text-question-as3-adobe-animate
- language_txt.txt

More @ https://github.com/ZZWWBUG/oldskool
More @ https://github.com/ZZWWBUG/oldskool/find/main

----------------------------------------------------------------

Language 1 - (language_txt.txt)
Header_001 = Sun is shining the weather is sweet
Slogan_001 = Make you want to move your dancing feet
Button_001 = CLICK HERE

Language 1 - (language_txt.txt)
Header_001 = El sol está brillando, el clima es dulce
Slogan_001 = Te dan ganas de mover tus pies bailando
Button_001 = HAGA CLIC AQUÍ

Language 1 - (language_txt.txt)
Header_001 = Die Sonne scheint, das Wetter ist schön
Slogan_001 = Machen Sie Lust, Ihre tanzenden Füße zu bewegen
Button_001 = KLICKE HIER

----------------------------------------------------------------

    This topic is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    Nov 7, 2021 3:20 PM UTC

    Hi.

     

    Here is a sample using a JSON file.

     

    JavaScript code:

    var root = this;
    var xhttp = new XMLHttpRequest();
    var languages = [ "enUS", "ptBR" ];
    var language = 1;
    var json;
    
    function main()
    {
    	xhttp.onreadystatechange = function()
    	{
    		if (this.readyState == 4 && this.status == 200)
    			loadComplete(xhttp.responseText);
    	};
    
    	xhttp.open("GET", "languages.json", true);
    	xhttp.send();
    }
    
    function loadComplete(data)
    {
    	json = JSON.parse(data);
    	root.win.Header_001.text = json[languages[language]].Header_001;
    	root.win.Slogan_001.text = json[languages[language]].Slogan_001;
    	root.win.clickHereButton.button.Button_001.text = json[languages[language]].Button_001;
    }
    
    main();

     

    FLA / code / source download:

    https://bit.ly/3CYxndS

     

    I hope this helps.

     

    Regards,

    JC

    6 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    Nov 7, 2021 3:20 PM UTC

    Hi.

     

    Here is a sample using a JSON file.

     

    JavaScript code:

    var root = this;
    var xhttp = new XMLHttpRequest();
    var languages = [ "enUS", "ptBR" ];
    var language = 1;
    var json;
    
    function main()
    {
    	xhttp.onreadystatechange = function()
    	{
    		if (this.readyState == 4 && this.status == 200)
    			loadComplete(xhttp.responseText);
    	};
    
    	xhttp.open("GET", "languages.json", true);
    	xhttp.send();
    }
    
    function loadComplete(data)
    {
    	json = JSON.parse(data);
    	root.win.Header_001.text = json[languages[language]].Header_001;
    	root.win.Slogan_001.text = json[languages[language]].Slogan_001;
    	root.win.clickHereButton.button.Button_001.text = json[languages[language]].Button_001;
    }
    
    main();

     

    FLA / code / source download:

    https://bit.ly/3CYxndS

     

    I hope this helps.

     

    Regards,

    JC

    Translate
    ZZWWBUG
    ZZWWBUGAuthor
    Participant
    Nov 7, 2021 3:57 PM UTC

    Thank you mister JoãoCésar 🙂

    It works realy nice... I also added a Dutch translation and that works fine.

     

    If I run into a problem in the further development of this option, I'll post another question here.

    Now I'm going to see how this works in an HTML5 banner/presentation with lots of layers and texts.

    Greetings From Holland!

     

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Nov 7, 2021 8:09 PM UTC

    Awesome! You're welcome!

     

    Just let us know if you need further assistance and I wish success in your journey.

     

    Greetings from Brazil!

     

    Regards,

    JC

    Translate