Localized URL for youtube player

Hi all,

I am using Unity 2020 and the Localization package.
I use the localization to give a language specific url to a youtube player.
But I guess the URL is not working. Anyone know why?
The youtube player in general is working.

using UnityEngine;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.Localization.Settings;
using Vuplex.WebView;

class TutorialView : MonoBehaviour {

    CanvasWebViewPrefab _canvasWebViewPrefab;
    string url;

    void Start() {
        setLocalUrl("Tutorial", "TUTORIAL_URL");

        var canvas = GameObject.Find("Canvas");
        // Create a CanvasWebViewPrefab
        // https://developer.vuplex.com/webview/CanvasWebViewPrefab
        _canvasWebViewPrefab = CanvasWebViewPrefab.Instantiate();
        _canvasWebViewPrefab.transform.SetParent(canvas.transform, false);
        _canvasWebViewPrefab.Initialized += (sender, eventArgs) => {
            _canvasWebViewPrefab.WebView.LoadUrl(url);
        };
    }

     void setLocalUrl(string key, string url) {   
            AsyncOperationHandle<string> op = LocalizationSettings.StringDatabase.GetLocalizedStringAsync(key, url);
            if (op.IsDone) {
                url = op.Result;
            } else {
                op.Completed += (o) => url = o.Result;
            }
    }
}


What happens? Does the URL get returned? Can you print it out with Debug.Log to check?

Hello Karl,

the URL is not returned. It’s empty. So the youtube player is not shown.

Changed the code but still an empty URL.

 void Start() {
        Debug.Log("in TutorialView");

        AsyncOperationHandle<string> op = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("Tutorial", "TUTORIAL_URL");
        if (op.IsDone) {
            url = op.Result;
        } else {
                op.Completed += (o) => url = o.Result;
        }

        Debug.Log("URL:" + url);

Best Regards
Fischkai

Is this in the editor or player? Did you build the addressables?

Hello Karl,

I go under “Game” and press the play-button.

Under Windows-> Asset Management → Addressables are Localization Groups:
Localization-String-Tables-English (en)
Localization-String-Tables-French (fr)
Localization-String-Tables-German (de)

Anything else I need to do?

I changed the URL default to url = “https://www.google”;

After

 AsyncOperationHandle<string> op = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("Tutorial", "TUTORIAL_URL");
        if (op.IsDone) {
            url = op.Result;
        } else {
                op.Completed += (o) => url = o.Result;
        }

the URL stays https://www.google.com.

Best Regards
Fischkai

Everything looks correct. Are you able to share the project?

Also worth trying this https://discussions.unity.com/t/829393

Hello Karl,

cannot share the project :frowning:

I attached are two screenshot.

  1. Is it the right place to set the translations?

  2. Is the Path correct? (in another attached screenshot)

Is this C#-line correct?

op.Completed += (o) => url = o.Result;

I wonder why it did not change the default url.

Best Regards
Fischkai


Does Completed get called? What is the value of result?
Everything looks fine so there must be something wrong with the setup that I can not see from the screenshots. Can you try creating a simple project and see if it happens in that?

Hello Karl,

I am trying to log it.

  } else {
                Debug.Log("in else");
                op.Completed += (o) => { Debug.Log("Result" + o.Result); url2 = o.Result;};
        }

Else is called. But there is no debug output for “Result”.

Best Regards
Fischkai

So completed never finishes or it is empty when it finishes?
What platform is this being tested on?

Hi Karl,

I have no clue if it never finishes or it is empty. But “Result” is not printed on the console.
The code keeps running and url is not changed with the localized string.

I am running Unity on windows. The target plattform is android for the VR headset Oculus Quest.

EDIT: I added “op.WaitForCompletion(); // Force synchronous loading”.
Now it sets the right URL.

Best Regards
Fischkai

1 Like

Ah gt. Sounds like it was not completing…you need to wait a few frames or call wait for completion as you did