Nothing Special   »   [go: up one dir, main page]

CN113760361A - Code file generation method, computer device and readable storage medium - Google Patents

Code file generation method, computer device and readable storage medium Download PDF

Info

Publication number
CN113760361A
CN113760361A CN202110942043.1A CN202110942043A CN113760361A CN 113760361 A CN113760361 A CN 113760361A CN 202110942043 A CN202110942043 A CN 202110942043A CN 113760361 A CN113760361 A CN 113760361A
Authority
CN
China
Prior art keywords
keyword
code file
language
file
language type
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110942043.1A
Other languages
Chinese (zh)
Inventor
安晓普
王雄斌
曹梦飞
原帅
王家尧
张磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhongke Shuguang International Information Industry Co ltd
Original Assignee
Zhongke Shuguang International Information Industry Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhongke Shuguang International Information Industry Co ltd filed Critical Zhongke Shuguang International Information Industry Co ltd
Priority to CN202110942043.1A priority Critical patent/CN113760361A/en
Publication of CN113760361A publication Critical patent/CN113760361A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Library & Information Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Machine Translation (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The embodiment of the application provides a code file generation method, computer equipment and a readable storage medium. The method comprises the following steps: acquiring an original code file of a target project; the original code file comprises a plurality of key value pairs, wherein each key value pair comprises a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type; determining the translation text of each character string of the first language type in the original code file under multiple language types according to the comparison file; the comparison file is used for indicating the translated text of the values of the keywords related to the target project under multiple language types; and generating a code file corresponding to each language type in the multiple language types according to the translated text of each character string of the first language type under the multiple language types and the original code file. The generation cost of the internationalized code file can be reduced, and the creation efficiency of the internationalized code file can be improved.

Description

Code file generation method, computer device and readable storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a code file generation method, a computer device, and a readable storage medium.
Background
Some scripts required for a computer to run typically include key-value pairs, including keys, which may be parameter names, and values, which may be parameter values. When some international projects are docked, the script needs to be internationally adapted, and the script is converted into an internationalized script (or an internationalized code file). The internationalized adaptation process for the script mainly relates to the translation of value. For example, the value in the key-value pair is "time", which can be translated into "time", and the internationalized script is generated.
At present, programmers mainly rely on manual writing of internationalized files and compiling value into languages of other countries such as English. However, this method requires a lot of labor cost, takes much time, and is inefficient.
Disclosure of Invention
The embodiment of the application provides a code file generation method, a computer device and a readable storage medium, which can reduce the generation cost of an internationalized code file and improve the creation efficiency of the internationalized code file.
In a first aspect, a method for generating a code file is provided, where the method includes:
acquiring an original code file of a target project; the original code file comprises a plurality of key value pairs, wherein each key value pair comprises a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;
determining the translation text of each character string of the first language type in the original code file under multiple language types according to the comparison file; the comparison file is used for indicating the translated text of the values of the keywords related to the target project under multiple language types;
and generating a code file corresponding to each language type in the multiple language types according to the translated text of each character string of the first language type under the multiple language types and the original code file.
In the method and the device, the server can automatically load the comparison file to determine the translation value of each value in the original code file after acquiring the original code file of the project, and further can automatically generate code files (also called as international files and international code files) of other language types according to the value translation value, so that the automatic generation of the international files is realized, the generation cost of the international files is saved, and the creation efficiency of the international files is improved.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the comparison file includes keywords related to the target item and a comparison portion; the contrast part comprises translated texts of the values of the keywords under a plurality of language types;
the first character is included between the keyword and the comparison part of the keyword, and the second character is included between the translation texts in different language types in the comparison part.
According to the method and the device, the format of the comparison file is limited, so that the server can accurately identify the translation texts of all language types according to the specific separating characters in the comparison file after reading the comparison file. For example, the control part in the control file, i.e. the translation text part, can be accurately identified according to the first character, and the translation text in different languages can also be accurately identified according to the second character.
With reference to the first aspect, in a first possible implementation manner of the first aspect, determining, according to the comparison file, a translation text of each character string of the first language type in the original code file under multiple language types includes:
aiming at each character string of the first language type, searching a comparison file according to the key word corresponding to the character string of the first language type, and determining a comparison part corresponding to the key word from the comparison file;
and extracting the translated text of the character string of the first language type under a plurality of language types from the comparison part corresponding to the keyword.
According to the method and the device, the specific implementation mode for generating the code files of different language types according to the comparison files is provided, the comparison part of the keywords is identified, the translation texts of the values of the keywords under different language types are extracted from the comparison part of the keywords, so that the code files under different language types can be generated based on the identified translation texts, manual translation is avoided, the generation cost of the internationalized code files is reduced, the internationalized code files are automatically generated, and the generation efficiency of internationalized codes is improved.
With reference to the first aspect, in a first possible implementation manner of the first aspect, generating, according to the translated text of each character string of the first language type under multiple language types and the original code file, a code file corresponding to each language type of the multiple language types includes:
writing a translation text of the character string of the first language type under the second language type and a keyword corresponding to the character string of the first language type according to a storage path corresponding to the second language type to generate a code file of the second language type; the second language type is any one of a plurality of language types.
According to the method and the device, a specific implementation mode for generating the internationalized code files is provided, after the translation text of each keyword is obtained, the keyword and the translation text can be written in the storage path corresponding to the language type according to the language type, the code files of different language types are isolated through different storage paths, and the generated code files can support effective reading and writing.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the generating process of the comparison file includes:
determining keywords relevant to the target by the project, and determining translation texts of the values of the keywords relevant to the target project under a plurality of language types;
and if the translation text comprises the first character, replacing the first character in the translation file with a preset indication character.
In the method and the device, the conflict between the characters in the translated text and the separation characters of KV is avoided, for example, the characters which are the same as the separation characters in the translated text can be replaced, errors in the process of identifying the keywords and the comparison part according to the comparison file are avoided, so that the problem of errors in the identification of the translated text is avoided, and the accuracy of automatically generating the international code file is improved.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the method further includes:
aiming at the code file corresponding to each language type in the multiple language types, if the value of the keyword in the code file comprises a preset indication character, replacing the indication character with a first character.
In the method and the device, after the separation characters in the original translation text are replaced, the indication characters in the code files can be restored into the separation characters after the code files of different language types are generated, and the accuracy of the translation text in the code files is guaranteed.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the method further includes:
aiming at each keyword in the original code file, if the comparison file does not comprise the keyword, sending a translation request to an external server; the translation request is used for indicating an external server to determine a first language type character string corresponding to the keyword and a translation text in multiple language types;
and acquiring the translation text of the first language type character string corresponding to the keyword from an external server, and writing the translation text of the first language type character string corresponding to the first keyword into a code file of a corresponding language type.
In the application, in the case that some keywords are not recorded in the comparison file, the external server may be requested to translate the value of the keyword, so that code files of other language types may be generated based on the translation result returned by the external server, a complete code file may be generated, and the translation text of the value of some keywords is prevented from being omitted in the final code file.
In a second aspect, there is provided a code file generation apparatus, including:
the acquisition unit is used for acquiring an original code file of the target project; the original code file comprises a plurality of key value pairs, wherein each key value pair comprises a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;
the determining unit is used for determining the translation text of each character string of the first language type in the original code file under multiple language types according to the comparison file; the comparison file is used for indicating the translated text of the values of the keywords related to the target project under multiple language types;
and the generating unit is used for generating a code file corresponding to each language type in the multiple language types according to the translated text of each character string of the first language type under the multiple language types and the original code file.
In a third aspect, there is provided a computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor, when executing the computer program, implements the method according to the first aspect or any one of the first aspects.
In a fourth aspect, there is provided a computer readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method of any of the first aspect or the first aspect as described above.
According to the code file generation method, the computer device and the readable storage medium provided by the embodiment of the application, the server can automatically load the comparison file after acquiring the original code file of the project, determine the translation value of each value in the original code file according to the comparison file, and further automatically generate code files (also called as international files and international code files) of other language types according to the translation value of the value, so that the automatic generation of the international files is realized, the generation cost of the international files is saved, and the creation efficiency of the international files is improved.
Drawings
Fig. 1 is a schematic diagram of a system architecture provided in an embodiment of the present application;
fig. 2 is a schematic flowchart of a code file generation method according to an embodiment of the present application;
fig. 3 is another schematic flowchart of a code file generation method according to an embodiment of the present application;
fig. 4 is another schematic flowchart of a code file generation method according to an embodiment of the present application;
fig. 5 is a block diagram of a code generation apparatus according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
First, to facilitate understanding of the technical methods provided by the embodiments of the present application, terms related to the embodiments of the present application are explained:
(1) code file
The code files in the embodiments of the present application may be referred to as scripts. A Script (Script) is a collection of program commands that contains a variety of program commands, and the program commands in the collection are typically stored as separate executable files. An executable file refers to a file that may be loaded and executed by an operating system. Executable programs are presented differently in different operating system environments, for example, in a windows operating system, an executable file may be of the type ". exe file", ". sys file", ". com file", etc.
The script comprises a key-value pair which comprises a key and a value. Wherein, the key may be a parameter name in the code file, such as time, place, cycle number, etc.; value is a specific value of a parameter, for example, 10:33:10 on 6/28/2021, Xian City, etc.
(2) Language type
The language type in the embodiment of the application can be the country of the language, and the different types of languages can be Chinese and English.
The method provided by the embodiment of the application is suitable for the system architecture shown in fig. 1. The architecture shown in fig. 1 includes a client 10 and a server 20, wherein the client 10 may submit a request for generating a code file to the server, and the server 20 may generate the code file in response to the request of the client 10 and transmit the code file to the client 10.
The embodiment of the present application provides a code file generation method, which is applicable to the system architecture shown in fig. 1, and an execution subject may be a server in the architecture shown in fig. 1. As shown in fig. 2, the method comprises the following steps:
step 201, acquiring an original code file of a target project; the original code file includes a plurality of key-value pairs, the key-value pairs including a keyword and a value of the keyword, the value of the keyword being a string of characters of a first language type.
In a specific implementation, a user may write an original step, i.e., the original code file, according to a specific docked item. The original code file may be implementation code of some functions of the target project, or may also be operation code of the whole target project, which is not limited in this application, and any code file related to the target project may be regarded as the original code file described in the embodiments of the present application.
In addition, in order to avoid the situation that a user manually translates values in the original code file and generates internationalized codes of various language types, the user can submit the original code file through the client and request the server to automatically generate different homemade code files according to the original code file.
In a possible implementation manner, after the client submits the original code file of the target project to the server, the server may obtain the original code file of the target project.
It should be noted that the keyword is a key in the key value pair, and may be some parameters related to the target item; the value of the key may be the actual value of the parameter. The first language type is a language type, for example, the value of a keyword in a key value pair is a chinese character string.
Step 202, determining the translated text of each character string of the first language type in the original code file under multiple language types according to the comparison file.
The comparison file can be generated according to the requirements of the target project, the translation texts of the values of the keywords related to the target project under multiple language types can be indicated, and different translation texts can support the target project to adapt to different development requirements. For example, the control file may indicate a plurality of translated texts of values of some keywords related to the target item, for example, english, korean, italian, and the like.
In a specific implementation, each value in the original code file is traversed, a comparison file is searched, and one or more translation texts corresponding to the value are determined. For example, the english translation string corresponding to each chinese string in the original code of the chinese version may be determined from the comparison file.
And step 203, generating a code file corresponding to each language type in the multiple language types according to the translated text of each character string of the first language type under the multiple language types and the original code file.
In a specific implementation, for each keyword in the original code, the keyword is combined with the translation text acquired in step 202 and corresponding to the keyword, so as to generate a code file of another language type.
For example, the original code file includes N keywords, the values of the N keywords are N chinese character strings, and in step 202, N english character strings corresponding to the N chinese character strings may be determined according to the comparison file, and the N keywords and the N english character strings are combined in a one-to-one correspondence manner to generate the english code file.
In one possible implementation manner, the method shown in fig. 2 in this embodiment is executed in a nodjs environment. Specifically, the following file directories are defined first:
Input
----need.json
Output
----need-en.js
----need-zh.js
wherein "Input" represents the Input of the program, "need. It should be noted that the output code file is not limited to the above "need-en.js" and "need-zh.js", but may be a code file of other language type, and the language type of the output code file depends on the translation text in the comparison file.
In a specific implementation, an index. js file is also defined, and program codes in the index. js file are used for executing the method shown in fig. 2. When the server runs a node./index. js./output./input/new. json command, the method described in the embodiments of the present application may be executed in a node js environment, for example, a new.
In the method provided by the embodiment of the application, after the server acquires the original code file of the project, the translation value of each value in the original code file can be determined by automatically loading the comparison file, and further, code files (also called as international files and international code files) of other language types can be automatically generated according to the value translation value, so that the automatic generation of the international files is realized, the generation cost of the international files is saved, and the creation efficiency of the international files is improved.
In a possible implementation manner, the embodiment of the present application further provides a specific format of the comparison file, specifically, the comparison file includes a keyword related to the target item and a comparison portion; the contrast part comprises translated texts of the values of the keywords under a plurality of language types;
the first character is included between the keyword and the comparison part of the keyword, and the second character is included between the translation texts in different language types in the comparison part.
Taking nodjs as an example, when the method described in the embodiment of the present application is executed in a nodjs environment, the format of the comparison file is also limited as follows:
(1) the comparison file is a file in a json format;
(2) the value of a Key (Key) in the comparison file is a value used in the target project;
(3) the keywords and values in the comparison file are separated by characters. For example, comma separation is used between key and value.
According to the method provided by the embodiment of the application, the format of the comparison file is limited, so that the server can accurately identify the translation texts of all language types according to the specific separating characters in the comparison file after reading the comparison file. For example, the control part in the control file, i.e. the translation text part, can be accurately identified according to the first character, and the translation text in different languages can also be accurately identified according to the second character.
In a possible implementation manner, in the method provided in this embodiment of the present application, the server may traverse each keyword in the original code file, determine a translation text of a value of each keyword, and construct code files of different language types according to the translation text of the value of each keyword.
For example, the specific implementation steps involved in determining the translated text of each character string of the first language type in the original code file under multiple language types according to the comparison file are shown in fig. 3:
step 301, for each character string of the first language type, searching a comparison file according to the keyword corresponding to the character string of the first language type, and determining a comparison part corresponding to the keyword from the comparison file.
In a specific implementation, each keyword in the original code file is traversed, and a comparison file is searched to determine a comparison portion corresponding to the value of the keyword (i.e., a character string of the first language type corresponding to the keyword).
For example, after the comparison file is loaded, the keywords and the comparison portion in the comparison file can be identified according to the first character, so that the comparison portion corresponding to each keyword can be determined. For example, the control file includes the following:
project key parameter 1(key1), chinese string 1@ english string 1@ korean string 1;
project key parameter 2(key2), chinese string 2@ english string 2@ korean string 2;
project key parameter 3(key3), chinese string 3@ english string 3@ korean string 3;
……
in the above comparison file, "," is the first character described above, "@" is the second character described above, and based on the first character, "the comparison portion capable of recognizing key1 is" chinese character string 1@ english character string 1@ korean character string 1 ", the comparison portion corresponding to key2 is" chinese character string 2@ english character string 2@ korean character string 2 ", and the comparison portion corresponding to key3 is" chinese character string 3@ english character string 3@ korean character string 3 ".
Step 302, extracting the translated text of the character string of the first language type under a plurality of language types from the comparison part corresponding to the keyword.
In specific implementation, translation texts in different language types are identified from the comparison texts corresponding to the keywords according to the second characters.
Referring to the related example of step 301, three language-type translated texts, respectively "chinese string 1", "english string 1", and "korean string 1", can be extracted from the collation portion of key1 according to the second character "@". Similarly, the translated text of three language types can be extracted from the contrast portion of key1, which is not described herein.
The embodiment of the application provides a specific implementation mode for generating code files of different language types according to the comparison file, the comparison part of the keyword is identified, and the translation texts of the values of the keyword under different language types are extracted from the comparison part of the keyword, so that the code files under different language types can be generated based on the identified translation texts, manual translation is avoided, the generation cost of internationalized code files is reduced, the internationalized code files are automatically generated, and the generation efficiency of internationalized codes is improved.
In the embodiment of the application, the translated text of the value of the keyword can be written according to the specified path so as to generate code files of other language types. Specifically, the specific implementation manner of generating the code file corresponding to each language type in the multiple language types according to the translated text and the original code file of each character string of the first language type in the multiple language types includes:
writing a translation text of the character string of the first language type under the second language type and a keyword corresponding to the character string of the first language type according to a storage path corresponding to the second language type to generate a code file of the second language type; the second language type is any one of a plurality of language types referred to by the reference document.
That is, for each language type related to the comparison file, a storage path of the code file corresponding to the language type is preset, for example, the storage path of the aforementioned new-en.js is a storage path of an english code file. And after the translation texts corresponding to the keywords in the original code are obtained from the comparison file, different storage paths are distinguished according to language types, and the translation texts in different language types and the corresponding keywords are written in the different storage paths to generate code files in different language types.
For example, after identifying the english translation corresponding to the key in the comparison file, the key and the corresponding english translation are written into the storage path of new-en.js, and an english code file is generated.
According to the method provided by the embodiment of the application, a specific implementation mode for generating the internationalized code file is provided, after the translation text of each keyword is obtained, the keyword and the translation text can be written in the storage path corresponding to the language type according to the language type, and the code files of different language types are isolated through different storage paths, so that the generated code file can support effective reading and writing.
In a possible implementation manner, when the comparison file is generated, if the translation text of the value of the keyword includes a separation character between the keyword and the value, the character in the translation text may be replaced with another character, so as to prevent that the keyword is recognized after the comparison file is acquired, and the comparison part is erroneous, so that the correct translation text cannot be recognized. It should be noted that the separation character is used to separate the keyword from the comparison portion of the keyword, which is beneficial for the server to accurately identify the keyword and the comparison portion.
Illustratively, the method shown in fig. 2 includes: determining keywords related to the target project, and determining translated texts of which the value of each keyword is under the plurality of language types; and if the translation text comprises the first character, replacing the first character in the translation file with a preset indication character.
For example, the key and control sections in the control file are used as "," separated "," preceded by "key", "preceded by" and followed by the control section. If the translated text in a certain language type in the comparison part comprises ",", the "in the translated text is replaced by other characters so as to avoid errors when the comparison part is identified.
According to the method provided by the embodiment of the application, the conflict between the characters in the translated text and the separation characters of KV is avoided, for example, the characters which are the same as the separation characters in the translated text can be replaced, errors are avoided when keywords and comparison parts are identified according to comparison files, and therefore the problem that the translated text is identified and made mistakes is avoided, and the accuracy of automatically generating the internationalized code files is improved.
In a possible implementation manner, if the preset indication character exists in the translation text of the code file, which indicates that the original translation text includes the first character, in order to ensure the accuracy of the translation text, the translation text in the code file may be restored to the first character.
For example, after generating the code files corresponding to the multiple language types, for the code file corresponding to each of the multiple language types, if the value of the keyword in the code file includes a preset indication character, the indication character is replaced with the first character.
In the method provided by the embodiment of the application, after the separation characters in the original translation text are replaced, the indication characters in the code file can be restored into the separation characters after the code files of different language types are generated, so that the accuracy of the translation text in the code file is ensured.
In a possible implementation manner, if the comparison part of a certain keyword is not recorded in the comparison file, an external translation server may be requested to translate the value of the keyword in the original code file to obtain a translation text of the value of the keyword.
For example, for each keyword in the original code file, if the keyword is not included in the comparison file, a translation request is sent to the external server. The translation request is used for indicating an external server to determine a first language type character string corresponding to the keyword, and a translation text under multiple language types;
and acquiring the translation text of the first language type character string corresponding to the keyword from an external server, and writing the translation text of the first language type character string corresponding to the first keyword into a code file of a corresponding language type.
It should be noted that the type of translation text requested depends on the type of language involved with the control document. Illustratively, if the comparison file comprises a korean value and an english value corresponding to the keyword, the external server is requested to translate the value of the keyword in the original file into korean and english for the unrecorded keyword in the comparison file.
In a specific implementation, the external server may be a web server, and the translation of the value is implemented by means of a web service.
In the method provided by the embodiment of the application, under the condition that some keywords are not recorded in the comparison file, the external server can be requested to translate the value of the keyword, so that code files of other language types can be generated based on the translation result returned by the external server, a complete code file is generated, and the translation text of the value of some keywords is prevented from being omitted in the final code file.
The following describes the code file generation method provided in the embodiment of the present application in detail by taking a nodejs environment as an example. As shown in fig. 4, the method comprises the steps of:
step 401, obtaining an original code file of the target project, where the value of each keyword in the original code file is a chinese character string.
In a specific implementation, the server may obtain an original code file submitted by the client, so as to automatically generate code files of various language types according to the original code file.
Step 402, reading a need.json file by a fs.readfile method, and acquiring N target character strings corresponding to each keyword in an original code file from the need.json file.
In a specific implementation, a need file is loaded in a nodejs environment, and translation texts of each keyword, that is, a target character string in the embodiment of the present application, may be recognized from a need file (that is, a comparison file in the embodiment of the present application) by using an fs. N is the number of language types referred to by the need.json file, for example, the need.json file includes value's english translation text and korean translation text, and N is equal to 2.
And step 403, converting the N target character strings corresponding to each keyword into objects through the JSON.
The object may be a minimum unit of code loop execution, and the target character string is converted into the object, that is, the data structure conversion is performed on the target character string, so that a job may be executed based on the object subsequently to generate a code file for each language type.
Step 404, starting the N job reading objects, and generating code files of N language types.
In specific implementation, the N jobs correspond to N language types, and are respectively used to read corresponding objects, write the objects in corresponding paths, and generate code files.
For example, step 402 acquires 2 character strings corresponding to key1, which are chinese character string 1 and english character string 1, respectively; 2 character strings corresponding to the key2, namely a Chinese character string 2 and an English character string 2; the 2 character strings corresponding to the key3 are chinese character string 3 and english character string 3, respectively.
The chinese character string 1 and the english character string 1 are converted into an object 11 and an object 12, respectively, the chinese character string 2 and the english character string 2 are converted into an object 21 and an object 22, respectively, and the chinese character string 3 and the english character string 3 are converted into an object 31 and an object 32, respectively.
The job 1 and the job 2 are started to generate a need-zh.js (chinese code file) and a need-en.js (english code file), respectively. Specifically, the start job 1 writes the object 11, the object 21, and the object 31 into new-zh.js, and generates a chinese code file. Job 2 is started to write object 12, object 22, and object 32 into new-en.js, and an english code file is generated.
In one possible implementation, code files of different language types may be generated only from original code files submitted by clients without the aid of a need. Illustratively, step 402 may be replaced with: and requesting the translation text of the Chinese character string of each keyword from the web server, and acquiring N target character strings corresponding to each keyword in the original code file. Wherein, the N target character strings are translation texts of values under different language types.
In specific implementation, koa service is started in the nodejs environment, a translation request is sent to a web server through an interface of a web translation webpage, and the web is requested to translate Chinese character strings of each keyword so as to obtain N target character strings corresponding to each keyword.
It should be noted that, in this way, except that step 402 may be replaced by the above implementation, the remaining steps are still applicable, and a code file of a different language type may be generated by means of the translation function of the web server.
In the method shown in fig. 4, the server may determine the translated text of the value of each keyword in the original code according to a preconfigured need.
An embodiment of the present application provides a code file generation apparatus, as shown in fig. 5, the apparatus includes an obtaining unit 501, a determining unit 502, and a generating unit 503.
In a possible implementation manner, the obtaining unit 501 is configured to obtain an original code file of a target project; the original code file comprises a plurality of key value pairs, wherein each key value pair comprises a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;
a determining unit 502, configured to determine, according to the comparison file, a translation text of each character string of the first language type in the original code file under multiple language types; the comparison file is used for indicating the translated text of the values of the keywords related to the target project under multiple language types;
the generating unit 503 is configured to generate a code file corresponding to each of the multiple language types according to the translated text of each of the character strings of the first language type in the multiple language types and the original code file.
In one possible implementation, the comparison file includes keywords related to the target item and a comparison part; the contrast part comprises translated texts of the values of the keywords under a plurality of language types;
the first character is included between the keyword and the comparison part of the keyword, and the second character is included between the translation texts in different language types in the comparison part.
In a possible implementation manner, the determining unit 502 is specifically configured to, for each character string of the first language type, search a comparison file according to a keyword corresponding to the character string of the first language type, and determine a comparison portion corresponding to the keyword from the comparison file;
and extracting the translated text of the character string of the first language type under a plurality of language types from the comparison part corresponding to the keyword.
In a possible implementation manner, the generating unit 503 is specifically configured to write, according to a storage path corresponding to the second language type, a translation text of a character string of the first language type in the second language type and a keyword corresponding to the character string of the first language type, so as to generate a code file of the second language type; the second language type is any one of a plurality of language types.
In a possible implementation manner, the generating process of the comparison file includes: determining keywords related to a target project, and determining translation texts of the values of the keywords related to the target project under a plurality of language types;
and if the translation text comprises the first character, replacing the first character in the translation file with a preset indication character.
In a possible implementation manner, the generating unit 503 is further configured to, for a code file corresponding to each of the multiple language types, replace the indication character with the first character if the value of the keyword in the code file includes a preset indication character.
In a possible implementation manner, the determining unit 502 is further configured to, for each keyword in the original code file, send a translation request to an external server if the comparison file does not include the keyword; the translation request is used for indicating an external server to determine a first language type character string corresponding to the keyword and a translation text in multiple language types; acquiring a translation text of a first language type character string corresponding to the keyword from an external server;
the generating unit is further configured to write the translation text of the first language type character string corresponding to the first keyword into a code file of a corresponding language type.
An embodiment of the present application further provides a computer device, where the computer device may be the data source device described above. The internal structure thereof may be as shown in fig. 6. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device may store configuration information, rights information, and the like. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement the steps performed by the server in the method shown in fig. 6 in the embodiment of the present application.
By way of example, the computer program when executed by a processor implements:
acquiring an original code file of a target project; the original code file comprises a plurality of key value pairs, wherein each key value pair comprises a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;
determining the translation text of each character string of the first language type in the original code file under multiple language types according to the comparison file; the comparison file is used for indicating the translated text of the values of the keywords related to the target project under multiple language types;
and generating a code file corresponding to each language type in the multiple language types according to the translated text of each character string of the first language type under the multiple language types and the original code file.
In one possible implementation, the comparison file includes keywords related to the target item and a comparison part; the contrast part comprises translated texts of the values of the keywords under a plurality of language types;
the first character is included between the keyword and the comparison part of the keyword, and the second character is included between the translation texts in different language types in the comparison part.
In one possible implementation, the computer program is executed by a processor to implement: aiming at each character string of the first language type, searching a comparison file according to the key word corresponding to the character string of the first language type, and determining a comparison part corresponding to the key word from the comparison file;
and extracting the translated text of the character string of the first language type under a plurality of language types from the comparison part corresponding to the keyword.
In one possible implementation, the computer program is executed by a processor to implement: writing a translation text of the character string of the first language type under the second language type and a keyword corresponding to the character string of the first language type according to a storage path corresponding to the second language type to generate a code file of the second language type; the second language type is any one of a plurality of language types.
In a possible implementation manner, the generating process of the comparison file includes: determining keywords related to a target project, and determining translation texts of the values of the keywords related to the target project under a plurality of language types;
and if the translation text comprises the first character, replacing the first character in the translation file with a preset indication character.
In one possible implementation, the computer program is executed by a processor to implement: aiming at the code file corresponding to each language type in the multiple language types, if the value of the keyword in the code file comprises a preset indication character, replacing the indication character with a first character.
In one possible implementation, the computer program is executed by a processor to implement: aiming at each keyword in the original code file, if the comparison file does not comprise the keyword, sending a translation request to an external server; the translation request is used for indicating an external server to determine a first language type character string corresponding to the keyword and a translation text in multiple language types; acquiring a translation text of a first language type character string corresponding to the keyword from an external server;
and writing the translation text of the first language type character string corresponding to the first keyword into a code file of a corresponding language type.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include at least one of non-volatile and volatile memory. Non-volatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical storage, or the like. Volatile Memory can include Random Access Memory (RAM) or external cache Memory. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM), among others.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A code file generation method, comprising:
acquiring an original code file of a target project; the original code file comprises a plurality of key value pairs, wherein each key value pair comprises a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;
determining a translation text of each character string of the first language type in the original code file under multiple language types according to the comparison file; the comparison file is used for indicating the translated text of the values of the keywords related to the target project under the multiple language types;
and generating a code file corresponding to each language type in the multiple language types according to the translated text of each character string of the first language type under the multiple language types and the original code file.
2. The method according to claim 1, wherein the comparison file comprises keywords related to the target item and a comparison part; the control portion includes translated text of values of the keywords in the plurality of language types;
wherein a first character is included between the keyword and a contrast part of the keyword, and a second character is included between the translated texts in different language types in the contrast part.
3. The method of claim 2, wherein determining the translated text of each of the character strings of the first language type in the original code file under multiple language types according to the comparison file comprises:
for each character string of the first language type, searching the comparison file according to the keyword corresponding to the character string of the first language type, and determining a comparison part corresponding to the keyword from the comparison file;
and extracting the translated text of the character string of the first language type under a plurality of language types from the contrast part corresponding to the keyword.
4. The method according to claim 1, wherein the generating a code file corresponding to each of the plurality of language types according to the translated text of each of the character strings of the first language type under the plurality of language types and the original code file comprises:
writing a translation text of the character string of the first language type under the second language type and a keyword corresponding to the character string of the first language type according to a storage path corresponding to the second language type to generate a code file of the second language type; the second language type is any one of the plurality of language types.
5. The method of claim 2, wherein the generating of the comparison file comprises:
determining keywords related to the target item, and determining translated texts of the values of the keywords related to the target item under the plurality of language types;
and if the translation text comprises the first character, replacing the first character in the translation file with a preset indicating character.
6. The method of claim 5, further comprising:
and for the code file corresponding to each language type in the multiple language types, if the value of the keyword in the code file comprises the preset indication character, replacing the indication character with the first character.
7. The method of claim 1, further comprising:
for each keyword in the original code file, if the keyword is not included in the comparison file, sending a translation request to an external server; the translation request is used for instructing the external server to determine a first language type character string corresponding to the keyword, and a translation text in the plurality of language types;
and acquiring the translation text of the first language type character string corresponding to the keyword from the external server, and writing the translation text of the first language type character string corresponding to the first keyword into a code file of a corresponding language type.
8. A code file generating apparatus, comprising:
the acquisition unit is used for acquiring an original code file of the target project; the original code file comprises a plurality of key value pairs, wherein each key value pair comprises a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;
the determining unit is used for determining the translation text of each character string of the first language type in the original code file under multiple language types according to the comparison file; the comparison file is used for indicating the translated text of the values of the keywords related to the target project under the multiple language types;
and the generating unit is used for generating a code file corresponding to each language type in the multiple language types according to the translated text of each character string of the first language type under the multiple language types and the original code file.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method of any of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.
CN202110942043.1A 2021-08-17 2021-08-17 Code file generation method, computer device and readable storage medium Pending CN113760361A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110942043.1A CN113760361A (en) 2021-08-17 2021-08-17 Code file generation method, computer device and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110942043.1A CN113760361A (en) 2021-08-17 2021-08-17 Code file generation method, computer device and readable storage medium

