Forum rules - please read before posting.

Auto detect operating system language

Hello everyone!

How are you? I'm sorry if this has been asked before but I haven't found it.
The game I am making has 3 languages and they can be selected at any time in the game as well as in the initial menu.

But I would like to autodetect the language of the operating system and automatically change the language of the game. Is there any adventure creator function or script to make this easier?

Thank you very much if someone has solved this and can share it with me.

Comments

  • I think I'd tackle it like this:

    I'd create an AC global boolean variable (let's assume its ID is 15) and link it to Options Data, with a start value of false. Then I'd write a script like this:

        using UnityEngine;
        using AC;
    
        public class SystemLanguage : MonoBehaviour
        {
            void SetSystemLanguage()
            {
                if (AC.GlobalVariables.GetBooleanValue(15)) return;
                if (Application.systemLanguage == SystemLanguage.French)
                {           
                    AC.Options.SetLanguage(0)       
                }        
                else if (Application.systemLanguage == SystemLanguage.English)
                {
                    AC.Options.SetLanguage(1);
                }        
                else if (Application.systemLanguage == SystemLanguage.Portuguese)
                {
                    AC.Options.SetLanguage(2);
                }
            AC.GlobalVariables.SetBooleanValue(15, true);
            }
        }
    

    Then I'd attach it to a GameObject in your first scene, and I'd run the AC Action Object > Send message > Custom > Method name: SetSystemLanguage in your "On start" actionlist. You'll need to adapt the script to reference the languages you're using (more info here) and their respect IDs in AC, but if you do that, you should be set. The script will only change the language to the system language the very first time the player launches the game, so that if they change the language manually, the setting won't be reset next time they run the game.

  • Hey, cool! I will try to implement that

    With SystemLanguage.English Unity understand any type of english? (UK, Australia, USA, etc?)

    Thank you!

  • I get errors. It doesn't contain a definition for 'English' or anything that follows SystemLanguage. Do you know why or how I can correct it?

  • edited February 5

    SystemLanguage.cs(17,67): error CS0117: 'SystemLanguage' does not contain a definition for 'Portuguese'

  • It's just a case of the class/filename matching that of the Enum being referenced.

    Replace SystemLanguage.English etc with UnityEngine.SystemLanguage.English and it should work.

  • edited February 6

    Thank you Chris!! I didn;'t know that

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.