How To Add Support For Multiple Languages In Unity

Поделиться
HTML-код
  • Опубликовано: 1 янв 2025

Комментарии • 127

  • @DapperDinoCodingTutorials
    @DapperDinoCodingTutorials  4 года назад +10

    Check out Admix here: admixplay.com/

    • @guilherme95069
      @guilherme95069 3 года назад +1

      I really liked the video I decided to implement this system in my game, but now I can't find how to create a simple dropdow menu that changes the game's language in the game's options menu. how do i do this does anyone know???

  • @kintarios
    @kintarios 4 года назад +204

    Guys. A very important tip that the author of this fantastic video forgot to mention:
    In order to set a locale manually, you have to write a method with a return type IEnumerator.
    Then inside of that method, you must write the following c# code:
    public IEnumerator setLanguage() {
    // Wait for the localization system to initialize, loading Locales, preloading, etc.
    yield return LocalizationSettings.InitializationOperation;
    // This variable selects the language. For example, if in the table your first language is English then 0 = English. If the second language in the table is Russian then 1 = Russian etc.
    int i = numberOfTheLanguageThatYouWantToUseForUserInterface
    // This part changes the language
    LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[i];
    }
    It took me about 6 days to find a working solution to this and I hope that the author will make another video that will demonstrate how to do that through the method that I mentioned above.
    Also, I hope that my answer will help people to avoid the amount of tortures and headaches that I had while trying to figure this out.
    Warning:
    If you are building for Android or IOS and when you launch your app on the device it doesn't translate or throws null exception errors for the Locale then you must do the following:
    Add addressables in Unity Editor:
    Window -> Asset Management -> Addressables -> Groups -> Build -> New Build -> Default Build Script -> Build and Run your app. This should do the trick.
    Extra tip:
    Efficient translation:
    Do not use one language translator. Use websites that allow you to translate words into many languages at once. It will save you hours of (select language, copy, paste) cycle. Instead, you will be doing (copy, paste) cycle.
    Disclaimer:
    I am not the author of the solutions and I will write the sources of the information at the bottom. I just want to make the life of other developers easier by sharing the information mentioned above.
    Sources:
    Localization for phones - null exception errors:
    forum.unity.com/threads/solved-loading-localization-addressables-fails-in-android.830412/
    Setting locale with LocalizationSettings.SelectedLocale = locale:
    forum.unity.com/threads/how-to-update-localizestring-at-runtime.969270/

    • @namenlosnutz
      @namenlosnutz 4 года назад

      So there's no way to make localized strings update without switching to a different locale?

    • @ZoidbergForPresident
      @ZoidbergForPresident 3 года назад +4

      I wouldn't mind another video for that! Or even to get the default language of the system for the first start.

    • @ZoidbergForPresident
      @ZoidbergForPresident 3 года назад +10

      Oh here's a script for a dropdown permitting the change of locale:
      using System.Collections;
      using System.Collections.Generic;
      using TMPro;
      using UnityEngine;
      using UnityEngine.Localization.Settings;
      public class LocaleDropdown : MonoBehaviour
      {
      public TMP_Dropdown dropdown;
      IEnumerator Start()
      {
      // Wait for the localization system to initialize, loading Locales, preloading etc.
      yield return LocalizationSettings.InitializationOperation;
      // Generate list of available Locales
      var options = new List();
      int selected = 0;
      for (int i = 0; i < LocalizationSettings.AvailableLocales.Locales.Count; ++i)
      {
      var locale = LocalizationSettings.AvailableLocales.Locales[i];
      if (LocalizationSettings.SelectedLocale == locale)
      selected = i;
      options.Add(new TMP_Dropdown.OptionData(locale.name));
      }
      dropdown.options = options;
      dropdown.value = selected;
      dropdown.onValueChanged.AddListener(LocaleSelected);
      }
      static void LocaleSelected(int index)
      {
      LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];
      }
      }

    • @sanic3400
      @sanic3400 3 года назад +9

      One more extra tip:
      Always localize to Portuguese (Brazil). Thank you. ^^

    • @shadikiller9431
      @shadikiller9431 3 года назад +3

      For selecting different locales with a button you can also add localizationsettings to an onclick event and then SetSelectedLocale and offcoarse your desired locale.

  • @clarisrichter7966
    @clarisrichter7966 3 года назад +3

    Thank you Dapper Dino. You've saved me hours of time with this video. I was busy writing my own localization system when I stumbled on this

  • @bestlifetutorial
    @bestlifetutorial 4 года назад +11

    Short and good, keep it up!

  • @RugbugRedfern
    @RugbugRedfern 4 года назад +2

    Very cool that unity added support for this! Thanks for explaining it :)

  • @marscaleb
    @marscaleb 3 года назад +3

    This is very cool to see.
    I always thought I'd have to build my own localization system, and I was just about to start a system where I can grab strings from external files.
    So glad there is an official system, and what's more, that it is really easy to implement into all my different system. Whether the text is coming from a UI button, a dialogue tree, or some custom script, I should be able to easily add this on top of what I'm doing.

  • @さよこせつこ
    @さよこせつこ Год назад +1

    Latest version;
    You don't have to create C# to add some public variable,
    You have now "Local Variables".
    Just make sure you spell Variable Name same as in {playerName}
    and use String (for this example)
    And thanks for this guide =)

  • @ankitmehrotra6104
    @ankitmehrotra6104 3 года назад +1

    I did exactly same nut when I reached at 7:36, I started getting these Errors :-
    1). Exception encountered in operation Resource(settings_BuildScriptFastMode.json): Unknown error in AsyncOperation
    UnityEngine.Localization.Components.LocalizeStringEvent:OnEnable ()
    2). No Locales were available. Did you build the Addressables?
    3). Can not preload when `LocalizationSettings.SelectedLocale` is null.
    UnityEditor.EditorApplication:Internal_PlayModeStateChanged (UnityEditor.PlayModeStateChange)
    4). Can not preload when `LocalizationSettings.SelectedLocale` is null.
    UnityEditor.EditorApplication:Internal_PlayModeStateChanged (UnityEditor.PlayModeStateChange)
    Please help.

  • @Gramini
    @Gramini 4 года назад +2

    "Command Line Locale Selector" seems to be an option you can specify when running the application from the CLI, like "./myGame --language=jp" or "./myGame --lang=de". The option lets you specify what option Unity looks for when starting.

  • @fv4202x
    @fv4202x 2 года назад +4

    If you can find "string reference" go to preferences/localization and uncheck the string one.

  • @nicogs90
    @nicogs90 4 года назад +1

    I really liked the video. Thanks!! I wanted to add localisation to my future game and this looks perfect.

  • @ksepastremenos
    @ksepastremenos 4 года назад

    Such a nice little feature. Glad I checked before starting my next project

  • @tatebinkey7935
    @tatebinkey7935 3 года назад +6

    Can you please help me? How do I change the text in a string variable on a scriptable object with this system?

  • @sjoepcoup87
    @sjoepcoup87 3 года назад +5

    Hello,
    Is it also possible to change the language in an array? I would like to use it in a dialogue system. Thanks in advance for your response

  • @haachamachama7
    @haachamachama7 3 года назад +1

    Do you have an updated video? I can't seem to find the new one you said you'd make. I don't really know how to access the localization data from a script directly. I'm assuming i have to use this key I made? So, how do I, through script, set a text object to a string of a specific key from the table? And how do I select the language in game?

  • @qroqloqqq5279
    @qroqloqqq5279 4 года назад

    hi mr dinosor, just found your channel via @jasonweimann shoutout. im so happy and gonna start binge watching the basics ones and wish you dont stop your unity c# bitesize series!

  • @suchizgames4748
    @suchizgames4748 3 года назад +2

    Gotta do this for every text component ? Is there any way to use a centralized file and use key_id like "strings.xml" in android ?

  • @maximevigneron560
    @maximevigneron560 3 года назад +2

    Does someone knows how to change the key of the table in real time? I don't know how to modify the "Localize string event"

  • @perparmiha
    @perparmiha 4 года назад +2

    Really cool, well explained

  • @irhampta4033
    @irhampta4033 3 года назад +1

    how to change the current language manually using script by pressing button?

  • @namenlosnutz
    @namenlosnutz 4 года назад +3

    How to use it for localizing dropdown options?

    • @nagybalint1474
      @nagybalint1474 3 года назад +3

      THIS IS FROM *@ZoidbergForPresident*
      not me :P
      using System.Collections;
      using System.Collections.Generic;
      using TMPro;
      using UnityEngine;
      using UnityEngine.Localization.Settings;
      public class LocaleDropdown : MonoBehaviour
      {
      public TMP_Dropdown dropdown;
      IEnumerator Start()
      {
      // Wait for the localization system to initialize, loading Locales, preloading etc.
      yield return LocalizationSettings.InitializationOperation;
      // Generate list of available Locales
      var options = new List();
      int selected = 0;
      for (int i = 0; i < LocalizationSettings.AvailableLocales.Locales.Count; ++i)
      {
      var locale = LocalizationSettings.AvailableLocales.Locales[i];
      if (LocalizationSettings.SelectedLocale == locale)
      selected = i;
      options.Add(new TMP_Dropdown.OptionData(locale.name));
      }
      dropdown.options = options;
      dropdown.value = selected;
      dropdown.onValueChanged.AddListener(LocaleSelected);
      }
      static void LocaleSelected(int index)
      {
      LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];
      }
      }

    • @canaldoluanbertollo
      @canaldoluanbertollo 3 года назад

      Up ❤

  • @cvalladaresh2
    @cvalladaresh2 3 года назад +3

    Hello! Thanks for the video, it has been very useful. I was wondering if you already uploaded the follow-up where you said you will show how to change the strings via script, thanks!

  • @olivierneve3490
    @olivierneve3490 2 года назад

    Really helpful viedo thanks dude!

  • @FMontanari709
    @FMontanari709 4 года назад +3

    I assume the "command line locale selector" might mean that you can run your game through a command prompt and use that argument as a way to select the language you want, instead of having to make an actual menu or something (I don't know why you'd want that, but you've got it)

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  4 года назад

      Yup, think so too. I'd still probably just leave it on English as default then add a menu on first startup for language (as well as in setup)

  • @fabiiily
    @fabiiily 3 года назад

    Thx very helpfully. Btw nice voice

  • @sanketvaria9734
    @sanketvaria9734 3 года назад +1

    But what if the characters are different? For example you cannot use english alphabets for chinese, Hindi, Arabic and russian languages. They have totally different alphabets/characters/letters whatever it's called. So how to deal with that?

  • @rangerracing7209
    @rangerracing7209 Год назад

    could you help me to show the player name?
    In the inspector i have the field "Local Variables", i added string event with the variable name "playerName", i can show the name in the string field, but i cant change the name string by script, could u tell me how to acess that field in script?

  • @domenicococcorese5372
    @domenicococcorese5372 3 года назад +4

    Hello! Very helpful video. Just one question: is there a way to change language for script-generated strings? Something like that:
    switch(language){
    case english:
    text = hello
    case spanish:
    text = hola
    case french:
    text = bonjour
    }

    • @sephypantsu
      @sephypantsu 2 года назад +1

      I'm guessing you can assign the the string to a public variable and use the smart text thing?

  • @uaefalcon97
    @uaefalcon97 3 года назад

    I want to change the font asset depending on the language , but I coudn't figure out how to get the current selected language form script

  • @Dadax9398
    @Dadax9398 Год назад

    Nice video, very helpful !!

  • @ysl8589
    @ysl8589 3 года назад +1

    anybody knows how to localization connection google Sheets??

  • @titangamabunta
    @titangamabunta 4 года назад +1

    Hello, since this update i always get this error "InvalidProgramException: Invalid IL code in Script.Funcion (string): IL_000f: call 0x0a00000d" and i cant figure a solution, any idea??

  • @siddharthtrivedi3322
    @siddharthtrivedi3322 3 года назад +1

    Please make another video, related to other types of asset usage, and through script language change settings topics get covered.

  • @AlcadraSoykan
    @AlcadraSoykan 3 года назад

    Thanks! I encountered an issue. When I press play the text comes with a 1-2 second delay. I thought it's about the script execution order, but I couldn't fixed it.

  • @zapposh
    @zapposh 4 года назад

    Excellent video. Thanks!

  • @noobdev6464
    @noobdev6464 8 месяцев назад

    how can i implement this with a dialogue system?

  • @ederhernandez5319
    @ederhernandez5319 2 года назад

    If you have a table with a list of words, how would you make a textMesh text change to a random item of the table every 30 seconds ?

  • @siddharthtrivedi3322
    @siddharthtrivedi3322 2 года назад +2

    Hello sir, please make video related to Smart Localized String related video because this video content become outdated now.

  • @krzysztofpaszkiewicz1274
    @krzysztofpaszkiewicz1274 2 года назад

    Guys any tutorials on buttons that change the language in menu? Just like the one you have in runtime near the gizmos? Thanks

  • @dakotahernandez9511
    @dakotahernandez9511 3 года назад +2

    I'm a little late but wouldn't it make sense that you can't just do [SerializeField] private variables? Because you'd be trying to reference a private variable in another script.

  • @kameronyoung781
    @kameronyoung781 3 года назад

    This is so helpful! Thanks

  • @BeyazBaron1
    @BeyazBaron1 3 года назад

    Thank you.. but it doesn't run dinamically.. Do you know how can we change entry name dinamically? If I have a message box and want to show convenient message for some conditions. I can create Alert Message Table and prepare message box object. Therefore I have to change entry name dinamically.

  • @TheRoqco
    @TheRoqco 4 года назад

    In editor text field is empty and only show on run mode. Is there a way to show default english in editor mode also. Hard to edit text in editor this way

  • @2009heyhow
    @2009heyhow 3 года назад

    This video shows how to set this up right at the beginning of a project. But what if you decide to add new languages for a finished game and send the project to people who speak those other languages? Could their approach of translating the game be the same like instructed in the video, or will it be different to work on a finished project?

  • @jayantbarthwal4470
    @jayantbarthwal4470 2 года назад

    i am tired of changing each text one by one of my game. Is there any way of accessing table keys and values in script.

  • @kantallive
    @kantallive 3 года назад

    So how to use it with an array?

  • @MaximilianPs
    @MaximilianPs 2 года назад

    Which version it was?
    'Cause the things are much more complicated than this now 🤔

  • @subkiro
    @subkiro 3 года назад

    Hello, I installed the Localization package on Unity 2019.4.10f1, I followed the Dino steps, and when i tried to Crete a Localisation Settings, an arror accures in console, Element 'Style' has no registered factory method. UnityEditor.InspectorWindow:RedrawFromNative(). is there any solution for that? Thank you!

  • @christianstachl
    @christianstachl 3 года назад +1

    Thanks for this great tutorial.
    I'm quite new to game developing, just working on my first, very simple, game, and i just realized i want multiple languages. I'm so glad there's this quite simple method to do it, even in retrospect.
    One little question though, after implementing the localisation package there's this new folder "AdressableAssetsData". I guess i should just leave it there because it somehow manages this package?
    Edit: Two more problems, i get some "SelectedLocale is null" exceptions. Also it seems to not save the standard language. When i start my game the dropdown menu says "None". I can then select another language and back and it works, but still the initial language is somehow "None".

    • @christianstachl
      @christianstachl 3 года назад +2

      Solved it.
      If you have the same problem go to "Window -> Asset Management -> Localization Scene Controls" and set "Active Locale" to your preferred language to start the game with.
      All errors are gone now 😅

  • @OsvaldoG
    @OsvaldoG 4 года назад +2

    This sets the system language as game language by default?

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  4 года назад +1

      Not by default as far as I'm aware. But I'm sure you can do that somehow with the command line stuff at 3:38

    • @Gramini
      @Gramini 4 года назад +1

      In the "Localization" menu there is a section called "Locale Selectors", which is a list. Unity goes from top to bottom until it found a locale. The second thing there by default is the "System Locale Selector", which should do what you asked for.

    • @nagybalint1474
      @nagybalint1474 3 года назад

      lmao for me its the opposite it uses that by default and I want English by default, any idea how

  • @guilherme95069
    @guilherme95069 3 года назад +1

    I really liked the video I decided to implement this system in my game, but now I can't find how to create a simple dropdow menu that changes the game's language in the game's options menu. how do i do this does anyone know???

    • @guilherme95069
      @guilherme95069 3 года назад

      ruclips.net/video/4lnpryCQTmI/видео.html&ab_channel=TheRealProfessionalGamer

  • @tomaterasu700
    @tomaterasu700 3 года назад

    Thanks! A great tutorial

  • @Renusek
    @Renusek 2 года назад

    What about diacritics? Some letters are showing up as □ and I'm 100% sure that the font has these symbols in it.

  • @rozcuy
    @rozcuy 2 года назад

    That is soo niceee!

  • @ОлегМашков-я8х
    @ОлегМашков-я8х 4 года назад +1

    hello. I do not understand how the language is switched on a real device. Have you tried experimenting with this program on a real device with different language settings? It didn't work for me the first time...

    • @noa9956
      @noa9956 4 года назад

      have you figured out? i'm having the same problem

    • @ОлегМашков-я8х
      @ОлегМашков-я8х 4 года назад +1

      @@noa9956 Yes. I have fixed this problem. If the language is not automatically switched, then you need to check the following:
      - Does your project contain any locales?
      - Did you configure the Locale Selectors so they pick one? docs.unity3d.com/Packages/com.unity.localization@0.6/manual/LocalizationSettings.html
      - Did you build the addressable assets when building to Android?
      My problem was that I forget to build the Addresseables to work in android. To fix this problem, you need to do the following:
      Window -> Asset Manager ->Addresseables -> Groups -> Build -> New build
      When my program starts I preload the locales with: LocalizationSettings.InitializationOperation;
      My program is working!
      If you open the apk as an archive file, then after the above operation, I have a folder "aa" (*. apk\assets\aa) which contains localization files, before comparison, this folder did not appear before.
      here I wrote what was described in this forum thread: forum.unity.com/threads/android-and-localizationsettings-selectedlocale.817590/

    • @VladimirDemidovIllusiveMan
      @VladimirDemidovIllusiveMan 2 года назад

      @@ОлегМашков-я8х Thank you my man!!

  • @anonymoussloth6687
    @anonymoussloth6687 Год назад

    Is there a way to automatically translate to other languages?

  • @shporgalkanope1575
    @shporgalkanope1575 3 года назад

    There is no way i can translate my script generated string?

  • @pilztrainingen623
    @pilztrainingen623 3 года назад

    Really helpfull Video Thnks!!!

  • @VladimirDemidovIllusiveMan
    @VladimirDemidovIllusiveMan 2 года назад

    Just in case someone cant find Localization in package manager, to save you 5-10 minutes of searching
    click the plus to add a new package, click add package from GIT URL, paste this there, no quotation marks "com.unity.localization"

  • @Ultrakupra
    @Ultrakupra 3 года назад

    Good stuff,but im trying to change the language on my android phone and the game is not changing from the default language,what am i doing wrong? Do i need to check system's language by code or something?

  • @rubennavarrodavo4227
    @rubennavarrodavo4227 3 года назад

    Hi. It works on the emulator but when I execute the app in my phone it doesn't select any language. Is it necessary to do some special configuration to generate the APK? (I am working with 1.0.0 version)

  •  3 года назад

    Hey great video, i have a question tho, if i already got a little "subtitles" system for a game, which works with ScriptableObjects files to get the different strings with their timestamps to be shown at the screen, how can i implement this new localization thing to a little system like that D: ?

  • @demyanrudenko
    @demyanrudenko 3 года назад

    A quick question concerning 'smart', I have list of strings for names in my code, and a couple of text fields in the project that could have any one of those. How could I approach localizing in this case ?..

    • @nagybalint1474
      @nagybalint1474 3 года назад

      save the strings in a another script on the UI or on some canvas and use the string from there

  • @alperenkabaday6474
    @alperenkabaday6474 3 года назад

    YOU ARE A WIZARD DUDE!

  • @eladnlg
    @eladnlg 4 года назад

    I think the player name is supposed to be public because other classes cannot get the values of variables from other classes without them being public. Idk though.

  • @ebrubetulkuyu9864
    @ebrubetulkuyu9864 3 года назад

    How do we integrate mobile?

  • @Am3ricium
    @Am3ricium 4 года назад

    Unity just surprises me more and more with each released feature (even in preview). I've always been afraid to dive into localization stuff, cuz it seemed boring and tedious. And now it's not much different from anything else in the engine.
    BTW
    You can not get access to "[SerializeField] private" variables the way you want.
    They are exposed in the inspector - so you can set them, but since they are private, you can't get their data outside the script they're in.
    Making variables public is probably the only way to do what you want, unless you store your player data in ScriptableObjects, which is way easier and better probably.

    • @VladimirDemidovIllusiveMan
      @VladimirDemidovIllusiveMan 2 года назад

      I was afraid of the whole localization thing for a while too, wayy before I started making games. One day I was determined to translate this skyrim mod that was only on japaneese language (you can guess what kind of mod it was just from that fact haha), so I sat for four hours translating everything, it was a mess, but I succeeded. It was a huge mod too lol.
      I plan on storing a static public variable that will represent the language, and will be alive in every scene. Later I plan adding some sort of session, or a cookie to store the value and read it from there.

  • @ak.atakan
    @ak.atakan 4 года назад

    I added language switching from the menu to my game. When I run it in Unity, everything goes normal, but the language does not change on the android phone.

    • @nagybalint1474
      @nagybalint1474 3 года назад

      ? makes 0 sense you run it on pc and why would it change on the phone export it to android and it will work fine

    • @ak.atakan
      @ak.atakan 3 года назад

      @@nagybalint1474 what I want to say is that when I test it on the unity editor on the computer, I can change the language, but when I build and test it on the phone, it doesn't work.

  • @srazysnake0221
    @srazysnake0221 2 года назад +2

    format argument no longer exists it seems, too bad.

  • @saadanees7989
    @saadanees7989 3 года назад +1

    What about arabic?

  • @karandhir2411
    @karandhir2411 4 месяца назад

    Thank you

  • @thygrrr
    @thygrrr 4 года назад

    public makes so much more sense than serialized private, if you think about it, tho.

    • @nagybalint1474
      @nagybalint1474 3 года назад

      nop we always want to use serialized privates to save memory and stabilize gameplay etc

    • @Dxpress_
      @Dxpress_ 3 года назад

      ​@@nagybalint1474 Private/serialized fields have no affect on memory or performance. The fields take up the same amount of memory regardless.
      The main reason to use private fields over public fields is to follow object-oriented programming encapsulation conventions.

  • @aboziad100
    @aboziad100 3 года назад

    thank you for your explanation put i did expect how to write inside unity in Arabic language not translation

  • @wholebitmedia
    @wholebitmedia 3 года назад

    Thas dope!

  • @thenextstep4990
    @thenextstep4990 2 года назад

    i think when i see arabic it's finally unity support right To left languages but when i try it . i feel disappoint

  • @thenextstep4990
    @thenextstep4990 2 года назад

    Knowing that all other engines support right to left
    languages

  • @MTandi
    @MTandi 3 года назад

    It sucks that you can't use it with the new UI toolkit

    • @nagybalint1474
      @nagybalint1474 3 года назад +1

      i use this with the newest every stable until version and it works fine

    • @christianstachl
      @christianstachl 3 года назад +1

      @@nagybalint1474
      Quick question, do you get exceptions?
      I did it like in the video and basically it works fine in the editor when i switch around, but at startup i always get some exceptions that say "SelectedLocale is null".
      Edit: solved it.
      In "Window -> Asset Management -> Localization Scene Controls" i had to set "Active Locale" and now it works fine 😅

  • @OdemGeek
    @OdemGeek 3 года назад

    Ohh, I wrote my own system.

  • @nachohotdawg5634
    @nachohotdawg5634 2 года назад

    Oh man, I thought Arabic would be fixed but no..

  • @РоманЛебідь-ш3ы
    @РоманЛебідь-ш3ы Год назад

    Overcomplicated method

  • @L4zzA
    @L4zzA 2 года назад

    Currently on latest 2021.2.16 you can find the package from the package manager
    docs.unity3d.com/Packages/com.unity.localization@1.2/manual/Installation.html