On Localize Callback doesnt work

More
8 years 4 days ago - 8 years 4 days ago #1325 by wagenheimer
Inspector setup:



Function code:
public class LocalizationCallback : MonoBehaviour
    {

        public void RestartPopupText()
        {
            Localize.MainTranslation = "Test";
        }

    }

Using version I2 Localization 2.6.5 b3. Text is blank. If debugging, function is never executed

Edit: It works if there is a term selected. I think it should work without a term selected too. B)
Last edit: 8 years 4 days ago by wagenheimer.

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

More
8 years 4 days ago #1326 by Frank
Hi,
I just tested the example scene "UnityStandard Localization" and the callback in there is still receiving the call. Which makes me think there is a problem with the setup you are showing.

One thing I noticed is that the callback target its pointing to the Text component, instead of pointing to your LocalizationCallback component.
For calling I'm using the SendMessage from unity which should call the target function in all behaviours inside the gameObject, but it could be that its trying to only call the Text component.

Can you please, try fixing that by using one of the following ways:
1- Make the callback point to your localizationCallback component. Just lock it and drag the component into the target field, instead of draging the Text component.

2- Modify the file "Assets\I2\Localization\Scripts\EventCallback.cs" to call
Target.gameObject.SendMessage (...) instead of
Target.SendMessage(...)

it should look like:
public class EventCallback
	{
		public MonoBehaviour Target;
		public string MethodName = string.Empty;

		public void Execute( UnityEngine.Object Sender = null )
		{
			if (Target && Application.isPlaying)
				Target.gameObject.SendMessage(MethodName, Sender, SendMessageOptions.DontRequireReceiver);
		}
	}

Hope that helps and please let me know if that fixed it.
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

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

More
8 years 2 days ago #1333 by wagenheimer
Hi Frank,

Have you read my edit?

Edit: It works if there is a term selected. I think it should work without a term selected too.


About the Text component: The LocalizationCallback component is attached to the same Text GameObject, thats why it's pointing to "Text" I guess :)

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

More
8 years 2 days ago #1334 by Frank
Hi,
Sorry to ask, but what you mean by "If there is a term selected"?
Do you mean, that your text is empty and the term is empty or none? Can you post a screenshot of the full Localize inspector?

If what you want is to call a method (e.g. RestartPopupText()) whenever localization happens. Then you could use the global localization callback.
public class LocalizationCallback : MonoBehaviour
    {
        public void Start()
        {
                I2.Loc.LocalizationManager.OnLocalizeEvent += RestartPopupText;
        }

        public void OnDestroy()
        {
                I2.Loc.LocalizationManager.OnLocalizeEvent -= RestartPopupText;
        }

        public void RestartPopupText()
        {
                // do anything here that you want to be executed everytime the language is changed
        }

    }

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

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

More
8 years 2 days ago #1335 by wagenheimer

Frank wrote: Hi,
Sorry to ask, but what you mean by "If there is a term selected"?
Do you mean, that your text is empty and the term is empty or none?


Exactly

Frank wrote: If what you want is to call a method (e.g. RestartPopupText()) whenever localization happens. Then you could use the global localization callback.

public class LocalizationCallback : MonoBehaviour
    {
        public void Start()
        {
                I2.Loc.LocalizationManager.OnLocalizeEvent += RestartPopupText;
        }

        public void OnDestroy()
        {
                I2.Loc.LocalizationManager.OnLocalizeEvent -= RestartPopupText;
        }

        public void RestartPopupText()
        {
                // do anything here that you want to be executed everytime the language is changed
        }

    }

Hope that helps,
Frank


This OnLocalizeEvent will be executed only on the current Localize script?

Anyway, it doesnt make sense to cancel the execution of the callback if there is no term selected.

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

More
8 years 1 day ago #1336 by Frank

This OnLocalizeEvent will be executed only on the current Localize script?


Yes, the local function is registered and will be called for that instance.

Anyway, it doesnt make sense to cancel the execution of the callback if there is no term selected.


The Localization callback of a Localize component is meant to be used for modifying the translation of a term.
If there is no Term selected on the Localize component and no term can be inferred by the Label's text, then I fail to see a point for executing the callback.

For getting a notification of when a Language is changed or a LocalizeAll command is issued, the plugin supports the global callback as shown in the previous example.
LocalizationManager.OnLocalizeEvent += callbackFunction;


Nonetheless, you can modify the Localize.cs file (OnLocalize function) to comment the line that checks if there is a FinalTranslation or a FinalSecondaryTranslation.


If you could explain me a bit more what you are trying to accomplish I could point you to a better solution.
Are you just trying to fill a popup whenever the language changes?
Or trying to localize each of the sub strings of the popup?
Or just want to execute a function when the language changes?

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.238 seconds
Template by JoomlaShine