Change numbers value dynamically

More
9 years 5 months ago #877 by vhasselmann
Hello,

I'm new to the plugin, have searched already on the forum, but didn't find it out.

Is there a way to change numbers or whatelse dynamically in a term using some of the I2Localization functions?

e.g: "Do X points" - I need to change this X for whatever number i want.

Thanks.

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

More
9 years 5 months ago - 9 years 5 months ago #878 by Frank
The plugin has Callbacks that allow modifying the translation.
In the Unity Standard Localization scene there is an example that uses "{PLAYER} wins"

and dynamically changes {PLAYER} by the Color of the player.
It also keeps the correct order of words, so in spanish it shows like "El {PLAYER} ha ganado" -> "El Rojo ha ganado"

Basically, you just need to add a function to one of your scripts that does the modification, and then on the Localize component, there is section at the end that allows selecting the object and method name for doing the modification.
Every time the object is localized, it will call your function to process it before showing it in the label.

More info about that:

forum.unity3d.com/threads/i2-localizatio.../page-2#post-1880413
inter-illusion.com/forum/i2-localization...raweventcallback#128
public void OnModifyLocalization()
{
      if (string.IsNullOrEmpty(Localize.MainTranslation))
          return;
 
     string PlayerColor = LocalizationManager.GetTermTranslation( "Color/Red" );
 
     Localize.MainTranslation = Localize.MainTranslation.Replace("{PLAYER_COLOR}", PlayerColor);
}



Also, If you are not using the Localize component in that label, and instead you are just adjusting things on your code. You can use:
var text = ScriptLocalization.Get("YourTerm", false);     // this term should be translated with {0} where you want the replacement. e.g. "Do {0} points"
var Xvalue = 30;

text = text.Replace("{0}", Xvalue);

if (LocalizationManager.IsRight2Left)               // Only fix for RTL if the current language is RTL
      text = ArabicSupport.ArabicFixer.Fix(text);

Hope that helps.

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: 9 years 5 months ago by Frank.
The following user(s) said Thank You: vhasselmann

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

More
9 years 5 months ago #879 by vhasselmann
Thanks for your fast reply, this will be really usefull.

I appreciate it. :)

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

Time to create page: 0.180 seconds
Template by JoomlaShine