Autumn Park QBlog technical principles Analysis: page content filling and multi-language translation process demo (X)

Review article:

 

ps: Autumn Park QBlog Download: http://www.cyqdata.com/download/article-detail-427

 

Recalling the previous section:

On an Autumn Garden QBlog technical principles of analysis: original multi-language translation mechanism (nine)  , we introduce the Autumn Park QBlog multilingual translation mechanism,

Serious liberated coder labor, separation of duties will be translated to the art community.

After a lapse of 10 days herein, this connection to the force, as everyone show you complete filling and page translation.

 

He started working:

 

A: The overall presentation solution:

 

From top to bottom, more or less content than the previous example:

1: database: myspace.mdb, uses a database Autumn Park, which there is also a lot of data.

2: Language.ashx: multi-language processing program used for translation.

3: UrlRewriteEntity: increased static content item, put a SQL table and enumerate

 

OK, what increase is not much, other content is the last example, do not know looking back from it.

 

Two: Multi-language translation

 

1: As an example of the previous section, the disposable bulk translated code:

        private void Translate(XmlHelper doc)
        {
            System.Xml.XmlNodeList list = doc.GetList("*", "key");//获取所有带key标签的节点
            System.Xml.XmlAttribute attr = null;
            if (list != null && list.Count > 0)
            {
                string key = null;
                for (int i = 0; i < list.Count; i++)
                {
                    attr = list[i].Attributes["key"];
                    key = attr.Value;
                    list[i].InnerXml = _Language.Get(key);//翻译
                    list[i].Attributes.Remove(attr);// remove the key attributes
                }
            }
            list = doc.GetList("*", "keyvalue");//获取所有带keyvalue标签的节点
            if (list != null && list.Count > 0)
            {
                string key = null;
                for (int i = 0; i < list.Count; i++)
                {
                    attr = list[i].Attributes["keyvalue"];
                    key = attr.Value;
                    list[i].Attributes["value"].InnerXml = _Language.Get(key);//翻译
                    list[i].Attributes.Remove(attr);//移除keyvalue属性
                }
            }
        }

 

2: HttpCustom business processes, the need to increase the translation of such a line call

        private void Page_PreLoad()
        {
            if (_Document.Load(Context.Server.MapPath("Skin/system_health/index.html")))
            {
                CssAndImg(_Document);
                Translate(_Document);
            }
        }

 

3: URL rewriting, language switching path, to the handler Lanuage.ashx

        public void HttpUrlRewrite(HttpContext context)
        {
            string url = context.Request.Url.ToString();
            if (url.Contains(".css") || url.Contains(".jpg") || url.Contains(".png"))//放到css和jpg图片
            {
                return;
            }
            if (url.Contains("lang"))
            {
                context.RewritePath("~/Language.ashx", null, "url=" + url);
            }
            else
            {
                //--这里要做很多Url逻辑处理
                context.RewritePath("~/Default.ashx", null, "url=" + url);
            }
        }

 

4: Language.ashx to handle it, and then return to the original page

public class Language : HttpCustom
{
    protected override void Page_Load()
    {
        string url = Request["url"];
        string lanKey = url.Substring(url.LastIndexOf('/')+1);
        Language.SetToCookie(lanKey.Substring(0, 1).ToUpper() + lanKey.Substring(1));
        Context.Response.Redirect(Context.Request.UrlReferrer.ToString());

    }
}

 

OK, even if the end of the multi-language processing, preview? Not urgent, such as the contents of the filling together also completed the first bar.

 

Three: page content filling

 

1: create a similar CMS-like syntax conventions

Example:

<ul class="evt_hots_list" name="catelist" id="16" count="8">
      <li><a href=" http://www.cyqdata.com/">省略内容</a></li>
</ul>

Description:

1: catelist, a convention of the label, the name of the category list

2: id, the id is classified.

3: count, that is, how many cycles

4: Li that line, decorative, since it is eventually replaced.

General information: any tag just add catelist + id, can get the output of a classification cycle, as to count the option is available.

 

2: Finishing HTML, according to the agreement put away to show the label classification

E.g:

<ul class="evt_plist" name="catelist" id="12" count="40">
 <!-- 健康·教育 -->
 <li><a target="_blank" title="路过秋天" href="#">教育</a></li>
 </ul>
 <ul class="evt_plist" name="catelist" id="13" count="40">
 <!-- 健康·和谐 -->
  <li><a target="_blank" title="路过秋天" href="#">和谐</a></li>
  </ul>
  <ul class="evt_plist" name="catelist" id="14" count="40">
  <!-- 健康·私语 -->
  <li><a target="_blank" title="路过秋天" href="#">私语</a></li>
   </ul>

So put a few lines of sound, the result is automatically classified id take 12, 13, fills the content of the list.

 

3: Background to write a generic code to handle

OK, now the self-filling function similar CMS also written, programmers easily, art is also easy.

 

Four: F5 final preview to see results

 

1: access, content list appeared

 

2: English translation

 

Only translations translation of the interface, the content is not translated, I would like to translate content? He wrote more than an English article, ha ha!

 

Five: summary

This section as a basis for concluding text of articles, not too many details textual explanation, sample code is intended to provide an overall process for everyone, focusing on the source.

The next section, will continue to the next process, analytical Autumn Park QBlog the Post delivery mechanism.

 

Six: Source download

 

Finally, there is the public looking for the source download.

Download: Autumn Park analytical principle in section X example .rar

 

Reproduced in: https: //my.oschina.net/secyaher/blog/274335

Guess you like

Origin blog.csdn.net/weixin_33794672/article/details/91966771