Sie sind nicht angemeldet.

1

Dienstag, 16. Mai 2023, 11:06

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

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

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

  • Nachricht senden

2

Dienstag, 16. Mai 2023, 11:32

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

Dienstag, 16. Mai 2023, 11:57

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

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

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

  • Nachricht senden

4

Dienstag, 16. Mai 2023, 12:16

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*

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Tuur« (16. Mai 2023, 12:33)


kme

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

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

  • Nachricht senden

5

Dienstag, 16. Mai 2023, 12:32

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:

Quellcode

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:

Quellcode

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

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

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

  • Nachricht senden

6

Dienstag, 16. Mai 2023, 12:47

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

Dienstag, 16. Mai 2023, 14:05

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.

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »s-maier« (19. Mai 2023, 18:39)


8

Dienstag, 16. Mai 2023, 15:41

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

Quellcode

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

Quellcode

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

that's it, that's all!

Tuur

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

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

  • Nachricht senden

9

Dienstag, 16. Mai 2023, 23:58

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*

Ähnliche Themen