Ejemplo n.º 1
0
 public static string GetString(string identifier)
 {
     if (!_inited)
     {
         Init();
     }
     try
     {
         return(Res[identifier]);
     }
     catch (KeyNotFoundException)
     {
         Logger.LogErrorToFile("No Translation for token " + identifier);
         if (CultureCode != "en")
         {
             var eng   = TranslationSets.FirstOrDefault(p => p.CultureCode == "en");
             var token = eng?.Translation.FirstOrDefault(p => p.Token == identifier);
             if (token == null)
             {
                 return(identifier);
             }
             Res.Add(identifier, token.Value);
             return(Res[identifier]);
         }
     }
     catch
     {
         //possible threading error where language is reset
     }
     return(identifier);
 }
Ejemplo n.º 2
0
        public static void SetString(Control ctrl, string identifier)
        {
            if (!_inited)
            {
                Init();
            }

            try
            {
                ctrl.Text = Res[identifier];
            }
            catch (KeyNotFoundException)
            {
                ctrl.Text = identifier;
                Logger.LogErrorToFile("No Translation for token " + identifier);
                if (CultureCode != "en")
                {
                    var eng   = TranslationSets.FirstOrDefault(p => p.CultureCode == "en");
                    var token = eng?.Translation.FirstOrDefault(p => p.Token == identifier);
                    if (token != null)
                    {
                        Res.Add(identifier, token.Value);
                        ctrl.Text = Res[identifier];
                    }
                }
            }
            catch
            {
                //possible threading error where language is reset
            }
        }
Ejemplo n.º 3
0
        public static string GetString(string Identifier)
        {
            string _lang = iSpyServer.Default.Language;

            if (_lang == "NotSet")
            {
                _lang = System.Globalization.CultureInfo.CurrentCulture.Name.Split('-')[0];
                if (TranslationSets.FirstOrDefault(p => p.CultureCode == _lang) != null)
                {
                    iSpyServer.Default.Language = _lang;
                }
                else
                {
                    iSpyServer.Default.Language = _lang = "en";
                }
            }

            TranslationsTranslationSetTranslation _t = TranslationSets.First(p => p.CultureCode == _lang).Translation.FirstOrDefault(p => p.Token == Identifier);

            if (_t != null)
            {
                return(_t.Value);//.Replace("&amp;", "&").Replace(@"\n", Environment.NewLine).Replace("&lt;", "<").Replace("&gt;", ">");
            }
            return("!" + Identifier + "!");
        }
Ejemplo n.º 4
0
        public static void SetString(ToolStripStatusLabel ctrl, string identifier)
        {
            if (!_inited)
            {
                Init();
            }

            try
            {
                ctrl.Text = Res[identifier];
            }
            catch (KeyNotFoundException)
            {
                MainForm.LogErrorToFile("No Translation for token " + identifier);
                ctrl.Text = identifier;
                if (CultureCode != "en")
                {
                    var eng = TranslationSets.FirstOrDefault(p => p.CultureCode == "en");
                    if (eng != null)
                    {
                        var token = eng.Translation.FirstOrDefault(p => p.Token == identifier);
                        if (token != null)
                        {
                            Res.Add(identifier, token.Value);
                            ctrl.Text = Res[identifier];
                        }
                    }
                }
            }
            catch
            {
                //possible threading error where language is reset
            }
            //dont modify design time text
        }
Ejemplo n.º 5
0
        private static void Init()
        {
            if (MainForm.Conf.Language == "NotSet")
            {
                MainForm.Conf.Language = CultureInfo.CurrentCulture.Name.ToLower().Split('-')[0];
                var ts = TranslationSets.FirstOrDefault(p => p.CultureCode == MainForm.Conf.Language);
                if (ts == null)
                {
                    MainForm.Conf.Language = "en";
                }
            }

            Res.Clear();

            foreach (var ls in TranslationSets)
            {
                foreach (var t in ls.Translation)
                {
                    try
                    {
                        Res.Add((ls.CultureCode + "." + t.Token.ToLower()), t.Value);
                    }
                    catch (Exception ex)
                    {
                        //ignore duplicates
                    }
                }
            }
            _inited = true;
        }
Ejemplo n.º 6
0
        private static void Init()
        {
            string lang = MainForm.Conf.Language;

            if (lang == "NotSet")
            {
                lang = CultureInfo.CurrentCulture.Name.ToLower();
                string lang1 = lang;
                if (TranslationSets.FirstOrDefault(p => p.CultureCode == lang1) != null)
                {
                    MainForm.Conf.Language = lang;
                }
                else
                {
                    lang = lang.Split('-')[0];
                    string lang2 = lang;
                    if (TranslationSets.FirstOrDefault(p => p.CultureCode == lang2) != null)
                    {
                        MainForm.Conf.Language = lang;
                    }
                    else
                    {
                        MainForm.Conf.Language = lang = "en";
                    }
                }
            }

            Res.Clear();
            _currentSet = TranslationSets.FirstOrDefault(p => p.CultureCode == lang);
            if (_currentSet != null)
            {
                foreach (TranslationsTranslationSetTranslation tran in _currentSet.Translation)
                {
                    try
                    {
                        Res.Add(tran.Token,
                                tran.Value.Replace("&amp;", "&")
                                .Replace("&lt;", "<")
                                .Replace("&gt;", ">")
                                .Replace(",", ",")
                                .Replace("#39;", "'"));
                    }
                    catch (Exception ex)
                    {
                        Logger.LogErrorToFile("Translation: " + tran.Token + ": " + ex.Message);
                    }
                }
            }

            _inited = true;
        }
Ejemplo n.º 7
0
        public static string GetString(string identifier)
        {
            string lang = MainForm.Conf.Language;

            if (lang == "NotSet")
            {
                lang = CultureInfo.CurrentCulture.Name.ToLower();
                string lang1 = lang;
                if (TranslationSets.FirstOrDefault(p => p.CultureCode == lang1) != null)
                {
                    MainForm.Conf.Language = lang;
                }
                else
                {
                    lang = lang.Split('-')[0];
                    string lang2 = lang;
                    if (TranslationSets.FirstOrDefault(p => p.CultureCode == lang2) != null)
                    {
                        MainForm.Conf.Language = lang;
                    }
                    else
                    {
                        MainForm.Conf.Language = lang = "en";
                    }
                }
            }


            if (CurrentSet == null)
            {
                Res.Clear();
                CurrentSet = TranslationSets.FirstOrDefault(p => p.CultureCode == lang);
                if (CurrentSet != null)
                {
                    foreach (TranslationsTranslationSetTranslation tran in CurrentSet.Translation)
                    {
                        Res.Add(tran.Token, tran.Value.Replace("&amp;", "&").Replace("&lt;", "<").Replace("&gt;", ">").Replace(",", ","));
                    }
                }
            }
            try
            {
                return(Res[identifier]);
            }
            catch
            {
                //possible threading error where language is reset
            }
            return("!" + identifier + "!");
        }