Welcome, Guest
Username: Password: Remember me

TOPIC: Change numbers value dynamically

Change numbers value dynamically 3 years 6 months ago #877


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.

The administrator has disabled public write access.

Change numbers value dynamically 3 years 6 months ago #878

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 1178
  • Thank you received: 253
  • Karma: 78
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:

public void OnModifyLocalization()
      if (string.IsNullOrEmpty(Localize.MainTranslation))
     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 6 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 6 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.091 seconds
Template by JoomlaShine