Autumn Park QBlog technical principles of analysis: original multi-language translation mechanism (IX)

Review article:

 

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

 

Recalling the previous section:

The festival QBlog Autumn Garden resolve technical principles: Web page of the process - filling contents (VIII)  , the analysis of the content of the page html how to be filled, and Set, SetFor, SetForeach small three two how to simplify development.

Look to see everyone's very excited, I write to write very sad

 

This section describes:

Because VII There are unfinished things Module layer, this section will complement VII subsequent multilingual translations.
About VIII example shows code that will leave to the next section commentary.

 

Less gossip, let me see the following:

 

A: multi-language translation of the principle of analytic

 

First Review Section VII : Page_PreLoad part of the process of code:

 

When Section VII, resolved to everyone how to load properly handle html and CSS / image path, this section will complement the principles of multi-language translation of the resolution.

 

1: traditional multi-language translation

I once wrote an article: actual articles - much simpler language implementation , introduced CYQ.Data MutilLanguage under .Xml, in the traditional aspx page, you can achieve multi-language translation as follows:

< p > html: <% = lang.Get( " autumn " %> </ p >

As long as the text to be translated, replaced by the same label syntax, you can obtain the corresponding multilingual effect, which seems to have a lot of people very convenient, but also is widely used with.

 

However, still have a conservative say a few words:

 

1.1: Browse effect destroyed the original interface, modified interface, not secondary use:

Traditional webform development, continue with server-side controls, server syntax, CMS own tag syntax invasion in this site belong to html and legendary art world, the interface after the invasion, no longer belongs to the art-recognized html.

He came out of the MVC, with no ViewState been talked about, but did not change the server html syntax invasion of habit.

There is reasonable, it brings rapid development effect for ASP the .NET brings rapid expansion .... quite quickly.

For this, I have to say is more conservative, I do not think the invasion is not good, because in fact, there are many projects to be quickly developed to violent.

Unless you can bring a more rapid development approach than the invasion of html, otherwise, it can not deny its existence and change.

 

1.2: a page full of a lot of these labels, in addition to the original developer, who took over maintenance, you have to be silly, especially E-wen bad person, like I said:

Who took over a community-based project: dozens of not-source dll, a large number of <% multilingual%> tags in the html mixed, each mode hybrid variety of coding style syntax [linq, lamb grammar, etc.], tortured me a months later, my boss said the development is too slow, took a novice when said novice example of the development progress faster than me, so I left.

 

After fooled everyone above two points, took the point to say Autumn Park QBlog how to deal with:

 

2: Autumn Park QBlog multi-language translation mechanism

 

Autumn Park QBlog is based on the html xml loaded as a way to handle interface, easy operation html as xml like.

In XmlHelper when the help is required to obtain a node or nodes in a batch, it is quite simple.

Ever since, we had the idea and practice of the following methods:

See Example html tags:

<h2 key="healthcare">健康·保健</h2>
<li><a href="/" key="index">首页</a></li>
<input keyvalue="submit" type="submit" name="btnPost" value="提交" class="Button Button_Style" />

Description:

From the above three tabs, to see that very clearly knew what the label is displayed,

It does not affect the original preview of html tags, just like xml-like increase of two custom properties: key, keyvalue.

Two small labels, but we can complete the translation needs of the entire Autumn Park station multi-language, how to do? Let us look at the following introduction:

 

1: Convention translated keywords

Text key = "id", id looking node from the same directory language.html text, the translation of key internal node: key

Text attribute value of key = "id", id looking node from the same directory language.html text translation keyvalue node: keyvalue

 

The above two translation master key, i.e. the label may be placed at any interface html, as exemplified above as html

Incidentally, a few nagging:

This interface is translated live, it should belong to the scope of the management process art community.
What multilingual translation interface, developers do not rushing to Scrapped. Toss a bunch of <% multilingual%>, and everyone looked at all uncomfortable.
No way to endure, now there is a way, and can save some worry the more.

 

However, the developers want to effort and worry, have in the base class, so write down a short code:

 

2: Translation of the implementation 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);//移除key属性
                }
            }
            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属性
                }
            }
        }

 

I believe such a simple code for each spectators are read to understand, not much chatter, and everyone looked to the force on the line.

 

And then on the two Autumn Park QBlog of charge to the point of view of the spectacle Logo:

When Chinese:

E When text:

 

to sum up:

In this section, the analysis of the Autumn Garden QBlog multi-language translation mechanism: the use of labels by acquiring all of the nodes of the agreement, a replacement cycle, which once solved the whole station translation problems.

At the same time, creating a new method, the developer placed in the body for many years mechanical-type translation work, a one-time liberation gave art community personnel, and to achieve a relatively progressive isolation of certain duties.

 

The next section, everyone will complete example demonstrates VIII, while adding translated content in this section include multiple languages, so stay tuned.

 

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

Guess you like

Origin blog.csdn.net/weixin_33984032/article/details/91966983