Community Forum

Translation system not working on Gui

Forum Overview >> Scripting

Created14.09.2021 08:06

Achim Kuntz (Achimobil) 14.09.2021 08:06

to publish my mod I was asked to transate everything, so I add the translation files "l10n_de.xml" and "l10n_en.xml" and fill it.
Here one Entry:
<text name="FactoryHeader" text="Produktion" />

In the XML for the Gui I changed the element to translate to this:
<GuiElement type="text" profile="pihFactoryListHeaderFactory" text="$l10n_FactoryHeader" id="pihFactoryListHeaderFactory" />

Running this tells me, that "FactoryHeader" is missing in the "l10n_de.xml".
I searched long time, but could not find why.

then I tried to change the line to:
<GuiElement type="text" onCreate="onCreateTranslateElementText" profile="pihFactoryListHeaderFactory" text="FactoryHeader" id="pihFactoryListHeaderFactory" />

In the onCreateTranslateElementText method I make:
element.text = g_i18n:getText(element.text);
And this works.

So the translation is loaded, but the xml definition could not load it.
What did I wrong. Why is the translation not found directly but when I access it in the skritp it works?
Do I miss a line of code to make the translations possible directly in the XML UI definition?

What I tried is to put the translation files in a subfolder, put it next to the xml files, With and without the filemaneprefix line in the modDesc.xml.
Nothing works. I could not imagine that the "$10n_" is only for Giants internal things possible.

Another thing is with this line I have in the UI XML:
<GuiElement type="button" profile="buttonOK" text="$l10n_button_ok" onClick="onClickOk" />
This workd fine, but this translation is from Giants itself. I think a global translation, but my mod sould also use the mod translations.

Bilbo Beutlin (BBeutlin) 14.09.2021 22:44
The location texts require always the "$l10n_" prefix.
If you have external texts the modDesc.xml needs the tag <l10n filenamePrefix=".."/>

Anyway, there are still some regions where the $l10n translations don't work.

Achim Kuntz (Achimobil) 15.09.2021 14:21
Please take into account that this is a script mod, not a vehicle mod. And the tags are written as you mentioined.
text="$l10n_FactoryHeader" do not work in the UI XML.
But in the script the following works:
element.text = g_i18n:getText("FactoryHeader");
So the UI do not find the mod translations, the script does.

Do I miss something to load the mod translations so that they are used?

Note: Log in to post. Create a new account here.