How to set a new term on a localised Text?

More
8 years 9 months ago #675 by protostarDean
Hi there,

Great plugin! Has been good so far except for this one issue. Forgive me if I have missed something obvious.

I have a ugui text that I want to be localised, but it's term needs to be set dynamically in code.

The last system I worked with, when you did for example:
myText.text = "ITEM_0";

it would look up "ITEM_0", translate it, and set the text to the localised string.

With i2, the Localize component is expecting a certain term, and just localizes to that term regardless of what I set the text to. I cant seem to add a component with an unspecified term.

What would be the equiavalent of the above example? is there something I have missed, or do I just have to have the text non localised and manually look up the translation in code?

Many thanks for your help.

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

More
8 years 9 months ago - 8 years 9 months ago #676 by Frank
Hi
When the Localize component is enabled, if there is no term, it takes the text of the Label and uses that as the term.
Modifying the label's text after that point doesn't override the Localize component.

If you want to change the term dynamically, you can use the SetTerm(term, null) function.

Here is an example:
inter-illusion.com/forum/i2-localization...ith-dynamic-term#499

Basically, instead of modifying the label text, you have to pass that string into the SetTerm and the Localize component will update the label's text with the correct translation.

instead of
myText.text = "ITEM_0";

you should do:
myText.GetComponent<Localize>().SetTerm("ITEM_0", null); 

that will translate ITEM_0 to the current language and update the myText.text with the translation.


Alternatively, you can do it manually (you don't need a Localize component for this next)
myText.text = ScriptLocalization.Get("ITEM_0");


You can also use the Localization Callback to override the Localize component and get the correct term, but that will be more code than needed :-)

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
Last edit: 8 years 9 months ago by Frank.

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

More
8 years 9 months ago #677 by protostarDean
Hi Frank,

Ok, No probs. I can deal with that.
Thanks for the super quick reply.

Keep up the good work :-)

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

Time to create page: 0.460 seconds
Template by JoomlaShine