Have a question about simple callbacks

More
3 years 2 months ago - 3 years 2 months ago #1704 by Sarr
Hello, thanks for your help with lists. Now I'd like to ask about a simple thing probably, to get that logic.
I have a following setup.

There's a text object: Text Text_char_race_string. In Unity, it's default content is: _char_race_string
Then, later in game, it's filled with race that is chosen by player.
public void RaceToCharacterSheet() {
	Text_ch_sh_char_race_string = GameObject.Find ("Text_ch_sh_char_race_string").GetComponent<Text> ();
	Text_ch_sh_char_race_string.text = characterRace;
}
For example, it may be filled with _dwarf, which is a term in my google spreadsheets.
It's set like this:
public void SetRaceFromArray () {
	if (raceGenerator.raceArray [0] == true) {
		// Assign character Race
		characterRace = "_dwarf";
		OnModifyLocalization ();
                RaceToCharacterSheet();
}
Now, I've just translated it to "Dwarf" using I2 this way:
public void OnModifyLocalization()
	{
		// if no MainTranslation then skip (most likely this localize component only changes the font)
		if (string.IsNullOrEmpty(Localize.MainTranslation))
			return;

		// get translation 
		characterRace = I2.Loc.ScriptLocalization.Get(characterRace.ToString());
	}
But of course it doesn't update on changing language. I've even tried to make that last code a single script attached to the object Text_char_race_string and setting function in Localize component to OnModifyLocalization, but still - everything in UI switches language, but not this.

How to do that properly? Do I need to set _char_race_string as a parameter somehow? But it will be swapped with _dwarf or _human etc, so not sure.
Last edit: 3 years 2 months ago by Sarr.

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

More
3 years 2 months ago #1705 by Frank
You can do that easily by setting the term instead of the text

1- Add a localize component to the Text_ch_sh_char_race_string object
2- Instead of doing Text_ch_sh_char_race_string.text = characterRace;
do Text_ch_sh_char_race_string.GetComponent<I2.Loc.Localize>().SetTerm( characterRace );

That will change the term, and will make the Localize component automatically change the text with the translation of that term.
Given that the term is changed, then every time you change languages, the text will be updated again with the new translation.

As a general rule, every localized Text should have a Localize. And every object with a localize component shouldn't be changing the text directly. Instead it should change the term.


Also, If you want to use callbacks, you shouldn't be calling the callback function directly. You should place a localize component in the Text object and in the Localize component inspector, there is a section where you can register which function to use as a callback.
(see the first image in: inter-illusion.com/assets/I2LocalizationManual/Callbacks.html )

The Localize component will call the callback automatically.

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: Sarr

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

More
3 years 2 months ago #1706 by Sarr
Hmm, that's great. Didn't know this is so automated, this is more than easy then. That explains a lot, thanks!
Seems another 5 stars for I2 Localization coming.

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

Time to create page: 0.166 seconds
Template by JoomlaShine