Displaying different graphics depending on selected translation

Started by Cone Arex, Mon 06/12/2021 17:09:15

Previous topic - Next topic

Cone Arex

Hello.
I have a problem regarding the use of translations. Up to now, I have used

Code: ags

if (Game.TranslationFilename == "English")
{
        // Do stuff
}


to check for translation and display different graphics for different translations. But this doesn't seem to work all the time. There were people who saw the untranslated graphic of note despite having an active translation. While testing, I've noticed that the above checking never works when playing the game with the Linux, Android or ScummVM ports of AGS.

Someone told me to first use IsTranslationAvailable() and then compare strings to check which translation is used.
Code: ags

if (IsTranslationAvailable())
{
        if (GetTranslation("Bertholds Rückkehr") == "Berthold's Return")
        {
                // Do stuff
        }
}


I can confirm this works all the time or least I've yet to encounter problems with it. Thing is, that it isn't really good coding style.

Any advice? What is the "correct" way to display graphics depending on the selected translation?

Crimson Wizard

Quote from: Cone Arex on Mon 06/12/2021 17:09:15But this doesn't seem to work all the time. There were people who saw the untranslated graphic of note despite having an active translation. While testing, I've noticed that the above checking never works when playing the game with the Linux, Android or ScummVM ports of AGS.

To clarify, are you saying that this works on Windows, but not on other ports? If so then this sounds like a bug with certain ports.

Could you tell which version of AGS are you using? Is "English" translation not default one, and present as a TRA file with your game?

Cone Arex

Quote from: Crimson Wizard on Mon 06/12/2021 17:23:19
To clarify, are you saying that this works on Windows, but not on other ports?
Yes. But I must point out that other people als had the issue that graphics weren't translated. I don't know if they were using windows or not.

Quote from: Crimson Wizard on Mon 06/12/2021 17:23:19
Could you tell which version of AGS are you using? Is "English" translation not default one, and present as a TRA file with your game?
I'm using AGS 3.5.0. Yes, English isn't the default one and present as TRA file.

Crimson Wizard

There have been a bug once where Game.TranslationFilename would always return an empty string, making check in scripts impossible. But I don't remember exactly where it was introduced (it was fixed in 3.5.1 - Patch 1).

If you or another user know the actual case where graphic is not changed for translation, and have a save made around that moment in game, I could perhaps test this under debugger and see what's happening.

Crimson Wizard

[REDACTED], sorry, nevermind.

heltenjon

Quote from: Cone Arex on Mon 06/12/2021 17:32:37
But I must point out that other people als had the issue that graphics weren't translated. I don't know if they were using windows or not.
I used windows when I got the "German graphics".

Cone Arex

QuoteBut I don't remember exactly where it was introduced (it was fixed in 3.5.1 - Patch 1).
I upgraded my game to 3.5.1. Patch 4 but it doesn't change anything.

QuoteI used windows when I got the "German graphics".
Thx for your information. Do you happen to remember if the name in the title screen (not in the title window) was also untranslated? There are only these two graphics that are checked for translation.

QuoteIf you or another user know the actual case where graphic is not changed for translation, and have a save made around that moment in game, I could perhaps test this under debugger and see what's happening.
Doesn't need a save. The titlescreen itself has a translated graphic. I also know that the same problem exist with another game in the titlescreen and the packing list as it used the same method to check for the translation.

Khris

I checked the available download (June 24, 2020) on Windows and translating the title screen worked fine for me.

Crimson Wizard

There's a potential reason that may cause this problem. The way AGS works, the translation name will be set to whatever is passed to ChangeTranslation command in script, or whatever is set to "translation" option in config which it reads on startup. That is, if you pass "English" then the translation name will be "English", but if you pass "english" then it will be "english".

Comparing two strings using "==" operator in script uses case sensitive comparison. Which will fail if translation is initialized as "english" and compared to "English".

To avoid such problems you may try using case insensitive comparisons using String's CompareTo function, which is case-insensitive by default:
Code: ags

if (Game.TranslationFilename.CompareTo("English") == 0)
{
     // change to english gfx
}


This code may of course be simplified by testing translation only once at startup, or when the language is changed in game (if you have such option), and storing result in your own global variable. Then you may check your variable instead.

Cone Arex

I've already had the idea that the problem is case-sensitivity.  :-D
I've now tried your code with CompareTo and in the past tried by just checking all lower case "english" as well as with an initial upper case. Nothing changes. It still works with Windows but nothing else. Interestingly (at least for me): The .tra file is spelled with all lower case, but the check only works with an initial upper case "English". Checking for "english" will not work with the case-sensitive == operator despite the file's name.

