Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            WLocale tgt = (WLocale)target;

            _languages.Build(new Menu <LangModel> .BuildCallback(
                                 "Languages",
                                 tgt.languages,
                                 l => l.title,
                                 s => {
                _selectedLanguage = s.Model;
                TextAsset t       = Resources.Load <TextAsset>(Path.Combine(tgt.path, $"locale_{_selectedLanguage.id}"));
                if (null == t)
                {
                    _selectedLocale = new LocaleModel(_selectedLanguage.id);
                }
                else
                {
                    _selectedLocale = JsonUtility.FromJson <LocaleModel>(t.text);
                }
            }
                                 ));

            if (null != _selectedLocale)
            {
                EditorGUILayout.LabelField(_selectedLocale.lang, EditorStyles.boldLabel);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取多语言信息
        /// </summary>
        /// <param name="langId">多语言Id</param>
        /// <param name="langAlias">别名</param>
        /// <returns>Lang,LangSln</returns>
        public static SubLang GetTipLang(Int64 langId, string langAlias = "")
        {
            var lang = new SubLang()
            {
                LangId    = langId,
                Lang      = string.Empty,
                LangSln   = string.Empty,
                LangAlias = langAlias
            };

            if (!_dicLangs.ContainsKey(langId))
            {
                if (_dtUseLang == null) //获取启用语言包
                {
                    _dtUseLang = DbHelper.GetDataTable("select * from ng3_use_lang");
                }

                DataTable dt;

                if (_dtUseLang.Rows.Count == 0) //没有语言包则只读取中文和英文
                {
                    dt =
                        DbHelper.GetDataTable(
                            "select phid,isuse,standard_lang,standard_lang_sln,zh_lang,zh_lang_sln,en_lang,en_lang_sln from ng3_lang where phid = " +
                            langId);
                }
                else
                {
                    //存在配置的语言包则读取中文、英文和其他语言包
                    var fields = _dtUseLang.Rows.Cast <DataRow>().Aggregate(string.Empty,
                                                                            (current, row) => current + string.Format("," + "lang{0},lang{0}_sln", row["phid"]));

                    dt =
                        DbHelper.GetDataTable(string.Format(
                                                  "select phid,isuse,standard_lang,standard_lang_sln,zh_lang,zh_lang_sln,en_lang,en_lang_sln,{0} from ng3_lang where phid = {1}",
                                                  fields.Substring(1), langId));
                }

                if (dt.Rows.Count == 1)
                {
                    //存在数据,则将此数据添加静态变量中
                    var model = new LangModel
                    {
                        PhId            = Convert.ToInt64(dt.Rows[0]["phid"]),
                        StandardLang    = dt.Rows[0]["standard_lang"].ToString(),
                        StandardLangSln = dt.Rows[0]["standard_lang_sln"].ToString(),
                        ZhLang          = dt.Rows[0]["zh_lang"].ToString(),
                        ZhLangSln       = dt.Rows[0]["zh_lang_sln"].ToString(),
                        EnLang          = dt.Rows[0]["en_lang"].ToString(),
                        EnLangSln       = dt.Rows[0]["en_lang_sln"].ToString(),
                    };

                    var dic = new Dictionary <string, string>();
                    foreach (DataRow row in _dtUseLang.Rows)
                    {
                        var field = "lang" + row["phid"];
                        var clang = dt.Rows[0][field].ToString();
                        dic.Add(field, string.IsNullOrWhiteSpace(clang) ? model.StandardLang : clang);

                        field += "_sln";
                        clang  = dt.Rows[0][field].ToString();
                        dic.Add(field, string.IsNullOrWhiteSpace(clang) ? model.StandardLangSln : clang);
                    }

                    model.DicLangs = dic;

                    _dicLangs.Add(langId, model);

                    if (Convert.ToInt16(dt.Rows[0]["isuse"]) == 0)
                    {
                        DbHelper.Open();
                        DbHelper.ExecuteNonQuery("update ng3_lang set isuse = 1 where phid =" + langId);
                        DbHelper.Close();
                    }
                }
            }

            var langModel = _dicLangs[langId];

            if (langModel == null)
            {
                langModel = new LangModel {
                    PhId = langId
                };
            }

            if (langModel.UseCount < Int64.MaxValue - 1)
            {
                langModel.UseCount++;
            }
            else
            {
                langModel.UseCount = 0;
            }

            if (_lang == "zh-CN") //中文
            {
                lang.Lang    = string.IsNullOrWhiteSpace(langModel.ZhLang) ? langModel.StandardLang : langModel.ZhLang;
                lang.LangSln = string.IsNullOrWhiteSpace(langModel.ZhLangSln)
                    ? langModel.StandardLangSln
                    : langModel.ZhLangSln;
            }
            else if (_lang == "en-US") //英文
            {
                lang.Lang    = string.IsNullOrWhiteSpace(langModel.EnLang) ? langModel.StandardLang : langModel.EnLang;
                lang.LangSln = string.IsNullOrWhiteSpace(langModel.EnLangSln)
                    ? langModel.StandardLangSln
                    : langModel.EnLangSln;
            }
            else
            {
                var rows = _dtUseLang.Select(string.Format("lang_key = '{0}'", _lang));

                if (rows.Length > 0)
                {
                    var field = "lang" + rows[0]["phid"];
                    lang.Lang = string.IsNullOrWhiteSpace(langModel.DicLangs[field])
                        ? langModel.StandardLang
                        : langModel.DicLangs[field];
                    ;
                    lang.LangSln = string.IsNullOrWhiteSpace(langModel.DicLangs[field + "_sln"])
                        ? langModel.StandardLangSln
                        : langModel.DicLangs[field + "_sln"];
                    ;
                }
            }

            return(lang);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取多语言信息
        /// </summary>
        /// <param name="busiType">ui元素业务类型</param>
        /// <returns>Lang,LangSln</returns>
        public static Dictionary <string, string> GetLabelLangWithConn(string language, string conn, string busiType)
        {
            var dicLabel = new Dictionary <string, string>();

            if (!_dicUILabels.ContainsKey(busiType))
            {
                if (_dtUseLang == null) //获取启用语言包
                {
                    _dtUseLang = DbHelper.GetDataTable(conn, "select * from ng3_use_lang");
                }

                var fields = _dtUseLang.Rows.Cast <DataRow>().Aggregate(string.Empty,
                                                                        (current, row) => current + string.Format("," + "lang{0}", row["phid"]));

                string test = string.Format(@"SELECT ng3_ui_lable.ui_identify, lang_alias, ng3_lang.phid, isuse, standard_lang, zh_lang, en_lang {0} 
                                FROM ng3_lang LEFT OUTER JOIN ng3_ui_lable ON ng3_lang.phid = ng3_ui_lable.lang_phid 
                                WHERE ui_identify = '{1}'", fields, busiType);

                var dtLang = DbHelper.GetDataTable(conn,
                                                   string.Format(@"SELECT ng3_ui_lable.ui_identify, lang_alias, ng3_lang.phid, isuse, standard_lang, zh_lang, en_lang {0} 
                                FROM ng3_lang LEFT OUTER JOIN ng3_ui_lable ON ng3_lang.phid = ng3_ui_lable.lang_phid 
                                WHERE ui_identify = '{1}'", fields, busiType));

                if (dtLang == null || dtLang.Rows.Count == 0)
                {
                    _dicUILabels.Add(busiType, new List <string>());
                    return(new Dictionary <string, string>());
                }
                var langAlias = new List <string>();
                foreach (DataRow dr in dtLang.Rows)
                {
                    var alias  = dr["lang_alias"].ToString();
                    var langId = Convert.ToInt64(dr["phid"]);
                    langAlias.Add(alias + "$" + langId);

                    if (_dicLangs.ContainsKey(langId))
                    {
                        continue;
                    }

                    //存在数据,则将此数据添加静态变量中
                    var model = new LangModel
                    {
                        PhId         = langId,
                        StandardLang = dr["standard_lang"].ToString(),
                        ZhLang       = dr["zh_lang"].ToString(),
                        EnLang       = dr["en_lang"].ToString(),
                        LangAlias    = alias,
                    };

                    var dic = new Dictionary <string, string>();
                    foreach (DataRow row in _dtUseLang.Rows)
                    {
                        var field = "lang" + row["phid"];
                        var clang = dr[field].ToString();
                        dic.Add(field, string.IsNullOrWhiteSpace(clang) ? model.StandardLang : clang);
                    }

                    model.DicLangs = dic;

                    _dicLangs.Add(langId, model);

                    if (Convert.ToInt16(dr["isuse"]) == 0)
                    {
                        DbHelper.Open(conn);
                        DbHelper.ExecuteNonQuery(conn, "update ng3_lang set isuse = 1 where phid =" + dr["phid"]);
                        DbHelper.Close(conn);
                    }
                }

                _dicUILabels.Add(busiType, langAlias);
            }

            var lblLangs = _dicUILabels[busiType];

            if (lblLangs == null)
            {
                lblLangs = new List <string>();
            }

            if (language == "zh-CN" || language == "en-US") //中文或者英文
            {
                foreach (var id in lblLangs)
                {
                    var aliasAndId = id.Split('$');
                    var alias      = aliasAndId[0];
                    var langId     = Convert.ToInt64(aliasAndId[1]);

                    var item = _dicLangs[langId];
                    if (item == null)
                    {
                        continue;
                    }

                    if (item.UseCount < Int64.MaxValue - 1)
                    {
                        item.UseCount++;
                    }
                    else
                    {
                        item.UseCount = 1;
                    }

                    if (language == "zh-CN")
                    {
                        if (!string.IsNullOrWhiteSpace(item.ZhLang))
                        {
                            dicLabel.Add(alias, item.ZhLang);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(item.EnLang))
                        {
                            dicLabel.Add(alias, item.EnLang);
                        }
                    }
                }
            }
            else
            {
                var rows = _dtUseLang.Select(string.Format("lang_key = '{0}'", language));

                if (rows.Length > 0)
                {
                    var field = "lang" + rows[0]["phid"];
                    foreach (var id in lblLangs)
                    {
                        var aliasAndId = id.Split('$');
                        var alias      = aliasAndId[0];
                        var langId     = Convert.ToInt64(aliasAndId[1]);

                        var item = _dicLangs[langId];
                        if (item == null)
                        {
                            continue;
                        }

                        if (item.UseCount < Int64.MaxValue - 1)
                        {
                            item.UseCount++;
                        }
                        else
                        {
                            item.UseCount = 1;
                        }

                        if (!string.IsNullOrWhiteSpace(item.DicLangs[field]))
                        {
                            dicLabel.Add(alias, item.DicLangs[field]);
                        }
                    }
                }
            }

            return(dicLabel);
        }