Search Unity

Question How to add change language option in game

Discussion in 'Localization Tools' started by Only4gamers, Aug 6, 2020.

  1. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Hello,
    I want to add language change option in-game. But I am new in coding and localization. can someone please help me on code?
    Thanks.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    There is a sample in the package called LocaleMenuIMGUI that should give you something to start with.
    Open the package manager and look at the samples section for the package.
     
    Only4gamers likes this.
  3. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Thanks for quick help. As I never use script for implementing UIs. it's really tough to understand UI part of those scripts.
    I want UI to look like my game UI style (I added some text using Photoshop for better understanding):

     

    Attached Files:

  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    list.gif Here is an example scene with 2 different ways to create a language selection menu.
    These samples will also be in the next release
    :)
     

    Attached Files:

    Last edited: Aug 7, 2020
    Only4gamers and Mauri like this.
  5. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Thank you so much for this great help :). But when I imported this package, console gives me 182 errors. Most are for words with "[ ]". Like [test] [SetUp] etc.

    Example:
    The type or namespace name 'SetUp' could not be found (are you missing a using directive or an assembly reference?)

    So, I deleted them (Are they needed?) But after deleting all these words there is still 16 errors of these:
    The type or namespace name 'Pool' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
    The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)
    The type or namespace name 'IPrebuildSetup' could not be found (are you missing a using directive or an assembly reference?)
     
    Last edited: Aug 7, 2020
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Ah for some reason it exported way too much. You have a bunch of the Localization tests :D
    ok here is a cut down version with just what you need
     

    Attached Files:

    Only4gamers likes this.
  7. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Ok, Thanks. Localization change is working fine in editor but in Android device it is Not clickable in dropdown mode (And maybe same with the other one). I tried previously with the sample package LocaleMenuIMGUI available in package manager and that time also same thing. Nothing was visible that time too. is IMGUI support in Android devices?

    Other than that can we add Language option like this (Available in LocaleMenuIMGUI):
    Russian (Russian in russian language)
    Arabic (Arabic in arabic language)

    If this is something easy to implement then please add this feature otherwise never mind.
     
    Last edited: Aug 8, 2020
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    It should work in Android. Are you using the new input system?
     
    Only4gamers likes this.
  9. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    No, I am not using new input system.
     
  10. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Just this is visible, and clicking on it not opening drop down.
     

    Attached Files:

  11. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    while debugging my game, I found these errors, maybe helpfull:

    Code (CSharp):
    1. 08-08 16:38:54.923: E/Unity(21408): MissingMethodException: Default constructor not found for type UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[[System.Collections.Generic.IList`1[[UnityEngine.Localization.Locale, Unity.Localization, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
    2. 08-08 16:38:54.923: E/Unity(21408):   at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
    3. 08-08 16:38:54.923: E/Unity(21408):   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
    4. 08-08 16:38:54.923: E/Unity(21408):   at UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (System.Type type, System.Int32 typeHash) [0x00000] in <00000000000000000000000000000000>:0
    5. 08-08 16:38:54.923: E/Unity(21408):   at UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (System.Type actualType, System.Int32 typeHash, System.Int32 operationHash, System.Action`1[T] onDestroyAction) [0x00000] in <00000000000000000000000000000000>:0
    6. 08-08 16:38:54.923: E/Unity(21408):   at UnityEngi
    7. 08-08 16:38:54.951: E/Unity(21408): MissingMethodException: Default constructor not found for type UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[[System.Collections.Generic.IList`1[[UnityEngine.Localization.Locale, Unity.Localization, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
    8. 08-08 16:38:54.951: E/Unity(21408):   at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
    9. 08-08 16:38:54.951: E/Unity(21408):   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
    10. 08-08 16:38:54.951: E/Unity(21408):   at UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (System.Type type, System.Int32 typeHash) [0x00000] in <00000000000000000000000000000000>:0
    11. 08-08 16:38:54.951: E/Unity(21408):   at UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (System.Type actualType, System.Int32 typeHash, System.Int32 operationHash, System.Action`1[T] onDestroyAction) [0x00000] in <00000000000000000000000000000000>:0
    12. 08-08 16:38:54.951: E/Unity(21408):   at UnityEngi
    13.  
     
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Are you using stripping? It won't work with code stripping at the moment due to a bug with SerialiseReference.
    Have you built the addressable assets?
     
    Only4gamers likes this.
  13. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    I disabled strip engine code but no help. I am not using addressable assets. just addressables added by Localization Package. I don't know much about addressable So, I never touched anything related this.
     
  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    To use Localization in the player you need to build the Addressables. Windows/Asset Management/Addressable/Groups.
    Click Build at the top and build player content. Now build the android game and it should work.
     
    Fergmart and Only4gamers like this.
  15. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Sorry to disturb you again but which one is player content? there is New build, Clean Build, Update a Previous Build and many options inside those Builds.
     
  16. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Try doing a new build.
     
    Only4gamers likes this.
  17. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Thank you so much, It finally worked now. But when I am restarting game language setting back to English. How to save selected language?
     
  18. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    What does your Localization settings look like? Click the + button for the locale selectors. I think there's one called player Prefs selector. Drag that to the top.
     
  19. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    FYI: on 0.7.1.preview it doesn't seem to be added by default, which I think would be a reasonable thing to consider doing.
     
    karl_jones likes this.
  20. agnesmegghan

    agnesmegghan

    Joined:
    Mar 4, 2022
    Posts:
    3
    Sorry to bother, but I tried your: ugui sample.unitypackage to see what I was missing in creating a langue selection menu and though it works in unity with no errors on console my visual studio is very angry throwing errors saying that "UI namespace doesn't exist in the namespace "UnityEngine". I'm using unity 2020.3.30f1
     
  21. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    There is an updated sample with the package. Go into the package manager window and you should see a Samples section under the localization package.
     
  22. agnesmegghan

    agnesmegghan

    Joined:
    Mar 4, 2022
    Posts:
    3
    I tried with the updated sample package and still the same errors. I also tried to regenerate the files and still "UI namespace doesn't exist in the namespace "UnityEngine" persist.
    upload_2022-4-7_16-55-8.png
     
  23. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Did you remove the ugui package? Go into the package manager and check if you have the "Unity UI" package in the project.

    upload_2022-4-7_21-0-59.png

    Also, are the errors coming from Unity or just visual studio? If its just visual studio then you probably need to enable the visual studio package (Visual Studio Editor) and regenerate the solution file.
     
    agnesmegghan likes this.
  24. agnesmegghan

    agnesmegghan

    Joined:
    Mar 4, 2022
    Posts:
    3

    Yes, I removed the ugui package and installed the sample from the package manager under Localization >Samples, and I do have "Unity UI" installed.
    The errors are just in Visual Studio and I already tried to go to Preferences> Regenerate project files. Still nothing.
    Also, Visual Studio Editor Package seems to be enabled in the package manager. upload_2022-4-7_17-31-52.png

    Edit: I tried the whole process in a new project and now it works, it seems I did something in the previous one that well... Unity didn't like it lol. Thank you, Karl!
     
    Last edited: Apr 7, 2022
  25. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    That's strange. This sounds like an issue with visual studio. Sounds like the generated solution is missing some references. You may be able to fix it on the preferences, maybe enabling the option to also include packages?
     
  26. IDK if this is the case, but similar things happen if you use assembly definition files and you don't add the proper references to them.
     
    karl_jones likes this.