Translating multiple messages in the same object

More
9 years 2 months ago #1016 by whipexx
Greetings, I've recently bought I2 to use it to localize a pretty big project that I have and after reading the guide and trying to search about it online I've arrived here.

What I've not been able to do is to translate multiple messages that can be displayed on the same object, I can only manage to get one of them. Am I missing something or is it that I2 is not compatible with messages that are changed via scrip?


For example, I would like that all the messages from this switch are translated when they appear on screen, but only the first one appears:
public void ChangeLanguage(string language){
counter++;
             switch(counter){
			case 1:
				middleText.text = "We have changed the language 1 time.";
			break;
			case 2:
				middleText.text = "The language is now changed for second time.";
			break;
			case 3:
			middleText.text = "For the third time, we changed language.";
			break;
			default:
			middleText.text = "We have changed changed the language many times.";
			break;
            }
}



Cheers

Please Log in or Create an account to join the conversation.

More
9 years 2 months ago #1017 by Frank
Hi,
When a label has a Localize component, its text property is controlled by the Localize component.
Instead of assigning the text directly, you should change the Term in the Localize component and that will automatically change the text into the correct translation.

You should add first a term to the I2Languages.prefab for every message you want to display: e.g. "We have changed the language 1 time.", "The language is now changed for second time.", etc.

and then in your script:
middleText.GetComponent<I2.Loc.Localize>().SetTerm("We have changed the language 1 time.", null); 

Or even better: Instead of using the name of the text as the term's name, consider enumerating them: "TUTORIAL MSG 1", "TUTORIAL MSG 2", etc.

That way I2 Localization will do the heavy lifting for you, and the code you posted, gets reduced to:
middleText.GetComponent<I2.Loc.Localize>().SetTerm("TUTORIAL MSG "+counter, null); 

Here is another example of using the SetTerm
inter-illusion.com/forum/i2-localization...-a-changing-text#687
inter-illusion.com/forum/i2-localization...a-localised-text#676

Furthermore, if you want to skip using the localize component (not advisable as a localize component will allow you to setup localization callbacks and has more controls), you can get the localization and assign it directly to the text.
middleText.text = I2.Loc.ScriptLocalization.Get("TUTORIAL MSG "+counter); 

Hope that helps,
Frank

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
The following user(s) said Thank You: whipexx

Please Log in or Create an account to join the conversation.

More
9 years 2 months ago - 9 years 2 months ago #1019 by whipexx
Thanks, I think that this will make my task much easier.

There is still something that seems to not be working as intended... And it might be a small bug.

Now my ChangeLanguage looks like this:
	public void ChangeLanguage(string language){

		counter++;
		if(counter > 4){
			counter = 4;
		}

		middleText.text = I2.Loc.ScriptLocalization.Get("mesage"+counter); 
	}

What is happening is that the first time that I change languages mesage1 is displayed regardless of counter, you need to click again on it for it to display the correct message. This might be because the buttons that change language with the SetLanguage.ApplyLanguage also call this code at the same time.

I can definitely find a workaround to this issue but I thought it might be a good idea to tell you.


EDIT
I've been testing a few things (not calling both things from the same button) and the issue definitely is that when you change language the messages that are shown on screen go to the default ones.


Cheers
Last edit: 9 years 2 months ago by whipexx.

Please Log in or Create an account to join the conversation.

More
9 years 2 months ago #1022 by Frank

What is happening is that the first time that I change languages mesage1 is displayed regardless of counter


I'm not understanding correctly the issue.

As I see it, the first time you call that function, it should show message1. Because initially counter is 0, and you are incrementing it before using it.

Also, notice that if you are changing the text variable directly, then that label shouldn't have a Localize component, otherwise the text variable will be overriden.

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out

Please Log in or Create an account to join the conversation.

Time to create page: 0.197 seconds
Template by JoomlaShine