LocalizationParamsManager overwrites text

2 months 3 weeks ago #3564 by plourdegui

Ever since upgrading to Unity 2018.3.6f1, we are facing issues with I2 version 2.8.11 f1

Consider the following code snippet:
TextMeshProUGUI descriptionText = descriptionGo.GetComponent<TextMeshProUGUI>();
descriptionGo.GetComponent<Localize>().SetTerm(I2TermCategory.UpgradeDescription + "/" + upgrade.DescriptionCode);
descriptionText.text = descriptionText.text.Replace("888", "<color=red><b>" + upgrade.AmountFormulaForDescription + "</b></color>");
We used to effectively replace arbitrary placeholders (e.g. 888) with actual numbers. In the example above, 888 would be replaced by something like <color=red><b>30</b></color>.

The reason why we use placeholders in the form of a number such as 888, is because it makes it easy for us to set our strings of text in a Google spreadsheet where each column has the text for a different language.
Then, a special formula translates the content for languages automatically by querying Google Translate. The automatic translation would be messy if the placeholder was anything other than a number (e.g. 888).

So, ever since upgrading, we notice that LocalizationParamsManager calls a method named DoAutoRegister which eventually rewrites the string into its original version, hence making the third line in the snipped above useless.

Could you please advise?

Thanks and regards,

Please Log in or Create an account to join the conversation.

2 months 3 weeks ago #3566 by Frank
The problem you are facing is that you are modifying the text directly.
When a label has a Localize component, all the text modification should be done by the Localize component. Otherwise, that modification is overriten whenever the component needs to re-localize (e.g. When switching languages, enabling the object, a new param manager is enabled so that it could localize parameters in that object, etc).

You have several ways of handling what you need:

1- Use parameters ( inter-illusion.com/assets/I2LocalizationManual/Parameters.html )
If the translation of each term "<upgradeDescription>/<descriptionCode>" has the format: "<color=red><b>{[AMOUNT_DESC1]}</b></color>".
And you have a global parameter manager like this one:
	public class GlobalParametersExample : RegisterGlobalParameters
		public override string GetParameterValue( string ParamName )
			if (ParamName == "AMOUNT_DESC1")
				return 30;

			if (ParamName == "AMOUNT_DESC2")
				return GameManager().GeAmountForDescription(2);

			return null;

Then, whenever you do SetTerm, the plugin will query for the amount corresponding to that upgrade parameter and replace the it in the translation.

2- Use Callback ( inter-illusion.com/assets/I2LocalizationManual/Callbacks.html )
If you want more control over the replacement, you can set a callback to execute your own code whenever the SetTerm happens or a re-localization is needed:
public void OnModifyLocalization()
       // if no MainTranslation then skip (most likely this localize component only changes the font)
       if (string.IsNullOrEmpty(Localize.MainTranslation))

       // get the amount from the script tha has that data
       int upgradeAmount = GetComponent<YourScript>().GetAmountForCurrentUpgrade();       

       Localize.MainTranslation = Localize.MainTranslation.Replace("888", "<color=red><b>" + upgradeAmount + "</b></color>");

3- Don't use Localize component at all.
If you have a Localize component attached to the label, then anytime it needs to re-localize it will modify the text.
You could bypass this by removing the Localize component and doing the traslation manually instead of doing SetTerm
TextMeshProUGUI descriptionText = descriptionGo.GetComponent<TextMeshProUGUI>();
string translation = LocalizationManager.GetTranslation(I2TermCategory.UpgradeDescription + "/" + upgrade.DescriptionCode);
descriptionText.text = translation.Replace("888", "<color=red><b>" + upgrade.AmountFormulaForDescription + "</b></color>");

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

Please Log in or Create an account to join the conversation.

Time to create page: 0.106 seconds
Template by JoomlaShine