#region Header // _,-'/-'/ // . __,-; ,'( '/ // \. `-.__`-._`:_,-._ _ , . `` // `:-._,------' ` _,`--` -: `_ , ` ,' : // `---..__,,--' (C) 2023 ` -'. -' // # Vita-Nex [http://core.vita-nex.com] # // {o)xxx|===============- # -===============|xxx(o} // # # #endregion #region References using System; using System.Collections.Generic; #endregion namespace VitaNex.Text { public class IndependentLanguagePack { private readonly Dictionary _Definitions = new Dictionary(); /// /// Gets the string at the given index, or String.Empty if undefined /// public virtual string this[int index] { get => _Definitions.ContainsKey(index) ? _Definitions[index] ?? String.Empty : String.Empty; set { if (_Definitions.ContainsKey(index)) { _Definitions[index] = value; } else { _Definitions.Add(index, value); } } } /// /// Checks if the given index has a defined entry. /// public bool IsDefined(int index) { return !String.IsNullOrEmpty(this[index]); } /// /// Sets the value of the given index /// public void Define(int index, string value) { this[index] = value; } /// /// Sets the value of the given index /// public string ToString(int index) { return this[index]; } /// /// Gets a formatted message string at the given index using the specified optional parameters to be included during /// formatting /// public string Format(int index, params object[] args) { return String.Format(this[index], args); } } public class LanguagePack { /// /// A table used for overriding cliloc text for each language /// private readonly Dictionary> _TableMutations = new Dictionary> { {ClilocLNG.ENU, new Dictionary()}, {ClilocLNG.DEU, new Dictionary()}, {ClilocLNG.ESP, new Dictionary()}, {ClilocLNG.FRA, new Dictionary()}, {ClilocLNG.JPN, new Dictionary()}, {ClilocLNG.KOR, new Dictionary()}, {ClilocLNG.CHT, new Dictionary()} }; /// /// Default constructor /// public LanguagePack(ClilocLNG lng = ClilocLNG.ENU) { Language = lng; } /// /// Current language used by this instance /// public virtual ClilocLNG Language { get; protected set; } /// /// Gets a cliloc table using this instance' selected language /// protected virtual ClilocTable Table => Clilocs.Tables[Language]; /// /// Gets the string at the given index, or String.Empty if undefined /// public virtual string this[int index] { get => !Table.IsNullOrWhiteSpace(index) ? (_TableMutations[Language].ContainsKey(index) ? _TableMutations[Language][index] : Table[index].Text) : (_TableMutations[Language].ContainsKey(index) ? _TableMutations[Language][index] : String.Empty); set { if (_TableMutations[Language].ContainsKey(index)) { _TableMutations[Language][index] = value; } else { _TableMutations[Language].Add(index, value); } } } /// /// Checks if the given index has a defined entry. /// public bool IsDefined(int index) { return !String.IsNullOrEmpty(this[index]); } /// /// Sets the value of the given index /// public void Define(int index, string value) { this[index] = value; } /// /// Sets the value of the given index /// public string ToString(int index) { return this[index]; } /// /// Gets a formatted message string at the given index using the specified optional parameters to be included during /// formatting /// public string Format(int index, params object[] args) { return String.Format(this[index], args); } } }