1
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user