Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
As used herein, the terms "first," "second," …, etc., do not denote any order or sequence, nor are they used to limit the present invention, but rather are used to distinguish one element from another or from another element or operation described in the same technical language.
The following describes a method and an apparatus for identifying a style of a product according to the present application in detail with reference to the drawings. Although the present application provides method operational steps or apparatus configurations as illustrated in the following examples or figures, more or fewer operational steps or module configurations may be included in the method or apparatus based on conventional or non-inventive efforts. In the case of steps or structures where there is no logically necessary cause-and-effect relationship, the execution order of the steps or the block structure of the apparatus is not limited to the execution order or the block structure provided in the embodiments of the present application. When the described method or module structure is implemented in an actual device or end product, it can be executed sequentially or executed in parallel (e.g., in the context of parallel processors or multi-threaded processing) according to the embodiments or the method or module structure shown in the figures. Fig. 1 is a flowchart of a method of an embodiment of a method for automatically generating a code file, as shown in fig. 1, an embodiment of the method for automatically generating a code file provided by the present application may include:
step S101, traversing a first code file, and searching a plurality of first language texts in the first code file;
step S102, replacing a plurality of first language texts with corresponding variable names;
step S103, generating a first language file based on the corresponding relation between the variable name and the first language text;
step S104, translating the first language text in the first language file into a second language text to generate a second language file, wherein the second language file comprises the corresponding relation between the second language text and the variable name;
and step S105, replacing the variable name in the first code file with the corresponding second language text based on the second language file to generate a second code file.
The method for automatically generating the code file provides a scheme for automatically extracting and translating the language text in the code aiming at the multilingual requirement of the front end (webpage end), the multilingual requirement is well stripped from the development work, so that a developer only needs to pay attention to function realization, the developer can directly fill in the single language (for example, Chinese) at a character display position like developing a single-language project, and translate the single language into the language to be translated according to the second language text of multiple language types at the later stage, the working strength of the developer is greatly reduced, the burden of the developer is reduced, and the working efficiency is improved.
In the present application, the search for several first language texts in the first code file is implemented by the following preferred embodiments: traversing codes in the first code file, and searching Chinese information except the Chinese annotations in the codes; and determining the searched Chinese information as a first language text. In the process of developing a project, since developers in chinese regions are generally chinese, developers habitually use chinese information in the development and coding stage, which is not limited in this application, and for projects developed by developers habitually using english, it is english information that is found.
Searching for a plurality of first language texts in the first code file can be realized through node js (a Java script operating environment) or through other programming languages such as Java, python, c + +, and the like. The searched first language texts can be stored in a js format, and can also be stored in data storage formats such as txt, csv, database tables and the like.
Before replacing the plurality of first language texts with the variable names corresponding to the first language texts, the variable names corresponding to the first language texts can be formulated according to preset rules. To the rule of predetermineeing in this application, can set for by oneself according to actual conditions, introduce two kinds of comparatively good usefulness, the predetermined rule of result of use preferred below, the first kind is: according to the parent-child relationship among codes, variables and applications in front of the first language text, making variable names corresponding to the first language text; secondly, a variable name corresponding to the first language text is established according to the position of the code in front of the first language text. Based on the preset rule, variable names corresponding to each first language text one to one can be formulated.
It should be noted that the second language file in the present application may be multiple files, and the language type used in each file is different, for example, the second language file may be a chinese language file, an english language file, a russian language file, or the like. The following introduces the generation process of the multilingual file by taking the example that the first language text is Chinese information: firstly, generating a Chinese language file (namely the first language file) based on the corresponding relation between the variable name and the Chinese information, wherein the corresponding relation between each variable name and the Chinese information is recorded in the Chinese language file; then, translating the Chinese language file, keeping the variable names in the Chinese language file unchanged, and translating the Chinese information corresponding to each variable name into other languages, such as English or Russian; and finally, correspondingly generating a second language file with a plurality of language types, such as an English language file or a Russian language file.
After generating a second language file with multiple language types, the first language text may be replaced according to a replacement requirement, and specifically, a language type (for example, russian) that the first language text needs to be replaced is determined according to the replacement requirement; calling a second language file (such as a Russian language file) corresponding to the language type; and replacing the variable name in the first code file with the corresponding second language text based on the second language file to generate a second code file. Based on the method, the Chinese information compiled by developers in the development and coding process can be replaced by the Russian information, the translation process is simple and efficient, the burden of the developers is reduced, and the development efficiency is improved.
In the present application, the types of the first code file include at least: js, html, jsp, php, or vm. For the html type file, the first code file cannot be directly replaced, and the html type file needs to be converted into a js type file. And then performing subsequent replacement translation operations.
It should be noted that, after the first code file is upgraded, for example, a developer develops the first code file again, or some new functions are extended, the newly added first language text needs to be searched, then a variable name corresponding to the newly added first language text is formulated according to a preset rule, and finally, the corresponding relationship between the variable name and the newly added first language text is added to the first language file. That is, the content in the first language file generated before is not overwritten, and only new content needs to be added. Therefore, the updating time of the multi-language file is shortened, and repeated work is avoided.
Two preset rules for setting variable names are described below by taking js files and html files as examples.
(one) js file
1. The first code file under the specified project folder is traversed.
2. The first language text in the first code file is retrieved.
Msg:{
NoRelaceTip: 'No variables requiring replacement'
}
3. And formulating a variable name corresponding to the first language text according to a preset rule, and then replacing the first language text with the variable name.
For example, a variable name corresponding to the first language text may be formulated according to a parent-child relationship between codes and variables and applications in front of the first language text: appName _ msg _ NoReplaceTip. The variable name represents the nodeplacetip under the variable msg under the appName, so that the future positioning is facilitated, and the subsequent replacement is facilitated. The appName and the variable msg are in a parent-child relationship, the appName is a parent, and the msg is a child; the variable msg and noReplaceTip are in a parent-child relationship, msg is the parent, and noReplaceTip is the child.
The code after replacement is as follows:
Msg:{
noReplaceTip:translate(‘appName_msg_noReplaceTip’)
}
html document (II)
1. And converting the html file into a js file.
2. And traversing the js file and calling the first language text.
< cable class for < desc-title > description </cable >
3. And formulating a variable name corresponding to the first language text according to a preset rule, and then replacing the first language text with the variable name.
For example, a variable name corresponding to the first language text may be formulated according to the position where the code in front of the first language text is located: appName _ templates _ UDFDetail _ 2. In the variable name, "2" means: the description of the first language text is a 2 nd first language text appearing in html (first code file) with a variable of UDFDetail under appName, so that the method is convenient to accurately position in the future and is beneficial to subsequent quick and accurate replacement.
The code after replacement is as follows:
<lable class=“desc-title”for=“udfComment”>
translate(‘appName_templates_UDFDetail_2’)
</lable>
by analogy, a variable name corresponding to the first language text can be formulated according to the two preset rules or other preset rules, and then a Chinese language file (namely the first language file) is established according to the corresponding relation between the variable name and the first language text.
The Chinese language document is as follows:
then, the Chinese language file is translated into a second language file of the other language types, and the second language file contains the corresponding relation between the second language text and the variable name. And replacing variable names in the codes with second code files of other language types according to actual requirements, thereby realizing international multi-language development.
When the first code file is developed again and some functions are expanded, an updated first language file can be obtained only by operating the technical scheme of the application again, a new first language text and a variable name thereof are added into the original first language file, then the second language file is generated by corresponding translation, and the previous translation result cannot be covered.
Fig. 2 is a flowchart of a method of an embodiment of the method for automatically generating a language file, and as shown in fig. 2, another embodiment of the method for automatically generating a language file provided by the present application may include:
step S201, traverse each first code file in the project folder. Of course, the traversal scope in the project folder can also be specified as desired.
Step S202, judging the file type of the first code file; if the file is a js file, step S204 is executed, and if the file is an html file, step S203 is executed.
Step S203, the html file is converted into a js file. Then, step S204 is performed.
Step S204, a plurality of first language texts in the first code file are extracted.
In step S205, a variable name corresponding to the first language text is generated.
Step S206, the first language text is replaced according to the variable name.
Step S207, judging whether the second language file exists; if yes, step S209 is performed, and if no, step S208 is performed.
Step S208, generating a first language file according to the corresponding relation between the variable name and the first language text. And translating the first language text in the first language file into a second language text to generate a second language file, wherein the second language file contains the corresponding relation between the second language text and the variable name.
Step S209, integrate and update the second language file.
Based on the scheme, developers only need to develop codes according to Chinese habits and operate the scheme before issuing each time, and international multi-language development is finished.
Based on the same inventive concept as the method for automatically generating a code file, the present application provides an apparatus for automatically generating a code file, as described in the following embodiments. Because the principle of solving the problems of the device for automatically generating the code file is similar to the method for automatically generating the code file, the implementation of the device for automatically generating the code file can refer to the implementation of the method for automatically generating the code file, and repeated parts are not repeated.
Fig. 3 is a schematic structural diagram of an embodiment of an apparatus for automatically generating a code file according to the present application, and as shown in fig. 3, the apparatus may include:
the searching unit 10 is configured to traverse the first code file and search a plurality of first language texts in the first code file; the searching unit 10 is a part for searching the first language text in the device for automatically generating the code file, and may be software, hardware or a combination of the two, for example, an input/output interface, a processing chip, or other components for performing the information searching function.
A first replacing unit 20, configured to replace the first language texts with corresponding variable names; the first replacing unit 20 is a part for replacing information in the device for automatically generating a code file, and may be software, hardware, or a combination of the two, and may be, for example, an input/output interface, a processing chip, or other components that perform an information replacing function.
A file generating unit 30 configured to generate a first language file based on a correspondence relationship between a variable name and a first language text; the file generation unit 30 is a part for generating a file in the apparatus for automatically generating a code file, and may be software, hardware, or a combination of both, and may be, for example, an input/output interface, a processing chip, or other components that perform a function of generating a file.
A translation unit 40, configured to translate the first language text in the first language file into a second language text to generate a second language file, where the second language file includes a correspondence between the second language text and the variable name; the translation unit 40 is a part for performing text translation in a device that automatically generates a code file, and may be software, hardware, or a combination of both, and may be, for example, an input/output interface, a processing chip, or other components that perform a text translation function.
And a second replacing unit 50 for replacing the variable name in the first code file with the corresponding second language text based on the second language file to generate a second code file. The second replacing unit 50 is a part for replacing information in the device for automatically generating a code file, and may be software, hardware or a combination of the two, for example, an input/output interface, a processing chip, or other components that perform the information replacing function.
The device for automatically generating the code file, which is provided by the application, provides a scheme for automatically extracting and translating the language text in the code aiming at the multilingual requirement of the front end (webpage end), and well strips the multilingual requirement from the development work, so that a developer only needs to pay attention to the function realization, the developer can directly fill in the single language (for example, Chinese) at a character display position like developing a single-language project, and translate the single language into the language to be translated according to the second language text of multiple language types at the later stage, thereby greatly reducing the working intensity of the developer, reducing the burden of the developer and improving the working efficiency.
Fig. 4 is a schematic structural diagram of an embodiment of a lookup unit according to the present application, and as shown in fig. 4, the lookup unit 10 includes: the traversing module 12 is used for traversing the codes in the first code file and searching the Chinese information except the Chinese annotations in the codes; and the determining module 14 is configured to determine the searched chinese information as the first code file. The search for the first code file can be realized through node js (a Java script operating environment), and can also be realized through other programming languages such as Java, python, c + +, and the like. The searched first code file can be stored in a js format, and can also be stored in data storage formats such as txt, csv, database tables and the like.
Fig. 5 is a schematic structural diagram of an embodiment of a variable name making unit according to the present application, and as shown in fig. 5, the apparatus further includes: a variable name making unit 60 for making a variable name corresponding to the first language text according to a parent-child relationship between codes and variables and applications in front of the first language text; or, the method is used for making a variable name corresponding to the first language text according to the position of the code in front of the first language text. Typically, only one of the preset rules is adopted.
It should be noted that the second language file in the present application may be multiple files, and the language type used in each file is different, for example, the second language file may be a chinese language file, an english language file, a russian language file, or the like. The following introduces the generation process of the multilingual file by taking the example that the first language text is Chinese information: firstly, generating a Chinese language file (namely the first language file) based on the corresponding relation between the variable name and the Chinese information, wherein the corresponding relation between each variable name and the Chinese information is recorded in the Chinese language file; then, translating the Chinese language file, keeping the variable names in the Chinese language file unchanged, and translating the Chinese information corresponding to each variable name into other languages, such as English or Russian; and finally, correspondingly generating a second language file with a plurality of language types, such as an English language file or a Russian language file.
Fig. 6 is a schematic structural diagram of an embodiment of a second replacement unit described in the present application, and as shown in fig. 6, the second replacement unit 50 includes: the language determining module 52 is used for determining the language type of the first language text to be replaced according to the replacement requirement; a file retrieving module 54, configured to retrieve a second language file corresponding to the language type; and a replacing module 56, configured to replace the variable name in the first code file with a corresponding second language text based on the second language file to generate a second code file. Thus realizing international multi-language development.
In the present application, the types of the first code file include at least: js, html, jsp, php, or vm. For the html type file, the first language text cannot be directly replaced, and the html type file needs to be converted into a js type file. And then performing subsequent replacement translation operations. Accordingly, the above apparatus further comprises: a type conversion unit for judging the type of the first code file; if the html type file is the html type file, the html type file is converted into a js type file.
It should be noted that, after the first code file is upgraded, for example, a developer develops the first code file again, or some new functions are extended, the newly added first language text needs to be searched, then a variable name corresponding to the newly added first language text is formulated according to a preset rule, and finally, the corresponding relationship between the variable name and the newly added first language text is added to the first language file. That is, the content in the previously generated language file is not overwritten, and only new content needs to be added. Based on this, the present application provides a preferred embodiment, that is, the above apparatus further comprises: the updating unit is used for searching the newly added first language text after the first code file is upgraded; formulating a variable name corresponding to the newly added first language text according to a preset rule; and supplementing the corresponding relation between the variable name and the newly added first language text into the first language file. Therefore, the updating time of the multi-language file is shortened, and repeated work is avoided.
From the above description, the scheme for automatically generating the code file is designed, so that the multi-language requirements are well stripped from the development work, and developers only need to pay attention to function implementation. The developer can directly fill in the characters on the display position by using Chinese as developing a project of a single language without considering the problems of later variable replacement and the like. And when the multi-language requirement is met, a developer does not need to change the source code, the quota burden of the developer is reduced, and the development efficiency is improved.
Although the present application provides method steps as described in an embodiment or flowchart, additional or fewer steps may be included based on conventional or non-inventive efforts. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. When an actual apparatus or client product executes, it may execute sequentially or in parallel (e.g., in the context of parallel processors or multi-threaded processing) according to the embodiments or methods shown in the figures.
The apparatuses or modules illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. The functionality of the modules may be implemented in the same one or more software and/or hardware implementations of the present application. Of course, a module that implements a certain function may be implemented by a plurality of sub-modules or sub-units in combination.
The methods, apparatus or modules described herein may be implemented in computer readable program code to implement a controller in any suitable manner, e.g., the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, Application Specific Integrated Circuit (ASIC), programmable logic controller and embedded microcontroller, examples of the controller including, but not limited to, ARC 625D, Atmel AT91SAM, Microchip 18F26K20 and Silicone L abs C8051F320, the memory controller may also be implemented as part of the control logic of the memory.
Some of the modules in the apparatus described herein may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, classes, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
From the above description of the embodiments, it is clear to those skilled in the art that the present application can be implemented by software plus necessary hardware. Based on such understanding, the technical solutions of the present application may be embodied in the form of software products or in the implementation process of data migration, which essentially or partially contributes to the prior art. The computer software product may be stored in a storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, mobile terminal, server, or network device, etc.) to perform the methods described in the various embodiments or portions of the embodiments of the present application.
The embodiments in the present specification are described in a progressive manner, and the same or similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. All or portions of the present application are operational with numerous general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, mobile communication terminals, multiprocessor systems, microprocessor-based systems, programmable electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like.
While the present application has been described with examples, those of ordinary skill in the art will appreciate that there are numerous variations and permutations of the present application without departing from the spirit of the application, and it is intended that the appended claims encompass such variations and permutations without departing from the spirit of the application.