123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace I2.Loc
- {
- [Serializable]
- public class TermData
- {
- public string GetTranslation(int idx, string specialization = null)
- {
- string text = this.Languages[idx];
- if (text != null)
- {
- text = SpecializationManager.GetSpecializedText(text, specialization);
- text = text.Replace("[i2nt]", string.Empty).Replace("[/i2nt]", string.Empty);
- }
- return text;
- }
- public void SetTranslation(int idx, string translation, string specialization = null)
- {
- this.Languages[idx] = SpecializationManager.SetSpecializedText(this.Languages[idx], translation, specialization);
- }
- public void RemoveSpecialization(string specialization)
- {
- for (int i = 0; i < this.Languages.Length; i++)
- {
- this.RemoveSpecialization(i, specialization);
- }
- }
- public void RemoveSpecialization(int idx, string specialization)
- {
- string text = this.Languages[idx];
- if (specialization == "Any" || !text.Contains("[i2s_" + specialization + "]"))
- {
- return;
- }
- Dictionary<string, string> specializations = SpecializationManager.GetSpecializations(text, null);
- specializations.Remove(specialization);
- this.Languages[idx] = SpecializationManager.SetSpecializedText(specializations);
- }
- public bool IsAutoTranslated(int idx, bool IsTouch)
- {
- return (this.Flags[idx] & 2) > 0;
- }
- public void Validate()
- {
- int num = Mathf.Max(this.Languages.Length, this.Flags.Length);
- if (this.Languages.Length != num)
- {
- Array.Resize<string>(ref this.Languages, num);
- }
- if (this.Flags.Length != num)
- {
- Array.Resize<byte>(ref this.Flags, num);
- }
- if (this.Languages_Touch != null)
- {
- for (int i = 0; i < Mathf.Min(this.Languages_Touch.Length, num); i++)
- {
- if (string.IsNullOrEmpty(this.Languages[i]) && !string.IsNullOrEmpty(this.Languages_Touch[i]))
- {
- this.Languages[i] = this.Languages_Touch[i];
- this.Languages_Touch[i] = null;
- }
- }
- this.Languages_Touch = null;
- }
- }
- public bool IsTerm(string name, bool allowCategoryMistmatch)
- {
- if (!allowCategoryMistmatch)
- {
- return name == this.Term;
- }
- return name == LanguageSource.GetKeyFromFullTerm(this.Term, false);
- }
- public bool HasSpecializations()
- {
- for (int i = 0; i < this.Languages.Length; i++)
- {
- if (!string.IsNullOrEmpty(this.Languages[i]) && this.Languages[i].Contains("[i2s_"))
- {
- return true;
- }
- }
- return false;
- }
- public List<string> GetAllSpecializations()
- {
- List<string> list = new List<string>();
- for (int i = 0; i < this.Languages.Length; i++)
- {
- SpecializationManager.AppendSpecializations(this.Languages[i], list);
- }
- return list;
- }
- public string Term = string.Empty;
- public eTermType TermType;
- public string Description;
- public string[] Languages = new string[0];
- public byte[] Flags = new byte[0];
- [SerializeField]
- private string[] Languages_Touch;
- }
- }
|