private static Dictionary <string, LocalisationEntry> LoadLocalisationFile(string file) { var workspaceRoot = Workspace.Instance.ProjectRoot; var workspaceFolder = Path.GetDirectoryName(workspaceRoot); var localisationFile = Path.Combine(workspaceFolder, "Localisation", "en", file + ".xml"); if (!File.Exists(localisationFile)) { return(new Dictionary <string, LocalisationEntry>()); } var contents = XDocument.Load(localisationFile); var output = new Dictionary <string, LocalisationEntry>(); foreach (var el in contents.Root.Elements()) { var id = el.Attribute("ID").Value; var context = el.Attribute("Context")?.Value ?? ""; var text = el.Value; var entry = new LocalisationEntry(); entry.ID = id; entry.Context = context; entry.Text = text; output[id] = entry; } return(output); }
public static void StoreLocalisation(string file, string id, string text, string context) { var contents = LoadLocalisationFile(file); LocalisationEntry entry; if (!contents.TryGetValue(id, out entry)) { entry = new LocalisationEntry(); contents[id] = entry; } entry.Text = text; entry.Context = context; SaveLocalisationFile(file, contents); }