You are not logged in.

1

Tuesday, May 16th 2023, 11:06am

translate a showtext with a dynamic variable

Is it possible to translate the showtext field with a dynamic variable?
xml =
onhover="showtext([h3]%$TEXT_BE_TRANSLATED%[/h3]);"
and then adding it through the initvars? Or do I need to inject it with javascript?
Has anyone done this before?

Tuur

Sage

Posts: 3,831

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

2

Tuesday, May 16th 2023, 11:32am

Hi Tuur,

Can you be more specific?
There are different ways of doing such. Use the search of the forum and you'll find some.

where is the language selection happening? In krpano world or web page..

Tuur *thumbsup*

3

Tuesday, May 16th 2023, 11:57am

I am building an application that is available in 2 languages, the pano contains several scenes and within each scene there are a lot of hotspots...
When the visitors hovers over a hotspot I want to show a label in the current language, all the labels are defined in the database... so passing it with an invitvars seems to more logical option to me... the language selection is happening in the webpage.

Tuur

Sage

Posts: 3,831

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

4

Tuesday, May 16th 2023, 12:16pm

isn't it better to 'php' the xml and input directly from the database? .. like:

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$rows[] = $row;

}

foreach($rows as $row){
$id2 = $row['name'];

}


echo "<hotspot .. blabla.. onhover=\"".$id2."\"

.. but then with showtext syntax obviously.

or perhaps you want/need to set the language by initvar yes.. _lang and from there pickup the right var from database like above perhaps.
Not directly my expertise though.. but I had it working nicely a few years ago in a project.

perhaps if(_lang == ENG, hotspot[bla].onhover = show text( \"".$id2."\" but then with right syntax obviously.


Hope it helps and makes sense..
Tuur *thumbsup*

This post has been edited 1 times, last edit by "Tuur" (May 16th 2023, 12:33pm)


kme

Intermediate

Posts: 309

Location: Belgium

Occupation: Long time coder, product manager and 3D enthousiast

  • Send private message

5

Tuesday, May 16th 2023, 12:32pm

I recently translated ArtPlacer.

I wanted a database free approach as the tool should be used without a database.

The way I approached the problem was to have an XML with all the translations:

Source code

1
2
3
4
5
6
<krpano>
	<translation name="Toggle Artplacer Editor" text="Abrir/Cerrar Editor de Artplacer" />
	<translation name="width:" text="Ancho:" />
	<translation name="height:" text="Altura:" />
...
</krpano>


And in the XML I used "get:" to fetch the translation like this:

Source code

1
<layer type="text" textalign="center" name="btnToggleArtplacerEditor" style="artplacer_editor_button_black"  text="get:translation[Toggle Artplacer Editor].text"      />


not sure if it helps you, but maybe you get inspiration from it :)

K.

Tuur

Sage

Posts: 3,831

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

6

Tuesday, May 16th 2023, 12:47pm

I use multi languages quite often but not by database and mostly just within krpano.
it is fairly simple then and there are different ways to go.

You could easily call the data container, or var, blabla_nl or blabla_eng and construct the show text.. like

showtext(calc('blabla_' + _lang), MYSTYLE);
or something like that..
many many options
The _lang could come from initvars and the text from the database like above...

Tuur *thumbsup*

7

Tuesday, May 16th 2023, 2:05pm

You can have a look at my project.

There are thousands of texts in two languages. I am using a multi-XML solution as well as language variables.

This post has been edited 1 times, last edit by "s-maier" (May 19th 2023, 6:39pm)


8

Tuesday, May 16th 2023, 3:41pm

Okay I've solved the problem with Tuur his hint :)
I am building my $initvar array in PHP dynamically

Source code

1
2
3
4
5
$initvar = [
    'label_to_translate_1' => 'Eerste label in het Nederlands',
    'label_to_translate_2' => 'Tweede label in het Nederlands',
    'label_to_translate_3' => 'Derde label in het Nederlands',
];

the passing it with a json_encoded array to the pano
and in the pano

Source code

1
onhover="showtext(calc($label_to_translate_1));"

that's it, that's all!

Tuur

Sage

Posts: 3,831

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

9

Tuesday, May 16th 2023, 11:58pm

Looks a bit strange to me to it that way, but if that works for your setup.. i'm glad i could help.

Tuur *thumbsup*

Similar threads