You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
//using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using UnityEngine.Networking;
|
|
|
|
public static class LanguageManager
|
|
{
|
|
private static string language = "ua";
|
|
|
|
public static string Language => language;
|
|
public static string FilePath => @$"{Application.streamingAssetsPath}/Languages/{language}.json";
|
|
|
|
private static Dictionary<string, string> dictionary;
|
|
|
|
static LanguageManager()
|
|
{
|
|
SetLanguage(language);
|
|
}
|
|
|
|
public static void Initialize() { }
|
|
|
|
private static Dictionary<string, string> GetLanDictionary(string langauge)
|
|
{
|
|
if (Application.platform == RuntimePlatform.Android)
|
|
{
|
|
return null;
|
|
|
|
//AndroidFileReader.Read(FilePath, () =>
|
|
//{
|
|
|
|
// //return JsonConvert.DeserializeObject<Dictionary<string, string>>(AndroidFileReader.Json);
|
|
//});
|
|
}
|
|
else
|
|
{
|
|
if (File.Exists(FilePath))
|
|
{
|
|
using (StreamReader reader = new StreamReader(FilePath))
|
|
{
|
|
string json = reader.ReadToEnd();
|
|
|
|
return null;//JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Language Get failed ");
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void SetLanguage(string language)
|
|
{
|
|
LanguageManager.language = language;
|
|
dictionary = GetLanDictionary(language);
|
|
}
|
|
|
|
public static string GetString(string str)
|
|
{
|
|
if (dictionary == null) return str;
|
|
|
|
dictionary.TryGetValue(str, out string value);
|
|
return value ?? str;
|
|
}
|
|
}
|
|
|