using System; using System.Collections.Generic; using System.Linq; namespace MyCommon { /// /// Manager MultiLang from .cvs file /// public class MultiLang { private Dictionary> multiDictionary = new Dictionary>(); //List of phrases by key private List langs = new List(); //Readable langs list public int langsCount { get { return langs.Count; } } /// /// Create Dictionary from string /// /// Dictionary text /// public void Initialise(string dico) { multiDictionary.Clear(); langs.Clear(); string[] lines = dico.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); //Load from .cvs ressources. langs = lines[0].Split(';').OfType().ToList(); langs.RemoveAt(0); foreach (string line in lines) { List items = line.Split(';').OfType().ToList(); string key = items[0]; items.RemoveAt(0); multiDictionary.Add(key, items); } } /// /// Get Language name from ID /// public string IDToLang(int lang) { if (lang < langs.Count) { return langs[lang]; } else { return "!!!UNKNOW LANG KEY!!!"; } } /// /// Get Language ID form name /// public bool TryLangToID(string lang, out int ID) { for (int i = 0; i < langs.Count; i++) { if (lang == langs[i]) { ID = i; return true; } } ID = -1; return false; } public List GetWords(string key) { if (!multiDictionary.ContainsKey(key)) return null; return multiDictionary[key]; } public string GetWord(string key, int lang) { string text = ""; if (multiDictionary.ContainsKey(key)) { if (multiDictionary[key].Count >= lang) { text = multiDictionary[key][lang]; } else { text = "!!!UNKNOW LANG KEY!!!"; } } else { text = "!!!UNKNOW WORD KEY!!!"; } return text; } } }