Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MSachs · Jan 21, 2020 at 07:49 AM · webglwwwjsonstreamingassetslocalization

Loaclization in WebGL?

Hi,


I would like to implement multiple languages into my WebGL build. I already did this tutorial: https://youtu.be/5Kt9jbnqzKA to get used to the general idea. But sadly the "StreamingAssets" folder can't be accessed directly when building for WebGL.

Has anyone experience with this and could point me in the right direction on how to accomplish localization in WebGL?


Thanks in advance :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Getsumi3 · Jan 30, 2020 at 07:06 PM

Hey @MSachs !

It's actually pretty easy to do it.




First. You can use your own localization but take a look at Lean Localization (it's free). https://assetstore.unity.com/packages/tools/localization/lean-localization-28504

It will save you some precious time, Easy to implement and almost no codding required.




Second. You can access almost any file/folder. For this you can use UnityWebRequest like it's said in the docs:

Use the UnityWebRequest class to access the Assets

Here is an example using UnityWebRequest

 public IEnumerator GetFileCo(string _filename)
     {
         string fullPath = Path.Combine(Application.streamingAssetsPath, _filename);
         var uwrLocal = UnityWebRequest.Get("file:///" + fullPath);
 
         yield return uwrLocal.SendWebRequest();
         if (uwrLocal.isHttpError || uwrLocal.isNetworkError)
         {
             Debug.Log("Error while getting the file. Code: " + uwrLocal.error);
         }
         else
         {
             Debug.Log("File content: " + uwrLocal.downloadHandler.text);
         }
     }


Third Let's say that you want to have your webgl language same as website language. For this you'll need to send message from webpage and then make an externall call from webgl to receive data.

Here is the trick. In your webgl index.html create a js function after unityInstance:

 function OnUnityReady() {
             unityInstance.SendMessage("WebRequestHandler", "SetLanguage", "en");
         };

The name of the function is the name that will be called in unity.
The first param of SendMessage is the script class name in Unity. Let's say it's WebRequestHandler.cs
The second param is the name of your method that will be executed. Lets say it's void SetLanguage(string _langID).
And the third param is the method's param. In our case it is _langID (You'll need to make a js function that will get the current language of your page and return a string with language code).



Now lets look what will happen inside WebGL. First of all create a new scene that will act as a splashScreen/loadingScreen and a script that will be called WebRequestHandler.cs. This script will be the bridge between website and unity.

Here how script will look inside:

 public string languageID;
 
 private void Start()
     {
         //calling OnUnityReady from JS script
         Application.ExternalCall("OnUnityReady");
 
         LoadScene();
     }

      //this is the method that is using in index.html to set language
     public void SetLanguage(string _langID)
     {
         languageID= _langID;
     }
 
     public void LoadScene()
     {
         if(languageID != "")
         {
            StartCoroutine(PrepareMainMenu());
         }
         else
         {
            languageID = defaultLanguageID;
            StartCoroutine(PrepareMainMenu());
         }
     }
 
     public Ienumerator PrepareMainMenu()
     {
         AsyncOperation loadAsync = SceneManager.LoadSceneAsync(yourSceneIndex);
         while (!loadAsync.isDone)
         {
             progressText.text = "INITIALIZING: " + (loadAsync.progress * 100) + "%";
 
             if (loadAsync.progress >= 0.9f)
             {
                 loadAsync.allowSceneActivation = true;
             }
             yield return null;
         }
     }

}

And basicaly that's all. All that remains is to tell to your localizationManager that language = languageID from WebRequestHandler

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Streaming Assets android 0 Answers

Streaming MP3s in WebGL Editor 0 Answers

How do I get into my StreamingAssets folder for the Web? 0 Answers

How to Write streamingAssets folder files to webgl persistent data at run time? 0 Answers

WebGL and Access-Control-Allow-Origin 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges