static void ReadTable(string tableStr, LocalizationMap map) { using (var csv = new LW.CsvReader(new StringReader(tableStr), true, delimeter)) { int columnsCount = csv.FieldCount; var headers = csv.GetFieldHeaders(); if (!headers.HasFieldNoBox("key", out int keyIndex)) { return; } Dictionary <int, LangCode> validKeys = new Dictionary <int, LangCode>(columnsCount); List <int> validKeysIds = new List <int>(columnsCount); for (int i = 0; i < columnsCount; ++i) { if (i == keyIndex) { continue; } var codeStr = headers[i].ToLower(); if (!LocData.TryParseCode(codeStr, out var code)) { continue; } validKeys[i] = code; validKeysIds.Add(i); } int keysCount = validKeysIds.Count; List <string> fields = new List <string>(columnsCount); while (csv.ReadNextRecord()) { fields.Clear(); for (int i = 0; i < columnsCount; ++i) { fields.Add(csv[i]); } var trans = new Dictionary <LangCode, string>(keysCount); for (int i = 0; i < keysCount; ++i) { int j = validKeysIds[i]; trans.Add(validKeys[j], fields[j]); } map.Add(fields[keyIndex], trans); } } }
static void LoadLang() { LangCode lt; string l = MyPlayerPrefs.GetString(key, null); if (l == null) { var sl = Application.systemLanguage; if (!LocData.TryGetCode(sl, out lt)) { lt = LangCode.en; } } else { if (!LocData.TryParseCode(l, out lt)) { lt = LangCode.en; } } MyPlayerPrefs.SetString(key, lt.ToString()); MyLogger.LogFormat("Localization: {0}", lt); lang = lt; }