internal static Dictionary <string, string> LoadLocalizationText(TextReader reader, Dictionary <string, string> dict, bool overwrite = false, string default_namespace = null) { StringTableManager.StringCollection last_coll = null; string last_id = null; LoadLocalizationTextGeneral(reader, (id) => dict.ContainsKey(id), (id, coll) => { if (last_coll != null) { var str = last_coll.GetExactString(0); if (last_coll.Count() > 1) { Logger.Warn($"Randomized localizations are not supported by DF localization. Only the first option ('{str}') will be used."); } dict[last_id] = str; } last_id = id; last_coll = coll; }, overwrite, default_namespace); if (last_id != null) { dict[last_id] = last_coll.GetExactString(0); if (last_coll.Count() > 1) { Logger.Warn($"Randomized localizations are not supported by DF localization. Only the first option ('{dict[last_id]}') will be used."); } } return(dict); }
/// <summary> /// Sets a string with the key of <paramref name="key"/> in the table. /// </summary> /// <param name="key">The string's key.</param> /// <param name="value">The string value.</param> public void SetValue(string key, StringTableManager.StringCollection value) { Table[key] = value; _changes[key] = value; JournalEntry.ReloadDataSemaphore++; TranslationManager.ForceUpdateTranslation(); }
private static Dictionary <string, StringTableManager.StringCollection> LoadEnemiesTable(string subDirectory) { TextAsset textAsset = (TextAsset)BraveResources.Load("strings/" + subDirectory + "/enemies", typeof(TextAsset), ".txt"); if (textAsset == null) { Debug.LogError("Failed to load string table: ENEMIES."); return(null); } StringReader stringReader = new StringReader(textAsset.text); Dictionary <string, StringTableManager.StringCollection> dictionary = new Dictionary <string, StringTableManager.StringCollection>(); StringTableManager.StringCollection stringCollection = null; string text; while ((text = stringReader.ReadLine()) != null) { if (!text.StartsWith("//")) { if (text.StartsWith("#")) { stringCollection = new StringTableManager.ComplexStringCollection(); if (dictionary.ContainsKey(text)) { Debug.LogError("Failed to add duplicate key to items table: " + text); } else { dictionary.Add(text, stringCollection); } } else { string[] array = text.Split(new char[] { '|' }); if (array.Length == 1) { stringCollection.AddString(array[0], 1f); } else { stringCollection.AddString(array[1], float.Parse(array[0])); } } } } return(dictionary); }
internal static void LoadLocalizationTextGeneral(TextReader reader, Func <string, bool> dupe_check, Action <string, StringTableManager.StringCollection> assign_action, bool overwrite = false, string default_namespace = null) { // mostly based on copied StringTableManager code // all the files have duplicate loading code but it all seems to be doing // the same thing /shrug StringTableManager.StringCollection coll = null; string text; while ((text = reader.ReadLine()) != null) { if (!text.StartsWithInvariant("//")) { if (text.StartsWithInvariant("#")) { coll = new StringTableManager.ComplexStringCollection(); if (default_namespace != null) { var id = text.Substring(1); if (id.Count(':') > 1) { Logger.Error($"Failed to add invalid key to table: {id}"); continue; } if (!id.Contains(":")) { id = $"{default_namespace}:{id}"; } if (id.StartsWithInvariant("gungeon:")) { text = $"#{id.Substring("gungeon:".Length)}"; } else { text = $"#{id}"; } } if (dupe_check.Invoke(text) && !overwrite) { Logger.Error($"Failed to add duplicate key to table: {text}"); } else { assign_action.Invoke(text, coll); } } else { if (coll == null) { continue; } // ignore the KEY,EN stuff on ui.txt // we don't need it anyway because we have our own ID system string[] array = text.Split(new char[] { '|' }); if (array.Length == 1) { coll.AddString(array[0], 1f); } else { coll.AddString(array[1], float.Parse(array[0])); } } } } }
private static void TableSetValueHook(Action <StringDBTable, string, StringTableManager.StringCollection> orig, StringDBTable self, string key, StringTableManager.StringCollection value) { orig(self, key, value); ForceUpdateTranslation(); }