55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Localization.Settings;
|
|
|
|
public class TextHandler : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public static string getText(string key){
|
|
key = key.Replace("(","").Replace(")","");
|
|
if(key[0].Equals(Char.ToUpperInvariant(key[0]))){
|
|
key = Char.ToLowerInvariant(key[0]) + key.Substring(1);
|
|
}
|
|
|
|
if(key.Contains("\r\n")){
|
|
return key;
|
|
}
|
|
|
|
string text = LocalizationSettings.StringDatabase.GetLocalizedString("MyTexts",key);
|
|
return text;
|
|
}
|
|
|
|
public static string translate(string text){
|
|
string result = "";
|
|
string[] parts = text.Split(" ");
|
|
for(int i = 0; i < parts.Length; i++){
|
|
try{
|
|
int.Parse(parts[i]);
|
|
result += parts[i] + " ";
|
|
}
|
|
catch(Exception ex){
|
|
if(parts[i].Contains("/")){
|
|
result += parts[i] + " ";
|
|
}
|
|
else{
|
|
result += getText(parts[i]) + " ";
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|