コード例 #1
0
        private void loadDefData2()
        {
            pageidx    = MakRequest.GetInt("page", 1);
            datalimit  = MakRequest.GetInt("limit", 20);
            lang_src   = MakRequest.GetString("lang1");
            lang_dst   = MakRequest.GetString("lang2");
            includeSys = MakRequest.GetInt("isys", 0) == 1;

            filterstar = Utils.StrToInt(MakRequest.GetString("filter_s"), 0);
            filterkw   = MakRequest.GetString("filter_k");

            if (!I18N.alllang.Contains(lang_dst))
            {
                lang_dst = "en-us";
            }
            I18N idst = new I18N(lang_dst);
            //过滤
            List <I18N.LangItem> filteredData = new List <I18N.LangItem>();

            foreach (var item in idst.lanStrs)
            {
                I18N.LangItem li       = item.Value;
                bool          isSyskey = I18N.sysKey.Contains(li.Key);
                if (includeSys || !isSyskey)
                {
                    AllRecordCount++;
                    s1_5[li.Score - 1]++;
                    if (filterstar == 0 || filterstar == li.Score)
                    {
                        if (string.IsNullOrEmpty(filterkw) || li.Key.IndexOf(filterkw) > -1 || li.Text.IndexOf(filterkw) > -1)
                        {
                            filteredData.Add(li);
                        }
                    }
                }
            }
            //分页
            List <lstItemModel> ll = new List <lstItemModel>();
            int pageStartIdx       = (pageidx - 1) * datalimit;

            for (int i = pageStartIdx; i < Math.Min(filteredData.Count, pageStartIdx + datalimit); i++)
            {
                I18N.LangItem item = filteredData[i];
                lstItemModel  llm  = new lstItemModel();
                ll.Add(llm);
                llm.isSyskey = I18N.sysKey.Contains(item.Key);
                llm.Original = item.Key;
                llm.lang1    = item.Key;
                llm.lang2    = item.Text;
                llm.Score    = item.Score;
            }
            RecordCount = filteredData.Count;

            if ("o".Equals(lang_src))
            {
                //lang_src = LI("原始字符串");
            }
            else
            {
                if (!I18N.alllang.Contains(lang_src))
                {
                    lang_src = "zh-cn";
                }
                I18N i18 = new I18N(lang_src);
                foreach (var item in ll)
                {
                    if (!item.isSyskey)
                    {
                        item.lang1 = i18.I(item.Original);
                    }
                }
            }
            rptList.DataSource = ll;
            rptList.DataBind();

            baseurl = Request.Path + "?lang1=" + lang_src + "&lang2=" + lang_dst;
            if (includeSys)
            {
                baseurl += "&isys=1";
            }
            if (datalimit != 20)
            {
                baseurl += "&limit=" + datalimit.ToString();
            }
        }
コード例 #2
0
        private void loadDefData()
        {
            pageidx    = MakRequest.GetInt("page", 1);
            datalimit  = MakRequest.GetInt("limit", 20);
            lang_src   = MakRequest.GetString("lang1");
            lang_dst   = MakRequest.GetString("lang2");
            includeSys = MakRequest.GetInt("isys", 0) == 1;

            if (string.IsNullOrEmpty(lang_dst) || !File.Exists(HttpContext.Current.Server.MapPath("/i18n/" + lang_dst + ".xml")))
            {
                lang_dst = "en-us";
            }
            List <lstItemModel> ll = new List <lstItemModel>();


            XmlDocument xml_src = new XmlDocument();

            xml_src.Load(HttpContext.Current.Server.MapPath("/i18n/" + lang_dst + ".xml"));
            XmlNode root = xml_src.SelectSingleNode("i18n");

            RecordCount = root.ChildNodes.Count;
            if (!includeSys)
            {
                RecordCount = RecordCount - I18N.sysKey.Count;
            }
            foreach (XmlNode item in root.ChildNodes)
            {
                if (item.Name == "a" && item.Attributes["key"] != null)
                {
                    string key      = item.Attributes["key"].Value;
                    bool   isSyskey = I18N.sysKey.Exists(aa => aa == key);
                    if (includeSys || !isSyskey)
                    {
                        int scr = item.Attributes["score"] == null ? 5 : Utils.StrToInt(item.Attributes["score"].Value, 5);
                        if (scr > 5)
                        {
                            scr = 5;
                        }
                        else if (scr < 1)
                        {
                            scr = 1;
                        }
                        s1_5[scr - 1]++;
                    }
                }
            }

            int startIdx = (pageidx - 1) * datalimit;

            while (startIdx < root.ChildNodes.Count)
            {
                XmlNode a = root.ChildNodes[startIdx++];
                if (a.Name == "a" && a.Attributes["key"] != null)
                {
                    string key      = a.Attributes["key"].Value;
                    bool   isSyskey = I18N.sysKey.Exists(aa => aa == key);
                    if (includeSys || !isSyskey)
                    {
                        lstItemModel llm = new lstItemModel();
                        ll.Add(llm);
                        llm.isSyskey = isSyskey;
                        llm.Original = key;
                        llm.lang1    = key;
                        llm.lang2    = a.Attributes["text"].Value;
                        if (string.IsNullOrEmpty(llm.lang2))
                        {
                            llm.Score = 1;
                        }
                        else
                        {
                            llm.Score = a.Attributes["score"] == null ? 5 : Utils.StrToInt(a.Attributes["score"].Value, 5);
                        }
                        if (ll.Count >= datalimit)
                        {
                            break;
                        }
                    }
                }
            }
            if ("o".Equals(lang_src))
            {
                //lang_src = LI("原始字符串");
            }
            else
            {
                if (string.IsNullOrEmpty(lang_src) || !File.Exists(HttpContext.Current.Server.MapPath("/i18n/" + lang_src + ".xml")))
                {
                    lang_src = "zh-cn";
                }
                I18N i18 = new I18N(lang_src);
                foreach (var item in ll)
                {
                    if (!item.isSyskey)
                    {
                        item.lang1 = i18.I(item.Original);
                    }
                }
            }
            rptList.DataSource = ll;
            rptList.DataBind();
        }