Publications (1)

Publication Number Publication Date
CN113760361A true CN113760361A (en) 2021-12-07

Family

ID=78789956

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110942043.1A Pending CN113760361A (en) 2021-08-17 2021-08-17 Code file generation method, computer device and readable storage medium

Country Status (1)

Country Link
CN (1) CN113760361A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114371996A (en) * 2021-12-30 2022-04-19 浙江中控技术股份有限公司 JS file testing method and device
CN114461193A (en) * 2022-04-11 2022-05-10 北京远特科技股份有限公司 Method, device, equipment and storage medium for generating communication protocol code

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102364437A (en) * 2011-09-22 2012-02-29 厦门游家网络有限公司 Multi-language site development system and implementation method thereof
CN109284145A (en) * 2018-08-28 2019-01-29 北京城市网邻信息技术有限公司 The generation of multilingual configuration file and methods of exhibiting and device, equipment and medium
CN111984300A (en) * 2020-09-08 2020-11-24 网易(杭州)网络有限公司 Code copying method and device, electronic equipment and computer readable storage medium
CN113139390A (en) * 2020-01-17 2021-07-20 北京沃东天骏信息技术有限公司 Language conversion method and device applied to code character strings

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102364437A (en) * 2011-09-22 2012-02-29 厦门游家网络有限公司 Multi-language site development system and implementation method thereof
CN109284145A (en) * 2018-08-28 2019-01-29 北京城市网邻信息技术有限公司 The generation of multilingual configuration file and methods of exhibiting and device, equipment and medium
CN113139390A (en) * 2020-01-17 2021-07-20 北京沃东天骏信息技术有限公司 Language conversion method and device applied to code character strings
CN111984300A (en) * 2020-09-08 2020-11-24 网易(杭州)网络有限公司 Code copying method and device, electronic equipment and computer readable storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114371996A (en) * 2021-12-30 2022-04-19 浙江中控技术股份有限公司 JS file testing method and device
CN114461193A (en) * 2022-04-11 2022-05-10 北京远特科技股份有限公司 Method, device, equipment and storage medium for generating communication protocol code
CN114461193B (en) * 2022-04-11 2022-07-12 北京远特科技股份有限公司 Method, device, equipment and storage medium for generating communication protocol code

