Summary of the invention
For solving the deficiency that adopts human translation among the present GUI between the different language, the present invention provides a kind of method that realizes automatic language translation in the graphic user interface, directly from the backstage of graphical interface program target language is replaced source language.
Technical scheme of the present invention is: a kind of method that realizes automatic language translation in the graphic user interface; With spoken and written languages in the described graphic user interface as source language text; Replace to a kind of target language literal that is different from source language text in addition, translation process may further comprise the steps automatically:
The step of the copy of the file in steps A, the generation graphical user interface program in the language catalogue;
Step B, obtain the id value and the step of source language text accordingly in the file of a plurality of id values of the html page that writes down in the duplicate of the document in the language catalogue in the graphical user interface program and corresponding spoken and written languages;
Step C, retrieval source language obtain the target language literal of source language text correspondence to the correspondence table of target language;
Step D, the target language literal replaced the step of the corresponding spoken and written languages of a plurality of id values of the html page that write down in the duplicate of the document in the language catalogue in the graphical user interface program;
Step e, preserve the duplicate of the document file in the language catalogue in the graphical user interface program, and the catalogue file name is modified as the step of the filename of target language by regulation.
Further, in the above-mentioned realization graphic user interface in the method for automatic language translation: described graphic user interface source program is that Javascript writes.The a plurality of id values of the html page of described record are that suffix is the file of js with the file of corresponding spoken and written languages.Described source language is the excel form to the correspondence table of target language.
The present invention provides a kind of method that realizes automatic language translation in the graphic user interface, through this method, can translate automatically the literal among the GUI.
Below in conjunction with specific embodiment the present invention is done comparatively detailed description.
Embodiment
Embodiment 1, and current have the GUI page of a product only to realize Chinese, English bilingual, because the market demand; Will be with this product promotion market of going abroad; Therefore to realize 20 multilinguals again, and consider, be on the basis of the original page, realize efficiently multilingual.At present, the multilingual basic realization of page architecture is every kind of corresponding catalogue of language; Be the js file under the catalogue, what write down in the js file is a plurality of id values of the html page and corresponding spoken and written languages, the js file under the corresponding corresponding language catalogue of a kind of language of each page; So implement; To realize exactly how the spoken and written languages in the js file under each catalogue being replaced to other language, and the id value is constant, just can on the basis of the original page, realize multilingual.And developing instrument is realized the process of this replacement, is to realize with the JS language, on the IE browser, carries out.
Javascript and Jscript are called for short JS, are most popular page script language on the Internet, and it is the necessary a kind of technology of website front end exploitation.JS mainly does the interface, is used for client execution script exploitation on the browser end just, and JS is short and pithy, and it is again specially for making a kind of simple programming language that the Web webpage is made to measure simultaneously.
The language location mode is as the form of " id: value ", and " id " attribute of element can play the effect that is positioned at page appropriate section display text among " id " corresponding html, and " value " is exactly concrete spoken and written languages.Give an example, if we will generate the language of German, the method that relatively is fit to is exactly, and the language catalogue copy portion that en_us is English is come, and then " value " literal in each file wherein replaced with corresponding German translation, and " id " is constant.The process of this whole replacement is exactly that the multilingual translation instrument will be realized so.
In addition, we also have a excel table of depositing various interpretive languages, and every replacement one " value " will be arrived the translation of searching corresponding language in this part excel table, replacement then.
As shown in Figure 1, may further comprise the steps of present embodiment:
1, original en_us English-language catalogue copy is a, the language that RNTO is new;
2, the js file under the catalogue is operated, navigated to each " value ";
3, retrieval excel table according to original ready-made sign, finds the translation of corresponding language;
4, with the translation replacement of finding in the excel table corresponding " value ";
5, the js file that will replace is exported preservation again.
Five above steps are exactly the process of searching and replacing, and present embodiment uses the js language of selecting to be simple and easy to usefulness, and the problem of the page selects the solution of js language good more only.At first, the id:value form in the js file is kept in " var data_language " variable, is the variable that js itself just can discern, and just can directly get " value " through data_language [" id "]; Js itself just has the object interface that can operate the excel table in addition, can quote very easily and retrieve the excel table.
The step that the Js programming tool is realized is following:
1, english language catalogue copy is a, and called after state language name;
2, certain language js file is passed through<script type=" text/javascript " src=''''></script>The src attribute be linked in the js code;
3, the variable in the language js file is operated, the organizational form of its variable is following JSON data layout;
var?data?=?{
xxx?:?{
yyy?:?value1,
zzz?:?value2
}
}
According to the variable in the js file, like data [xxx] [yyy], the multi-lingual excel document of index, value_xxx translated in the language that obtains certain state, and assignment data [xxx] [yyy]=value_xxx, by that analogy, realizes language replacement one by one; The data variable of having replaced is write back to original again with the form of JSON data and preserves.
Also available c/c++ Programming with Pascal Language etc. other, programming language establishment GUI.
The c/c++ Programming with Pascal Language, because the c/c++ language can't discern the variable in the js file, can only be with the formal operations of text; Navigate to " value " in each js file, the process of programming will relate to loaded down with trivial details string operation, storage allocation; Releasing memory, cumbersome compiling debugging etc.; Retrieval excel table can be selected the VC instrument, and corresponding insert is installed, or the excel table is output as the plain text form, uses the c/c++ Programming with Pascal Language merely.But in any case, all inevitably to relate to loaded down with trivial details string operation, also need consider different disposal routes special string format.
Select the vb programming, vb itself comprises the plug-in unit of excel table handling, can directly operate the excel table; For vb also is to have loaded down with trivial details string operation; Want special study vb language in order to realize this conversion instrument.
Comprehensive above analysis, here we select the js Programming with Pascal Language
Instrument is to realize that with the js script than C language and VB, he has following benefits: at first, it is quite convenient that it handles the js file, can quote wherein variable very easily, than the C language, saved character string complicated operations in a lot of C language; Secondly, the interface of EXCEL document read-write is provided, provides support for making things convenient for index EXCEL document; At last, the js Programming with Pascal Language is flexible, and it is simple that programmed logic is wanted relatively.
The Js programming is simple, and it is convenient to move, and programming need not compiling, does not have the loaded down with trivial details very long compilation process of C language, has edited code and can pass through browser execution, and the operation discovery is wrong can be easy to the miscue orientation problem according to browser.
If make a mistake in the instrument operational process, can support to rerun from mistake, debugging is convenient; Running log is detailed.
Instrumentation code is portable strong.