heltenjon

Quote from: Cone Arex on Mon 06/12/2021 18:45:24
QuoteI used windows when I got the "German graphics".
Thx for your information. Do you happen to remember if the name in the title screen (not in the title window) was also untranslated? There are only these two graphics that are checked for translation.

From the other thread:
Quote
QuoteThere is also a note on the kitchen door that is still in German.
Quote:(
I did translate the note on the door, but I also had the issue that doesn't load the correct graphic sometimes. Is the title screen graphic also untranslated ("Bertholds Rückkehr" instead of "Berthold's Return")?

Yes. The intro "types" in German at first, and then switches to the English text. Mind you, I didn't touch the setup, so I may have neglected to do something.
I can't remember the details more than that.

EDIT: Downloaded again and retried. The title screen says "Ruckkehr", the typing right after pressing start is in German, but switches to the finished English text when the typing is done, and the note on the door is in German.

Cone Arex

Ah, I now understand what meant with "typed". You mean the introtext that is typed after you pressed Start. (The text is hardcoded because it's created dynamically.) I always thought the meant the title in the window.  :-D Thx again.

Crimson Wizard

#12
Quote from: Cone Arex on Mon 06/12/2021 21:26:00The .tra file is spelled with all lower case, but the check only works with an initial upper case "English". Checking for "english" will not work with the case-sensitive == operator despite the file's name.

AGS complicates this in many places. The filename's case is not important, what's important is how it is written in the config file. Winsetup.exe has an additional quirk: it always capitalizes the first letter of the translation name, probably for backward compatibility reasons (because people in the past used to spell translations with capital letter in scripts). This means that if you are using winsetup, then the language will be set with first capital letter.

You may test this by setting up language in user config file by hand in small letters (on windows user config is located in %USERPROFILE%\Saved Games\<name of game>).
Alternatively it's also possible to test using Game.ChangeTranslation command in script.

Crimson Wizard

Oh, Cone Arex, another thing that I forgot to mention, you may display the value of Game.TranslationFilename on screen, either with Display command or on a label.
If it has unexpected value, then we'd have to find out why. If it has a proper value, then there might be something wrong with the game script.

Cone Arex

Finally, some progress. I displayed the output of both Game.ChangeTranslation("English") (which doesn't change anything regarding graphics) and Game.TranslationFilename.CompareTo("English"). ChangeTranslation correctly returns 1, while TranslationFIlename returns -101 under ScummVM, which is the same value that is returned under windows if no translation is selected/the default language is used.

Crimson Wizard

#15
Quote from: Cone Arex on Tue 07/12/2021 19:12:41while TranslationFIlename returns -101 under ScummVM, which is the same value that is returned under windows if no translation is selected/the default language is used.

Sorry, i am bit confused; TranslationFilename is a string, how do you get "-101"? ...or is this a result of Compare?

What I meant, it could be displayed as:
Code: ags

Display("translation = %s", Game.TranslationFilename);

Cone Arex

Oh, yes I misunderstood. -101 is of course the output of CompareTo.
The output of Game.TranslationFilename is indeed an empty string if played under ScummVM, but "English" when played under windows.

Crimson Wizard

Quote from: Cone Arex on Tue 07/12/2021 19:58:06
The output of Game.TranslationFilename is indeed an empty string if played under ScummVM, but "English" when played under windows.

ScummVM is not precisely 1:1 with ags engine, and it may have its own bugs (also it's likely more in sync with some wip stage of 3.6.0 engine now).

I think it's best to try ags ports first to see how they behave.

Cone Arex

I tried it again with the Linux port and it has the same output. An empty string for TranslationFileName. (I used ScummVM for it ease of use. As itt has all the exact same issues as the Linux and Android ports of AGS.)

Crimson Wizard

#19
Okay, I tested this on linux now with "Bernhold's revenge", and see the issue: the game's subtitle on a intro screen is displayed in german but the character speech etc texts are in english.

Changing "translation" option in config file from "english" to "English" fixes it though... I'd suppose this is the case sensitivity problem that I mentioned above, but since you said that Game.TranslationFilename becomes empty, not sure what is going on at this point.

Could you also tell, what version of a linux port are you using and where did you get it, to make sure we're testing same thing?

SMF spam blocked by CleanTalk