Support => NGUI 3 Support => Topic started by: capitalj on August 13, 2012, 11:34:10 PM
Title: Localization keys
Post by: capitalj 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:
string x ="Airstrike successful";
x +="\nYou lost a plane during the airstrike";
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
Title: Re: Localization keys
Post by: Malzbier on August 14, 2012, 03:45:26 AM
Its not a ngui solution but what about String.Replace (http://msdn.microsoft.com/de-de/library/fk49wtc1.aspx) ? Just replace a placeholder with the current variable.
Title: Re: Localization keys
Post by: capitalj 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
Title: Re: Localization keys
Post by: ArenMook 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
Title: Re: Localization keys
Post by: capitalj 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.