This commit is contained in:
CortexCore
2024-03-31 23:31:00 +08:00
parent e179d2eb53
commit b7b89ee71a
641 changed files with 31286 additions and 22134 deletions

View File

@@ -1,12 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if RH_SerializedDictionary
using RotaryHeart.Lib.SerializableDictionary;
#endif
using AYellowpaper.SerializedCollections;
namespace BITKit
{
public sealed class TranslateSO : ScriptableObject
{
#if RH_SerializedDictionary
public SerializableDictionaryBase<string, string> dictionary = new();
#else
public SerializedDictionary<string, string> dictionary = new();
#endif
public string Get(string text, bool isLocalization = true)
{
foreach (var word in dictionary)
@@ -14,7 +22,11 @@ namespace BITKit
var value = word.Value;
if (isLocalization)
{
value = DI.Get<ITranslator>().Translate(value);
try
{
value = DI.Get<ITranslator>().Translate(value);
}
catch (NullReferenceException){}
}
text = text.Replace(word.Key, value);
}
@@ -22,11 +34,18 @@ namespace BITKit
}
public string GetAt(string key, bool isLocalization = true)
{
var translater = DI.Get<ITranslator>();
if (dictionary.TryGetValue(key, out var value))
{
if (isLocalization)
value = translater.Translate(value);
try
{
if (isLocalization)
{
var translater = DI.Get<ITranslator>();
value = translater.Translate(value);
}
}
catch (NullReferenceException){}
return value;
}
else