Translation not working

Started by ManicMatt, Thu 30/01/2020 18:24:15

Previous topic - Next topic

ManicMatt

Help!

I am having my last game translated, so I am trying to test the code where a language GUI in the game would let you choose it. Before I make the GUI, I thought I'd check I can get it working first, so just threw it in a specific interaction within the game. I have created a translation trs file called French, and filled in a space with words for the specific line the character says when interacting with a magazine, using notepad (Would that mess it up?). With the below code however, the character speaks the standard English line.

Code: ags


function hKerrang_Interact()
{
cEgo.FaceDirection(eDirectionUpLeft, eBlock);
Game.ChangeTranslation("French");
cEgo.Think("&430 I like Sonic Boom Six, but I don't have time to read this.");
}



This isn't the code in the manual, as it has a "static bool" I think it said at the top of the entry, which doesn't work as it says it needs to be outside a function, which is no good when it should be activated in a function!

To add to the confusion, the example given in the manual for using the code is as follows:

Code: ags
if (Game.ChangeTranslation("Spanish") == true)
{
  Display("Changed the translation to Spanish!");
}
else
{
  Display("Unable to change the translation");
}

will attempt to change the translation to Spanish


Now I'm no expert, but that code reads to me that it is just checking if the language is in Spanish, with nothing in that example being code to change the translation at all!? The only actions it will do is display some text! I've tried the code anyway, and sure enough it just says the second line "Unable to..", even in addition to the top code I gave.

What am I missing here? Thanks!

Cassiebsg

#1
Think you should take this in two steps:

1 - Making sure the translation file actually works. To do this, just run winsetup and change the language to french, then save and run the game. If the line is not translated then something might be wrong either with the trs file (make sure you save it as UTF-8)  or the think function might need some extra instructions. I never actually used it so I'm not sure it works out of the box.
If you're unsure about your trs file, try Tzachs new TRS Editor: https://tzachshabtay.github.io/ags-trs-editor/ (just use the load icon to upload/open your trs file, translate a couple lines, then save/download it and test it.

2 - Once you're sure the trs is being loaded correctly, then code changing the translation. Basically the "Spanish" is tra name of your trs/tra file, minus the extension.

Edit:
To change the game language in game create a GUI with a button (or add the button to an existing GUI) and in the function for that button, use:

Code: ags

if (Game.ChangeTranslation("French") == true)
{
  Display("Changed the translation to French!");
}
else
{
  Display("Unable to change the translation");
}


I'll agree that changing the translation using an if condition is kind of weird and intuitive.  (wtf)

About your Interact function, the code ChangeTranslation won't work because, in order to change the translation what you need to do is the above. And once you've already changed the translation via a button, the game will use the translation lines. Remember that they have to be exactly identical, otherwise AGS won't find it. I can see you have voice acting, if for example you made the trs before adding the voice code &430 then AGS won't find the line to translate... even if you deleted a single space it won't work.
There are those who believe that life here began out there...

Crimson Wizard

#2
Quote from: ManicMatt on Thu 30/01/2020 18:24:15
To add to the confusion, the example given in the manual for using the code is as follows:

Code: ags
if (Game.ChangeTranslation("Spanish") == true)
{
  Display("Changed the translation to Spanish!");
}
else
{
  Display("Unable to change the translation");
}

will attempt to change the translation to Spanish


Now I'm no expert, but that code reads to me that it is just checking if the language is in Spanish, with nothing in that example being code to change the translation at all!?

The Game.ChangeTranslation call is trying to change game translation to Spanish.
The condition is checking return value of ChangeTranslation, which means whether changing to Spanish was successful or not.

To know whether the current language is Spanish, use "Game.TranslationFilename" and compare it to your translation name.

ManicMatt

#3
Thanks Cassiebsg!

I think in the end, it wasn't working because I was loading up an older save file within the game. I didn't think that would matter.

Then it was in French without pressing the GUI button! In the default setup it said default language but I realised it was set to French in the compiled Winsetup so I guess that was messing with it.

So everytime you boot the game, it will saved as the last language huh. Well the very first screen will be language selection every time so I guess that will be okay right?

P.S - Oh yeah, this is a game I finished last year, so the voices were already implemented.

Crimson - I didn't think an if statement line could make any changes. Just when I think I understand a piece of code!

eri0o

It isn't the if, it's the function inside of it. The if is just to read if the function had succeeded.

My reading on this implementation is most functions when something fails, they crash the engine, because most causes of failure are related to error on scripting, I think this one doesn't crash the engine because it depends on stuff not packed with the game that may not exist.

Khris

Quote from: ManicMatt on Thu 30/01/2020 20:47:06I didn't think an if statement line could make any changes. Just when I think I understand a piece of code!

Let me address that, because not understanding how this works is a very common issue. People assume that the computer will look at the entire if statement as a whole here, but that's not at all what happens. The computer resolves the line piece by piece, according to operator precedence.
People actually do the exact same thing, for instance when solving something like  x = (4 + 5) * 6

Code: ags
  if (SomeFunctionCall() == true) ...


When AGS (or any other programming language) finds a line like this, the  if  is ignored for the moment because the condition is an expression. So the first thing the computer does is evaluate the expression:

Code: ags
  SomeFunctionCall() == true


This expression is a basic comparison, however there's a function call on the left. So again, the actual comparison is ignored for the moment and the computer focuses on the left side: it calls the function, executing whatever code is inside. Let's assume the function returns  true. The expression becomes:

Code: ags
  true == true


Now that all we have left is a single, well-defined value on each side, the computer evaluates the expression further, which results in  true. Now it goes back to the  if, which has now become

Code: ags
  if (true) ...


and the computer can finally process the  if.

This also nicely shows that adding  == true is completely redundant.

Code: ags
  if (Game.ChangeTranslation("Spanish")) ...


is all you need.

ManicMatt

Hmm, does that work with things like if i did the code to change a character's view within an if statement, would it change the view and then also check if true/false and act accordingly to the if and else? Or is it only certain "expressions"?

Thanks for the indepth explanation!

Khris

The key is that the function call part of the expression is something that returns a value. Consider this:

Code: ags
  if (Maths.Sqrt(9.0) == 3.0) ... 


You probably wouldn't think twice about what exactly is happening here, but it really is the exact same thing.  Maths.Sqrt(9.0)  causes a function to run. The function contains a square root algorithm and returns a value, 3.0. Which is then compared to 3.0, resulting in  true.

So no, you can't use any function.

Character.ChangeView()  doesn't return a value, and  Character.SpeechView  is a property, not a function call.

Granted, the example of  Game.ChangeTranslation()  is kind of confusing, because the function a) causes something to happen but also b) returns a value. Most functions do one or the other, not both.

ManicMatt

Ah right, I think I kinda got that, lol. I use if statements a ton but it's basic stuff like variables and uh, declared string values, or something.

Cassiebsg

I'd like to thank for the explanation as well.  :)
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk