Localize directly from scripts

More
10 years 8 months ago #53 by Xito
Hello!

We are using your asset to localize text and we was using something like this:

UILabel label;
label.text = Localization.Get(STRING);

In execution time. Don't We make this in I2?

Thanks.

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

More
10 years 8 months ago - 10 years 8 months ago #55 by Frank
Hi,

After you install the I2 Localization and enable the NGUI plugin by removing the comments on the #define NGUI, the plugin will automatically localize the UILabels. Just add a Localize component to the label and associate a Term.

Check this video to see how the automatic localization works for labels. The video is localizing the GUIText component but it will work the same for UILabel



However, if you want to access the localization within your scripts, you can call:
ScriptLocalization.Get( Term )

Also, a feature that I think will be interesting for project accessing the localization directly on the code is the Compile Time Checking:



The editor is able to auto-generate an script file and exposes some of the terms as variables. That way if you make a Typo the compiler will warn you about it. That eliminates the need of accessing Terms by string which could introduce errors because of Typos, Terms no longer existing, etc.

To use that feature, just open the Script tab inside the Tool in the LanguageSource, select the terms you want to expose to the script and click the button to generate the script. That will modify the ScriptLocalization file and allow you to access the terms as variables.

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

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

More
10 years 7 months ago #76 by crash
Hi, I have a problem with localize text in javascript, because of order of compilation I think. What I have to do for translate text in javascript code?

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

More
10 years 7 months ago #77 by Frank
Moving the folder I2 \ Localization \ Scripts into the plugin folder may help as that will force the plugin to compile first

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.

More
10 years 7 months ago #78 by crash
Unfortunatelly, when copy I2 to folder plugins there's a problem with google.api, which is compile after the plugin folder. Copy to folder editor doesn't helped too. If I understand correctly how to call translatation from code: after addscript "localize" to game object, where is script with my text, then I can call function localize.get(term) is it right?

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

More
10 years 7 months ago #79 by Frank
Hi,

Moving the entire I2 folder will give you issues on some of the editor scripts.
But if you just move the "I2 \ Localization \ Scripts". It could work depending on what plugin you are using.

The I2 Localization is not by default in the plugins folder because it links with other plugins like (NGUI, DF-GUI, etc) that by default are not in the Plugins folder.

If you are using an add-on that its already in the plugins folder, then you are save to move the "I2 \ Localization \ Script" folder into the Plugins folder.

To access the localization thru scripts, there are several ways and you don't even need to assign the Localize component to the objects.

On your scripts you just need to call ScriptLocalization.Get(Term)
ScriptLocalization is an static class, so you don't need any object to use it.

If what you want its changing the localization to attach numbers or other things, Like transforming
"THE SCORE IS {SCORE}" into "THE SCORE IS 320"

Then you can use the localization callbacks. There is an example on the "UnityStandards Localization" scene

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

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

Time to create page: 0.192 seconds
Template by JoomlaShine