Author Topic: Localization keys  (Read 3930 times)

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Localization keys
« on: August 13, 2012, 11:34:10 PM »
Hi,

I'm wondering if there is a way to localize strings that are created by combining several strings based on an event outcome, without making a key/string pair for every possibility?

For example: a text message in my game is created based on the outcome of an airstrike, so if the airstrike is successful the string will add together a few components like:

  1. string x = "Airstrike successful";
  2. x += "\nYou lost a plane during the airstrike";
  3. x += "\nYou dealt " + damageAmount + " damage";

I don't think there would be any way to insert the damageAmount integer, but what about the rest of the message?

-JJ

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Localization keys
« Reply #1 on: August 14, 2012, 03:45:26 AM »
Its not a ngui solution but what about String.Replace ?
Just replace a placeholder with the current variable.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Localization keys
« Reply #2 on: August 14, 2012, 11:50:01 AM »
Hi,

Thanks for the suggestion. How would that work with the localization keys? I don't want to actually modify any of the string in the uiLabel.text as it is being filled with the localized version by the NGUI localization.

-JJ

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization keys
« Reply #3 on: August 14, 2012, 03:30:44 PM »
Look into string.Format. Your localized string can then be this:

Quote
You lost a plane during the airstrike\nYou dealt {0} damage

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Localization keys
« Reply #4 on: August 15, 2012, 04:07:50 PM »
Awesome, thank you!

Here's what I did, it works, but if there's a better way to do this then let me know. I just experimented.

Localization string:
  1. TURN TIMER\n{0}:{1}

and the code in script handling this text:
  1. timerText.GetComponent<UILocalize>().Localize();
  2. timerText.text = string.Format(multiplayerTimerText.text, minutes, seconds);