Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.9 kB
4
Indexable
Never
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GP_Utilities.Console;
using System.Runtime.InteropServices;
using System;
using UnityEngine.Events;

public class LanguageTest : MonoBehaviour
{
	public static event UnityAction<Language> OnChangeLanguage;
	public static event Action<Language> _onChangeLanguage;

	private static string English = "en";
	private static string Russian = "ru";

	[DllImport("__Internal")]
	private static extern string GP_Current_Language();
	public static Language Current()
	{
#if !UNITY_EDITOR && UNITY_WEBGL
            return ConvertToEnum(GP_Current_Language());
#else
		if (GP_ConsoleController.Instance.LanguageConsoleLogs)
			Debug.Log("LANGUAGE CURRENT: ");
		return Language.English;
#endif
	}

	[DllImport("__Internal")]
	private static extern void GP_ChangeLanguage(string lang);
	public static void Change(Language lang, Action<Language> onLanguageChange = null)
	{
		_onChangeLanguage = onLanguageChange;
#if !UNITY_EDITOR && UNITY_WEBGL
            GP_ChangeLanguage(ConvertToString(lang));
#else
		if (GP_ConsoleController.Instance.LanguageConsoleLogs)
			Debug.Log("LANGUAGE CHANGE: ");
		OnChangeLanguage?.Invoke(lang);
		_onChangeLanguage?.Invoke(lang);
#endif
	}

	private void CallChangeLanguage(string lang) { _onChangeLanguage?.Invoke(ConvertToEnum(lang)); OnChangeLanguage?.Invoke(ConvertToEnum(lang)); }

	private static Language ConvertToEnum(string lang)
	{
		if (lang == English)
			return Language.English;

		if (lang == Russian)
			return Language.Russian;

		

		return Language.English;
	}

	private static string ConvertToString(Language lang)
	{
		if (lang == Language.English)
			return English;

		if (lang == Language.Russian)
			return Russian;
		return English;
	}

public enum Language : byte
{
	English,
	Russian,
}

}
Leave a Comment