public static void InsertLocale(string from, string groupName, string name, string language, string value) { if (!LocaleSystem.ExistsGroup(from, groupName)) { LocaleSystem.CreateGroup(from, groupName); } LocaleElement newLe = new LocaleElement(name, language, value); bool done = false; FileInfo fi = new FileInfo(LocaleSystem.GetDirectoryString(from) + groupName + ".tsv"); List <LocaleElement> list = LocaleSystem.GetAll(from, groupName); using (StreamWriter sw = new StreamWriter(fi.Open(FileMode.Truncate, FileAccess.Write, FileShare.Write))) { foreach (LocaleElement le in list) { if (le.Name == name && le.Language == language) { done = true; } le.WriteToFile(sw); } if (!done) { newLe.WriteToFile(sw); } } }
public static bool ExistsGroup(string from, string name) { if (LocaleSystem.ValidateGroupName(name)) { FileInfo fi = new FileInfo(LocaleSystem.GetDirectoryString(from) + name + ".tsv"); return(fi.Exists); } return(false); }
public static void DeleteGroup(string from, string name) { if (LocaleSystem.ValidateGroupName(name)) { FileInfo fi = new FileInfo(LocaleSystem.GetDirectoryString(from) + name + ".tsv"); if (fi.Exists) { fi.Delete(); } } }
public string Get(string name, string language) { LocaleElement elem = LocaleSystem.GetLocale(this.dir, this.groupName, name, language); if (elem != null) { return(elem.Value); } else { throw new Exception("L'objet locale '" + name + "' pour le language '" + language + "' n'existe pas"); } }
public static List <string> GetGroups(string from) { List <string> list = new List <string>(); DirectoryInfo dir = LocaleSystem.GetDirectory(from); if (dir.Exists) { foreach (FileInfo fi in dir.GetFiles("*.tsv")) { list.Add(Path.GetFileNameWithoutExtension(fi.Name)); } } return(list); }
public static void CreateGroup(string from, string name) { if (LocaleSystem.ValidateGroupName(name)) { DirectoryInfo dir = LocaleSystem.GetDirectory(from); if (!dir.Exists) { dir.Create(); } FileInfo fi = new FileInfo(LocaleSystem.GetDirectoryString(from) + name + ".tsv"); if (!fi.Exists) { fi.Create().Close(); } } }
public static void RemoveLocale(string from, string groupName, string name) { if (LocaleSystem.ExistsGroup(from, groupName)) { FileInfo fi = new FileInfo(LocaleSystem.GetDirectoryString(from) + groupName + ".tsv"); List <LocaleElement> list = LocaleSystem.GetAll(from, groupName); using (StreamWriter sw = new StreamWriter(fi.Open(FileMode.Truncate, FileAccess.Write, FileShare.Write))) { foreach (LocaleElement le in list) { if (!(le.Name == name)) { le.WriteToFile(sw); } } } } }
public static List <LocaleElement> GetAll(string from, string groupName) { List <LocaleElement> list = new List <LocaleElement>(); if (LocaleSystem.ExistsGroup(from, groupName)) { FileInfo fi = new FileInfo(LocaleSystem.GetDirectoryString(from) + groupName + ".tsv"); using (StreamReader sr = new StreamReader(fi.Open(FileMode.Open, FileAccess.Read, FileShare.Read))) { int next = 0; while (!sr.EndOfStream) { LocaleElement le = LocaleElement.Parse(sr, ref next); list.Add(le); } } } return(list); }
public static LocaleElement GetLocale(string from, string groupName, string name, string language) { if (LocaleSystem.ExistsGroup(from, groupName)) { FileInfo fi = new FileInfo(LocaleSystem.GetDirectoryString(from) + groupName + ".tsv"); using (StreamReader sr = new StreamReader(fi.Open(FileMode.Open, FileAccess.Read, FileShare.Read))) { int next = 0; while (!sr.EndOfStream) { LocaleElement le = LocaleElement.Parse(sr, ref next); if (le.Name == name && le.Language == language) { return(le); } } } } return(null); }
/// <summary> /// Checks and returns parts /// </summary> /// <param name="text">text to parse</param> /// <param name="groupName">returned group name</param> /// <param name="name">returned locale name</param> /// <returns>true if well-formed</returns> public bool ExtractGroupAndName(string text, out string groupName, out string name) { groupName = ""; name = ""; bool result = false; try { string[] split = text.Split('.'); if (split.Length > 1) { LocaleSystem.ValidateGroupName(split[0]); LocaleElement.ValidateName(String.Join(".", split, 1, split.Length - 1)); groupName = split[0]; name = String.Join(".", split, 1, split.Length - 1); result = true; } } catch { } return(result); }
/// <summary> /// Creates a new locale group /// </summary> /// <param name="name">the group name to create</param> public void Create(string name) { LocaleSystem.CreateGroup(this.directory, name); }
private static DirectoryInfo GetDirectory(string dir) { return(new DirectoryInfo(LocaleSystem.GetDirectoryString(dir))); }
public void Add(string name, string language, string value) { LocaleSystem.InsertLocale(this.dir, this.groupName, name, language, value); }
public void Modify(string name, string language, string value) { LocaleSystem.ModifyLocale(this.dir, this.groupName, name, language, value); }
public bool Exists(string name) { return(LocaleSystem.ExistLocale(this.dir, this.groupName, name)); }
/// <summary> /// Reads the locale group and returns a reference to it /// </summary> /// <param name="name">group name</param> /// <returns>a locale set</returns> public ILocaleSet Get(string name) { return(LocaleSystem.GetSet(this.directory, name)); }
public void DeleteOne(string name, string language) { LocaleSystem.RemoveLocale(this.dir, this.groupName, name, language); }
/// <summary> /// Says if a locale group by name exists /// </summary> /// <param name="name">the group name to search</param> /// <returns>true if exists</returns> public bool Exists(string name) { return(LocaleSystem.ExistsGroup(this.directory, name)); }
public ITab GetValues(string name) { List <LocaleElement> list = LocaleSystem.GetLocale(this.dir, this.groupName, name); return(Tab.FromArray(list.ToArray())); }
public void Delete(string name) { LocaleSystem.RemoveLocale(this.dir, this.groupName, name); }
public void Rename(string oldName, string name) { LocaleSystem.RenameLocale(this.dir, oldName, this.groupName, name); }
/// <summary> /// Suppress an existing locale group /// </summary> /// <param name="name">the group name to suppress</param> public void Remove(string name) { LocaleSystem.DeleteGroup(this.directory, name); }
public bool ExistsOne(string name, string language) { return(LocaleSystem.ExistLocale(this.dir, this.groupName, name, language)); }