TermData.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace I2.Loc
  5. {
  6. [Serializable]
  7. public class TermData
  8. {
  9. public string GetTranslation(int idx, string specialization = null)
  10. {
  11. string text = this.Languages[idx];
  12. if (text != null)
  13. {
  14. text = SpecializationManager.GetSpecializedText(text, specialization);
  15. text = text.Replace("[i2nt]", string.Empty).Replace("[/i2nt]", string.Empty);
  16. }
  17. return text;
  18. }
  19. public void SetTranslation(int idx, string translation, string specialization = null)
  20. {
  21. this.Languages[idx] = SpecializationManager.SetSpecializedText(this.Languages[idx], translation, specialization);
  22. }
  23. public void RemoveSpecialization(string specialization)
  24. {
  25. for (int i = 0; i < this.Languages.Length; i++)
  26. {
  27. this.RemoveSpecialization(i, specialization);
  28. }
  29. }
  30. public void RemoveSpecialization(int idx, string specialization)
  31. {
  32. string text = this.Languages[idx];
  33. if (specialization == "Any" || !text.Contains("[i2s_" + specialization + "]"))
  34. {
  35. return;
  36. }
  37. Dictionary<string, string> specializations = SpecializationManager.GetSpecializations(text, null);
  38. specializations.Remove(specialization);
  39. this.Languages[idx] = SpecializationManager.SetSpecializedText(specializations);
  40. }
  41. public bool IsAutoTranslated(int idx, bool IsTouch)
  42. {
  43. return (this.Flags[idx] & 2) > 0;
  44. }
  45. public void Validate()
  46. {
  47. int num = Mathf.Max(this.Languages.Length, this.Flags.Length);
  48. if (this.Languages.Length != num)
  49. {
  50. Array.Resize<string>(ref this.Languages, num);
  51. }
  52. if (this.Flags.Length != num)
  53. {
  54. Array.Resize<byte>(ref this.Flags, num);
  55. }
  56. if (this.Languages_Touch != null)
  57. {
  58. for (int i = 0; i < Mathf.Min(this.Languages_Touch.Length, num); i++)
  59. {
  60. if (string.IsNullOrEmpty(this.Languages[i]) && !string.IsNullOrEmpty(this.Languages_Touch[i]))
  61. {
  62. this.Languages[i] = this.Languages_Touch[i];
  63. this.Languages_Touch[i] = null;
  64. }
  65. }
  66. this.Languages_Touch = null;
  67. }
  68. }
  69. public bool IsTerm(string name, bool allowCategoryMistmatch)
  70. {
  71. if (!allowCategoryMistmatch)
  72. {
  73. return name == this.Term;
  74. }
  75. return name == LanguageSource.GetKeyFromFullTerm(this.Term, false);
  76. }
  77. public bool HasSpecializations()
  78. {
  79. for (int i = 0; i < this.Languages.Length; i++)
  80. {
  81. if (!string.IsNullOrEmpty(this.Languages[i]) && this.Languages[i].Contains("[i2s_"))
  82. {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. public List<string> GetAllSpecializations()
  89. {
  90. List<string> list = new List<string>();
  91. for (int i = 0; i < this.Languages.Length; i++)
  92. {
  93. SpecializationManager.AppendSpecializations(this.Languages[i], list);
  94. }
  95. return list;
  96. }
  97. public string Term = string.Empty;
  98. public eTermType TermType;
  99. public string Description;
  100. public string[] Languages = new string[0];
  101. public byte[] Flags = new byte[0];
  102. [SerializeField]
  103. private string[] Languages_Touch;
  104. }
  105. }