using System.Collections.Generic; namespace PKHeX.Core { /// /// String Translation Utility /// public static class RibbonStrings { private static readonly Dictionary RibbonNames = new(); /// /// Resets the Ribbon Dictionary to use the supplied set of Ribbon (Property) Names. /// /// Array of strings that are tab separated with Property Name, \t, and Display Name. public static void ResetDictionary(IEnumerable lines) { // Don't clear existing keys on reset; only update. // A language will have the same keys (hopefully), only with differing values. foreach (var line in lines) { var index = line.IndexOf('\t'); if (index < 0) continue; var name = line.Substring(0, index); var text = line.Substring(index + 1); RibbonNames[name] = text; } } /// /// Returns the Ribbon Display Name for the corresponding ribbon property name. /// /// Ribbon property name /// Ribbon display name public static string GetName(string propertyName) { // Throw an exception with the requested property name as the message, rather than an ambiguous "key not present" message. // We should ALWAYS have the key present as the input arguments are not user-defined, rather, they are from PKM property names. if (!RibbonNames.TryGetValue(propertyName, out string value)) throw new KeyNotFoundException(propertyName); return value; } } }