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();
         }
     }
 }
Exemple #4
0
        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);
 }
Exemple #10
0
        /// <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);
        }
Exemple #11
0
 /// <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)));
 }
Exemple #13
0
 public void Add(string name, string language, string value)
 {
     LocaleSystem.InsertLocale(this.dir, this.groupName, name, language, value);
 }
Exemple #14
0
 public void Modify(string name, string language, string value)
 {
     LocaleSystem.ModifyLocale(this.dir, this.groupName, name, language, value);
 }
Exemple #15
0
 public bool Exists(string name)
 {
     return(LocaleSystem.ExistLocale(this.dir, this.groupName, name));
 }
Exemple #16
0
 /// <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));
 }
Exemple #17
0
 public void DeleteOne(string name, string language)
 {
     LocaleSystem.RemoveLocale(this.dir, this.groupName, name, language);
 }
Exemple #18
0
 /// <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));
 }
Exemple #19
0
        public ITab GetValues(string name)
        {
            List <LocaleElement> list = LocaleSystem.GetLocale(this.dir, this.groupName, name);

            return(Tab.FromArray(list.ToArray()));
        }
Exemple #20
0
 public void Delete(string name)
 {
     LocaleSystem.RemoveLocale(this.dir, this.groupName, name);
 }
Exemple #21
0
 public void Rename(string oldName, string name)
 {
     LocaleSystem.RenameLocale(this.dir, oldName, this.groupName, name);
 }
Exemple #22
0
 /// <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);
 }
Exemple #23
0
 public bool ExistsOne(string name, string language)
 {
     return(LocaleSystem.ExistLocale(this.dir, this.groupName, name, language));
 }