SOLVED: Language switch via language folders or data:

  • Sorry guys, for bothering you with the ever basic problems. My scripting knowledge has not really improved over the years.

    So, here's my problem.

    I have got a language switch (via the xml combo box) to set a variable to "en" or "de" for english/german language.
    I did place jpgs in their respective languages into two folders "en" and "de".

    The idea is, to show the right image to the user depending on the chosen language. Sounds simple. Maybe it is, maybe it isn't, as some would say - I'm no expert.


    The first layer has a hard coded url to show you, what I want to achieve. I tried with the very basic image name and add the path according to this post , but that did not work, I went crazy in my IFs like this:

    Code
    if	(v_lang == 'en', 
    					trace('Sprache ist englisch'),	
    					if	(		layer.tag == 'img', <!-- I tried to attach tags to my layers as in the example, took them away again -->
    								for	(set(i,0), i LT layer.count, inc(i),						
    									calc(v_path, 'stills/en/' + layer[get(i)].url);				
    									set(layer[get(i)].url, get(v_path));
    									trace(layer[get(i)].url);						
    									);	
    ...


    I tried to use the calc action directly then, but that did not work either - probably because I don't know how to use it correctly. Something in the line with url="calc:'%CURRENTXML%/stills/' + get(v_lang) + '/box5-hs.jpg'"

    Is there any smart way to achieve this? It's only one tiny part of the url that has to be changed according to a simple variable. That has to be easy... somehow... or not?

    I really, really... really appreciate some help with this.

    Michael

    Edited 3 times, last by mstoss: Weitere Option hinzugefügt (May 4, 2020 at 6:59 PM).

  • best dont set url before localizing. that triggers a load.
    you could use something else like url_localize, this at the same time marks which layers to localize

    so you have for example

    Code
    <layer ... url_localize="%CURRENTXML%/stills/__LANG__/box5-hs.jpg" ... />


    and then you can do something like...

    Code
    for(set(i,0), i LT layer.count, inc(i),	
    	if(layer[get(i)].url_localize,
    		txtreplace(layer[get(i)].url, layer[get(i)].url_localize, '__LANG__', get(v_lang));
    		trace(layer[get(i)].url);	
    	);					
    );
  • txtreplace(layer[get(i)].url, get(layer[get(i)].url_localize), '__LANG__', get(v_lang));

    trace(layer[get(i)].url); =layer[get(i)].url
    ?????????
    txtreplace(layer[get(i)].url, layer[get(i)].url_localize, '__LANG__', get(v_lang));

    *smile* *smile* *smile*

  • denada...

    additionally you could do something like that :

    Code
    <action name="localize" autorun="preinit">
      set(v_lang,de); // set the default language
       if(lang !== null, copy(v_lang, lang)); // override if url argument given
       // ... now do the localizing ...
    </action>


    now you have a default language and you can override it with the url
    ie. https://domain/path/?lang=en

    index

  • Hi,
    I thought it would be of interest to some, that I used a different aproach for some html-links, which I had to include as well.

    The language folders work nice, but I needed to point the user to some links to web pages in english and german as well. So I used a data: set for the links and included them as follows:

    (v_lang is being set to "en" or "de" via the switch, e.g. via a dropdown menu)

    The action:

    Code
    <action name="a_openlocalizedurl">
    					openurl('get(data[url_infopoint-%1-%2].content)',_blank);
    	</action>

    The dynamic link:

    Code
    <layer name="box5startlink" type="image" style="linkspotstyle" url="skin/linkspot.png" visible="true" parent="box5start" x="10" y="20" onclick="a_openlocalizedurl(box5startlink,get(v_lang));"	/>	
    
    
    <layer name="box5pluslink" type="image" style="linkspotstyle" 
    url="skin/linkspot.png" visible="true" parent="box5start" x="10" y="70" 
    onclick="a_openlocalizedurl(box5pluslink,get(v_lang));"	/>	
    
    
    (...)

    The data:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!