Similar Documents

Publication Publication Date Title
CN108762743B (en) Data table operation code generation method and device
CN111176996A (en) Test case generation method and device, computer equipment and storage medium
CN106874281B (en) Method and device for realizing database read-write separation
US11422917B2 (en) Deriving software application dependency trees for white-box testing
CN113760361A (en) Code file generation method, computer device and readable storage medium
CN116226170A (en) Database statement conversion method and device, electronic equipment and storage medium
CN113434395A (en) Automatic generation method, device, equipment and medium of test case
CN116955720A (en) Data processing method, apparatus, device, storage medium and computer program product
CN115238655A (en) Json data editing method and device
CN111581344B (en) Interface information auditing method and device, computer equipment and storage medium
US10942934B2 (en) Non-transitory computer-readable recording medium, encoded data searching method, and encoded data searching apparatus
JP6492466B2 (en) Information processing system, translation method, and program therefor
US11003439B2 (en) Incorporating version control into packaging
US11977477B2 (en) System and method for identification of web elements used in automation test case
CN113723082B (en) Method and device for detecting Chinese pinyin from text
CN116775830A (en) Online technical document searching method, device and medium
CN110928896A (en) Data query method and device
CN111813749B (en) File filtering method and device, electronic equipment and storage medium
JP5932707B2 (en) Computer, program, and data generation method
CN114816364A (en) Method, device and application for dynamically generating template file based on Swagger
US7523031B1 (en) Information processing apparatus and method capable of processing plurality type of input information
CN114281688A (en) Codeless or low-code automatic case management method and device
CN113342749A (en) File path matching method, device, equipment and computer readable storage medium
CN111144135A (en) Entry conversion method, device, equipment and readable medium
US10789245B2 (en) Semiconductor parts search method using last alphabet deletion algorithm

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination