From 752bdc92af0801579d6c599ba82f58591a63b209 Mon Sep 17 00:00:00 2001 From: sheychen Date: Sat, 10 Dec 2016 16:25:17 +0100 Subject: [PATCH] Creation du projet Ajout de MultiLang --- MyCommon/Class1.cs | 12 ---- MyCommon/Lang.csv | 3 + MyCommon/MultiLang.cs | 102 ++++++++++++++++++++++++++++ MyCommon/MyCommon.csproj | 37 +++++----- MyCommon/Properties/AssemblyInfo.cs | 5 +- 5 files changed, 124 insertions(+), 35 deletions(-) delete mode 100644 MyCommon/Class1.cs create mode 100644 MyCommon/Lang.csv create mode 100644 MyCommon/MultiLang.cs diff --git a/MyCommon/Class1.cs b/MyCommon/Class1.cs deleted file mode 100644 index cd3e6bc..0000000 --- a/MyCommon/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MyCommon -{ - public class Class1 - { - } -} diff --git a/MyCommon/Lang.csv b/MyCommon/Lang.csv new file mode 100644 index 0000000..fd44bc8 --- /dev/null +++ b/MyCommon/Lang.csv @@ -0,0 +1,3 @@ +Key;Francais;English +Hello;Bonjour;Hello +MyName;Mon nom est paul;My name is paul \ No newline at end of file diff --git a/MyCommon/MultiLang.cs b/MyCommon/MultiLang.cs new file mode 100644 index 0000000..8b159b4 --- /dev/null +++ b/MyCommon/MultiLang.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MyCommon +{ + /// + /// Manager MultiLang from .cvs file + /// + public class MultiLang + { + private Dictionary> multiDictionary = new Dictionary>(); //List of phrases by key + private List langs = new List(); //Readable langs list + + public int langsCount { get { return langs.Count; } } + + /// + /// Create Dictionary from string + /// + /// Dictionary text + /// + public void Initialise(string dico) + { + multiDictionary.Clear(); + langs.Clear(); + string[] lines = dico.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); //Load from .cvs ressources. + langs = lines[0].Split(';').OfType().ToList(); + langs.RemoveAt(0); + foreach (string line in lines) + { + List items = line.Split(';').OfType().ToList(); + string key = items[0]; + items.RemoveAt(0); + multiDictionary.Add(key, items); + } + } + + /// + /// Get Language name from ID + /// + public string IDToLang(int lang) + { + if(lang < langs.Count) + { + return langs[lang]; + } + else + { + return "!!!UNKNOW LANG KEY!!!"; + } + } + + /// + /// Get Language ID form name + /// + public bool TryLangToID(string lang, out int ID) + { + for(int i = 0; i < langs.Count; i++) + { + if (lang == langs[i]) + { + ID = i; + return true; + } + } + ID = -1; + return false; + } + + + public List GetWords(string key) + { + if (!multiDictionary.ContainsKey(key)) + return null; + + return multiDictionary[key]; + } + + public string GetWord(string key, int lang) + { + string text = ""; + + if (multiDictionary.ContainsKey(key)) + { + if (multiDictionary[key].Count >= lang) + { + text = multiDictionary[key][lang]; + } + else + { + text = "!!!UNKNOW LANG KEY!!!"; + } + } + else + { + text = "!!!UNKNOW WORD KEY!!!"; + } + + return text; + } + } +} \ No newline at end of file diff --git a/MyCommon/MyCommon.csproj b/MyCommon/MyCommon.csproj index ff40dd0..c99bbf3 100644 --- a/MyCommon/MyCommon.csproj +++ b/MyCommon/MyCommon.csproj @@ -1,16 +1,17 @@ - + Debug AnyCPU - 276ceeb0-800f-4b90-aabc-d1b96dfc548b + {276CEEB0-800F-4B90-AABC-D1B96DFC548B} Library Properties MyCommon MyCommon - v4.5.2 + v4.5 512 + true @@ -30,25 +31,22 @@ 4 - - - - - - - - - - - - - - + + + + + + + + - + + + + - - + \ No newline at end of file diff --git a/MyCommon/Properties/AssemblyInfo.cs b/MyCommon/Properties/AssemblyInfo.cs index 059c7b8..aa01b6c 100644 --- a/MyCommon/Properties/AssemblyInfo.cs +++ b/MyCommon/Properties/AssemblyInfo.cs @@ -1,15 +1,14 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Les informations générales relatives à un assembly dépendent de // l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations // associées à un assembly. [assembly: AssemblyTitle("MyCommon")] +[assembly: AssemblyProduct("MyCommon")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MyCommon")] +[assembly: AssemblyCompany("Sheychen")] [assembly: AssemblyCopyright("Copyright © 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]