58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace NEG.Localization
|
|
{
|
|
public class LocalizationProvider
|
|
{
|
|
private readonly Dictionary<string, string> texts = new();
|
|
private readonly Dictionary<int, string> posToString = new();
|
|
|
|
public LocalizationProvider(string path)
|
|
{
|
|
|
|
}
|
|
|
|
public string GetText(string key)
|
|
{
|
|
if (texts.TryGetValue(key, out string val))
|
|
{
|
|
return val;
|
|
}
|
|
|
|
return "BAD_" + key;
|
|
}
|
|
|
|
public string GetText(string key, params LocalizationContext[] contexts)
|
|
{
|
|
return "BAD_" + key;
|
|
}
|
|
|
|
internal void RegisterKeys(BinaryReader keysReader)
|
|
{
|
|
int i = 0;
|
|
while (keysReader.BaseStream.Position < keysReader.BaseStream.Length)
|
|
{
|
|
string read = keysReader.ReadString();
|
|
if (texts.ContainsKey(read))
|
|
Debug.LogWarning($"{read} is already added to localization");
|
|
else
|
|
texts.Add(read, "");
|
|
posToString.Add(++i, read);
|
|
}
|
|
}
|
|
|
|
internal void ChangeLanguage(BinaryReader reader)
|
|
{
|
|
int i = 0;
|
|
while (reader.BaseStream.Position < reader.BaseStream.Length)
|
|
{
|
|
texts[posToString[++i]] = reader.ReadString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|