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 LocaleElement Parse(StreamReader sr, ref int next) { string name = LocaleElement.IdentifyWord(sr, ref next, false); string language = LocaleElement.IdentifyWord(sr, ref next, false); string value = LocaleElement.IdentifyWord(sr, ref next, true); return(new LocaleElement(name, language, value)); }
public LocaleElement(string name, string language, string value) { if (LocaleElement.ValidateName(name) && LocaleElement.ValidateLanguage(language)) { this.Name = name; this.Language = language; this.Value = value; } }
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 <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); }