Hello! I need some help on changing translation in game.
First I must say that the game uses the Tumbleweed template.
I have the default game in Spanish and I have added a test English translation. When I change the translation from winsetup everything goes well. The texts and the GUI change languages and the changes are maintained in the following sessions.
The problem is when I change the translation from within the game through:
Game.ChangeTranslation("English");
What happens is that the language of the texts is changed but not that of the GUI and in the 9 verbs. In addition, the changes are not maintained in the following sessions either.
Let's see if you can give me a hand. Thank you so much!
[EDIT]
I have added this:
System.SaveConfigToFile();
And now the language changes are maintained in the following sessions. But I still have the problem that the language of the 9 GUI verbs is not changed. Instead, it does when I log out of the game and back in.
I think you can change the GUI verbs translation by using Verbs.VerbGuiOptions[eVerbGuiTemplateLanguage] and Verbs.InitGuiLanguage(), see more info below:
https://adventuregamestudio.github.io/ags-manual/Tumbleweed.html#language--translation
https://adventuregamestudio.github.io/ags-manual/Tumbleweed_helper.html#verbsinitguilanguage
Thank you very much for your answer. Yes, indeed these days I have been able to test it and it has been solved. To change the language from within the game I use:
Game.ChangeTranslation("English");
Verbs.VerbGuiOptions[eVerbGuiTemplateLanguage] = eLangEN;
Verbs.AdjustGUIText();
System.SaveConfigToFile();
That way it changes the language of the GUI and texts perfectly.
But there is still a small detail that I would like to fix. If you load a save game in a language other than the current one, then the GUI doesn't switch languages either. It would be solved by adding this code:
if (Game.TranslationFilename == "English") {
Verbs.VerbGuiOptions[eVerbGuiTemplateLanguage] = eLangEN;
Verbs.AdjustGUIText();
}
but I don't know where to put it. It should be at the time of loading... Can you give me a hand?
Thank you!
In on_event() (https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_event), checking for eEventRestoreGame:
function on_event(EventType event, int data)
{
if(event == eEventRestoreGame)
{
// Code goes here
}
}
It seems that it doesn't work. Still does not change the GUI language when loading a save in another language. However, the rest of the text does change it.
Now I have this in the global script:
function on_event(EventType event, int data) {
if (event==eEventLeaveRoom)
if (event==eEventRestoreGame) {
Verbs.Localize();
//new code
if (Game.TranslationFilename == "English") {
Verbs.VerbGuiOptions[eVerbGuiTemplateLanguage] = eLangEN;
Verbs.AdjustGUIText();
}
else if (Game.TranslationFilename == "") {
Verbs.VerbGuiOptions[eVerbGuiTemplateLanguage] = eLangES;
Verbs.AdjustGUIText();
}
//
}
if (event==eEventEnterRoomBeforeFadein || event==eEventRestoreGame)
player.PlaceOnWalkableArea();
}
[EDIT]
I think when it loads the game it doesn't read this code. I have added a player.Say() inside the eEventRestoreGame and it does not execute it when loading the game.
[SOLVED]
That's it. Now it works. The code is the following:
function on_event(EventType event, int data) {
if (event==eEventLeaveRoom)
if (event==eEventRestoreGame) {
//this part here is not executed...
Verbs.Localize();
}
if (event==eEventEnterRoomBeforeFadein || event==eEventRestoreGame)
player.PlaceOnWalkableArea();
if (Game.TranslationFilename == "English") {
Verbs.VerbGuiOptions[eVerbGuiTemplateLanguage] = eLangEN;
Verbs.AdjustGUIText();
}
else if (Game.TranslationFilename == "") {
Verbs.VerbGuiOptions[eVerbGuiTemplateLanguage] = eLangES;
Verbs.AdjustGUIText();
}
}
You have a syntax mistake in your code here:
if (event==eEventLeaveRoom)
if (event==eEventRestoreGame) {
This reads like the the second "if" is a continuation of a first one, and becomes a sub-condition under the first condition. It will only get checked if the first one succeeds (but this means that the second check will never succeed, because event cannot be both at the same time).
Either remove the eEventLeaveRoom completely, if you are not using it, or close the first conditional "block" by placing a `;` sign or `{}` after it:
if (event==eEventLeaveRoom) { /* do nothing */ }
if (event==eEventRestoreGame) {
Ok, thanks for the correction! :-[
Well, the error is in the default code of the Tumbleweed template!
Quote from: Carles on Tue 21/02/2023 21:42:55Well, the error is in the default code of the Tumbleweed template!
Hmm, really!
https://github.com/dkrey/ags_tumbleweed/blob/411d3e14ef1cd91e434db5f03cbd83e70d3776c5/GlobalScript.asc#L47
I shall report to the author. This looks like a unnecessary line.
Partly for reasons like this, I think it's better and clearer to use a switch/case statement when you're doing multi-branching on the value of a variable:
switch(event)
{
case eEventLeaveRoom:
break;
case eEventRestoreGame:
// code
break;
case eEventEnterRoomBeforeFadein:
// ...
break;
// ...
}