Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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();
         }
     }
 }
Ejemplo n.º 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");
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 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();
         }
     }
 }
Ejemplo n.º 7
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 12
0
 private static DirectoryInfo GetDirectory(string dir)
 {
     return(new DirectoryInfo(LocaleSystem.GetDirectoryString(dir)));
 }
Ejemplo n.º 13
0
 public void Add(string name, string language, string value)
 {
     LocaleSystem.InsertLocale(this.dir, this.groupName, name, language, value);
 }
Ejemplo n.º 14
0
 public void Modify(string name, string language, string value)
 {
     LocaleSystem.ModifyLocale(this.dir, this.groupName, name, language, value);
 }
Ejemplo n.º 15
0
 public bool Exists(string name)
 {
     return(LocaleSystem.ExistLocale(this.dir, this.groupName, name));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 17
0
 public void DeleteOne(string name, string language)
 {
     LocaleSystem.RemoveLocale(this.dir, this.groupName, name, language);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 19
0
        public ITab GetValues(string name)
        {
            List <LocaleElement> list = LocaleSystem.GetLocale(this.dir, this.groupName, name);

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