Author Topic: Localization with dynamic numbers  (Read 1517 times)

badawe

  • Jr. Member
  • **
  • Thank You
  • -Given: 8
  • -Receive: 7
  • Posts: 70
    • View Profile
Localization with dynamic numbers
« on: December 05, 2013, 11:19:04 AM »
Hey guys, just to help anyone out there with the same thing;

We have some things in our game, like a button to with the label "Hire for $10" but this needs to be localized, and I started using replace, but now we've come with a better way, just add this new method to Localization.cs

  1.     static public string Localize(string key, params object[] pValue)
  2.     {
  3.         string tString = Localize(key);
  4.         tString = string.Format(tString, pValue);
  5.         return tString;
  6.     }
  7.  

And in our language.txt use like that:
  1. hire_btn = Hire for {0}
  2.  


and in your code you can just pass, many parameters as you want, like these:
  1. hireLabel.text = Localization.Localize("hire_btn", tLevelPrice);
  2.  

Help us here! I hope can help any other! Maybe Aren can put this by default on the Localization.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization with dynamic numbers
« Reply #1 on: December 05, 2013, 03:21:21 PM »
  1. hireLabel.text = string.Format(Localization.Localize("hire_btn"), tLevelPrice);
No extra function necessary.