Sie sind nicht angemeldet.

1

Sonntag, 26. April 2020, 22:49

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.

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!-- v_lang is defined as onstart="set(v_lang,de); " -->


	<combobox name="sprache" design="default" align="righttop" >
		<item name="en" caption="EN" onclick="set(v_lang,en);" />
		<item name="de" caption="DE" onclick="set(v_lang,de);" />
	</combobox>


 			<hotspot name="hs_box5" ath="88" atv="15" style="infospotstyle" onclick="a_popupinfo(box5start);"  />

			<layer name="box5start" type="image" tag="" url="stills/de/aufmacher_box5.jpg" children="true" align="center" style="infobasisstyle" >
				
<layer name="close" type="image" url="skin/close.png" distorted="false" align="righttop" y="20" x="20" parent="box5start" onclick="a_popoutinfo(box5start);"/>
				<layer name="box5" type="image" tag="" url="box5-hs.jpg'" style="infoimagestyle" parent="box5start" x="34" onclick="a_popupdetails(box5detail);"/>
				<layer name="box5plus" type="image" tag="" url="box5plus-hs.jpg" style="infoimagestyle" parent="box5start" x="317" onclick="a_popupdetails(box5plusdetail);"/>
				<layer name="box5luft" type="image" tag="" url="box5luft-hs.jpg" style="infoimagestyle" parent="box5start" x="535" onclick="a_popupdetails(box5luftdetail);"/>
			</layer>

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:

Quellcode

1
2
3
4
5
6
7
8
9
	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

Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von »mstoss« (4. Mai 2020, 18:59) aus folgendem Grund: Weitere Option hinzugefügt


2

Sonntag, 26. April 2020, 23:35

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

Quellcode

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

and then you can do something like...

Quellcode

1
2
3
4
5
6
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);	
	);					
);	

Dieser Beitrag wurde bereits 6 mal editiert, zuletzt von »indexofrefraction« (27. April 2020, 11:39)


3

Montag, 27. April 2020, 05:25

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*



4

Montag, 27. April 2020, 08:52

@panoyun : yup, corrected above... *whistling*

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »indexofrefraction« (27. April 2020, 11:39)


5

Montag, 27. April 2020, 11:03

hehe... was just about to write, that I could not make this work. Thank you so much for taking the time anyway.

I will try the corrected version now, give me a minute to check this out.


Yours,
Michael

6

Montag, 27. April 2020, 11:14

It works! Nice one, @indexofrefraction and @panoyun!


A deep felt Thank you for working this out - I guess this will help many people :-D
Yours,
Michael

7

Montag, 27. April 2020, 11:45

denada...

additionally you could do something like that :

Quellcode

1
2
3
4
5
<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

8

Mittwoch, 29. April 2020, 19:02

That's a nice feature indeed. Thank you again!

9

Montag, 4. Mai 2020, 19:15

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:

Quellcode

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


The dynamic link:

Quellcode

1
2
3
4
5
6
7
<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:

Quellcode

1
2
3
4
5
6
7
8
9
		<data name="url_infopoint-box5startlink-de">https://www... linkdeutsch1.html</data>
    	<data name="url_infopoint-box5startlink-en">https://www... linkenglish1.html</data> 

		<data name="url_infopoint-box5pluslink-de">https://www... linkdeutsch2.html</data> 	
		<data name="url_infopoint-box5pluslink-en">https://www... linkenglish2.html</data> 

		<data name="url_infopoint-box5luftlink-de">https://www... linkdeutsch3.html</data>
		<data name="url_infopoint-box5luftlink-en">https://www... linkenglish3.html</data>  
(...)