Parameters isn't change when I apply text by code

More
7 years 11 months ago - 7 years 11 months ago #1971 by Philomat
Hi,
I apply text to UI label by code
using I2.Loc;
using UnityEngine;
using UnityEngine.UI;

void Start()
{
  string desc = ScriptLocalization.Get("_missionReachScore");
  GetComponent<Text>().text= "" + desc;
}

key "_missionReachScore" value is
Win any level with more than {[SCORE]} score

In your examples Parameters changing by attaching Localize component to label, can I do same in my script without Localize component?
Last edit: 7 years 11 months ago by Philomat.

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

More
7 years 11 months ago #1973 by Frank
Hi,
ScriptLocalization.Get doesn't call the parameters directly, so that you could do some further processing (changing/adding parameters before replacing them).

You need to call
LocalizationManager.ApplyLocalizationParams(ref desc, null);

to replace the GLOBAL parameters in desc.

You can register global parameters using a script similar to
Assets\I2\Localization\Examples\Common\Scripts\GlobalParametersExample.cs
Just add that to any of the objects in your first scene.

That way, the code becomes:
using I2.Loc;
using UnityEngine;
using UnityEngine.UI;

void Start()
{
  string desc = ScriptLocalization.Get("_missionReachScore");

  LocalizationManager.ApplyLocalizationParams(ref desc, null);
  GetComponent<Text>().text= "" + desc;
}

using UnityEngine;
using System.Collections;

namespace I2.Loc
{

    public class GlobalParametersExample : RegisterGlobalParameters
	{
		public override string GetParameterValue( string ParamName )
        {
            if (ParamName == "WINNER")
                return "Javier";            // For your game, get this value from your Game Manager
            
            if (ParamName == "NUM PLAYERS")
                return 5.ToString();

            return null;
        }

	}
}

Hope that helps,
Frank

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
The following user(s) said Thank You: Philomat

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

More
7 years 11 months ago #1974 by Frank
BTW, I just added another version of ScriptLocalization.Get that automatically applies the parameters:
public static string Get(string Term, bool FixForRTL, int maxLineLengthForRTL, bool ignoreNumbers, bool applyParameters, GameObject localParametersRoot)

and you can use it like this:
string desc = ScriptLocalization.Get("_missionReachScore", LocalizationManager.IsRight2Left, 0, false, true, null);

That will be available in the new version (2.6.10a1)

Hope that helps,
Frank

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
The following user(s) said Thank You: Philomat

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

Time to create page: 0.181 seconds
Template by JoomlaShine