Change language manually by <ILocalizationManager>

Using Naninovel C# APIs: adding custom actor implementations or commands, overriding engine services, integrating with other systems, etc.
Post Reply
MBoy
Posts: 7
Joined: 12 Jul 2020 01:25

Change language manually by <ILocalizationManager>

Post by MBoy »

I'm working on integration with Adventure Creator and Naninovel and
trying to switch Naninovel language manually when a user switched language from Adventure Creator's UI.

With the code below, at first glance it seemd to work without error, but only Managed Text is switched but Script(.nani) remains unchanged.
I would be happy if you could tell me what is wrong!

Code: Select all


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;
using Naninovel;

public class CustomScript : MonoBehaviour
{

    void setLanguage (int language)
    {
        int locale = AC.Options.GetLanguage ();
        var naniLocaleManager = Engine.GetService<ILocalizationManager>();

        if (naniLocaleManager != null)
        {

            switch (locale)
            {
                case 0:
                naniLocaleManager.SelectLocaleAsync ("ja");
                break;
            
                case 1:
                naniLocaleManager.SelectLocaleAsync ("en");
                break;
            }
            
        }

    }

    void OnEnable ()
    {
        EventManager.OnChangeLanguage += setLanguage;
    }

    void OnDisable ()
    {
        EventManager.OnChangeLanguage -= setLanguage;
    }


}
Elringus
admin
Posts: 538
Joined: 11 May 2020 18:03

Re: Change language manually by <ILocalizationManager>

Post by Elringus »

Check out language dropdown script from the game settings UI. There are additional steps required in case you want to update currently displayed printed text.

MBoy
Posts: 7
Joined: 12 Jul 2020 01:25

Re: Change language manually by <ILocalizationManager>

Post by MBoy »

I checked the script and I guess I understood.
Thanks!

Post Reply