Welcome, Guest
Username: Password: Remember me

TOPIC: Change numbers value dynamically

Change numbers value dynamically 3 years 4 months ago #877

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.
The administrator has disabled public write access.

Change numbers value dynamically 3 years 4 months ago #878

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 1146
  • Thank you received: 246
  • Karma: 74
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: 3 years 4 months ago by Frank.
The administrator has disabled public write access.
The following user(s) said Thank You: vhasselmann

Change numbers value dynamically 3 years 4 months ago #879

Thanks for your fast reply, this will be really usefull.

I appreciate it. :)
The administrator has disabled public write access.
Time to create page: 0.177 seconds
Template by JoomlaShine