示例#1
0
 public MV_R_Label(int id)
 {
     int langID = Utility.CurrLangID;
     using (MVASM_Entities ctx = new MVASM_Entities())
     {
         getLabel_Result label = ctx.getLabel(id, langID).FirstOrDefault();
         if (label != null)
         {
             this.ID = label.ID;
             this.TypeDescriptor = null;
             this.TypeInternal = label.Internal == null ? false : (Boolean)label.Internal;
             this.text = label.Content;
             this.RefName = label.RefName;
         }
     }
 }
示例#2
0
文件: MV_Lang.cs 项目: JCanhoto/MVASM
        /// <summary>
        /// contrutor que seleciona o idioma com base nas configurações do browser do cliente
        /// </summary>
        public MV_Lang()
        {
            if (Utility.AvailableLangs == null)
            {
                // vai buscar à base de dados e guarda na aplicação
                using (MVASM_Entities Ctx = new MVASM_Entities())
                {
                    List<MV_Lang> idiomas = new List<MV_Lang>();
                    var my_langs = Ctx.getAllLangs();
                    foreach (getAllLangs_Result res in my_langs)
                        idiomas.Add(new MV_Lang(res));

                    Utility.AvailableLangs = idiomas;
                }
            }

            HttpRequest Request = HttpContext.Current.Request;
            if (Request.UserLanguages == null)
            {
                // não foi possível obter a opção a partir do browser
                setCurrLang(Consts.defaultLanguageID); // português
            }

            String theLang;
            String userLangs = "";
            try
            {
                foreach (String lang in Request.UserLanguages)
                {
                    theLang = lang;
                    theLang = theLang.Split(';')[0];
                    userLangs += theLang.Substring(0, 2);

                    var findLang = Utility.AvailableLangs.Where(l => l.LanguageCode == theLang).FirstOrDefault();

                    if (findLang == null)
                    {
                        // tenta apenas com o idioma, ignorando o país
                        findLang = Utility.AvailableLangs.Where(l => l.LanguageCode.Substring(0, 2).ToUpper() == theLang.ToUpper().Substring(0, 2)).FirstOrDefault();
                    }

                    if (findLang == null)
                        continue;
                    else
                    {
                        try
                        {
                            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(theLang);
                            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                            MV_Lang temp = findLang as MV_Lang;
                            Utility.CurrLang = findLang as MV_Lang; // encontrou um idioma e guardou em sessão
                            this.Active = temp.Active;
                            this.Flag = temp.Flag;
                            this.ID = temp.ID;
                            this.Language = temp.Language;
                            this.LanguageCode = temp.LanguageCode;
                            break; // encontrou uma que está mais acima nas opções de idioma
                        }
                        catch { ; }
                    }
                }
            }
            catch { ; }

            if (this.ID == 0) // porque não encontrou nenhum idioma igual, ou parecido
            {
                // seleciona um idioma por defeito
                setCurrLang(Consts.defaultLanguageID);
            }
        }