Code file generation method, computer device and readable storage medium

Through automated methods, using comparison files to generate code files of different language types, solving the problem of low efficiency in the generation of international code files in the existing technology, and achieving efficient and automated international code file generation.

CN113760361BActive Publication Date: 2025-05-06DAWNING INT INFORMATION IND CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110942043.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-17
Publication Date
2025-05-06
Estimated Expiration
2041-08-17

AI Technical Summary

Technical Problem

In the prior art, the generation of international code files requires a lot of labor costs and time, and is less efficient.

Method used

By obtaining the original code file of the target project and automatically determining the multilingual translation text of each string with the comparison file, code files of different language types are generated.

Benefits of technology

It realizes automatic generation of international code files, reduces generation costs, improves creation efficiency, and avoids the steps of manual translation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760361B_ABST
    Figure CN113760361B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a code file generation method, a computer device and a readable storage medium. The method includes: obtaining the original code file of the target project; the original code file includes multiple key-value pairs, the key-value pairs include keywords and keyword values, and the keyword value is a string of the first language type; according to the reference file, the translation text of each string of the first language type in the original code file in multiple language types is determined; the reference file is used to indicate the translation text of the keyword value related to the target project in multiple language types; according to the translation text of each string of the first language type in multiple language types and the original code file, a code file corresponding to each language type in multiple language types is generated. It can reduce the generation cost of internationalized code files and improve the creation efficiency of internationalized code files.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code file generation method, a computer device, and a readable storage medium. Background Art

[0002] Some scripts required for computer operation usually include key-value pairs, which include key and value, where key can be a parameter name and value can be a parameter value. When docking some international projects, it is necessary to internationalize the scripts and convert them into internationalized scripts (or internationalized code files). The internationalization adaptation of scripts mainly involves the translation of values. For example, if the value in the key-value pair is "time", "time" can be translated into "time" to generate an internationalized script.

[0003] At present, programmers are mainly required to manually compile internationalization files and compile values ​​into English and other languages. However, this method requires a lot of manpower and time, and is very inefficient. Summary of the invention

[0004] The embodiments of the present application provide a code file generation method, a computer device, and a readable storage medium, which can reduce the generation cost of internationalized code files and improve the creation efficiency of internationalized code files.

[0005] In a first aspect, a method for generating a code file is provided, the method comprising:

[0006] Obtaining an original code file of a target project; the original code file includes a plurality of key-value pairs, the key-value pairs include a keyword and a value of the keyword, and the value of the keyword is a string of the first language type;

[0007] Determine the translation texts of each character string of the first language type in the original code file in multiple language types according to the reference file; the reference file is used to indicate the translation texts of the values ​​of the keywords related to the target project in multiple language types;

[0008] A code file corresponding to each of the multiple language types is generated according to the translation texts of each character string of the first language type in the multiple language types and the original code file.

[0009] In the present application, after the server obtains the original code file of the project, it can automatically load the reference file to determine the translation value of each value in the original code file. It can further automatically generate code files of other language types (also called internationalization files, internationalization code files) according to the value translation value, thereby realizing the automatic generation of internationalization files, saving the generation cost of internationalization files, and improving the creation efficiency of internationalization files.

[0010] In combination with the first aspect, in a first possible implementation manner of the first aspect, the comparison file includes keywords related to the target project and a comparison part; the comparison part includes translation texts of the keyword values ​​in multiple language types;

[0011] The first character is included between the comparison parts of the keywords, and the second character is included between the translation texts in different language types in the comparison parts.

[0012] In the present application, by limiting the format of the comparison file, the server can accurately identify the translation texts of various language types according to the specific separation characters in the comparison file after reading the comparison file. For example, the comparison part in the comparison file, that is, the translation text part, can be accurately identified according to the first character, and the translation texts in different languages ​​can also be accurately identified according to the second character.

[0013] In combination with the first aspect, in a first possible implementation of the first aspect, determining, according to the reference file, translation texts of each character string of the first language type in the original code file in multiple language types includes:

[0014] For each character string of the first language type, searching a reference file according to a keyword corresponding to the character string of the first language type, and determining a reference part corresponding to the keyword from the reference file;

[0015] Extract translation texts of a character string of a first language type in multiple language types from the comparison part corresponding to the keyword.

[0016] In the present application, a specific implementation method for generating code files of different language types based on a reference file is provided. By identifying the reference part of the keyword, the translation text of the keyword value in different language types is extracted from the reference part of the keyword, so that code files in different language types can be generated based on the identified translation text, avoiding manual translation, reducing the generation cost of internationalized code files, automatically generating internationalized code files, and improving the generation efficiency of internationalized code.

[0017] In combination with the first aspect, in a first possible implementation of the first aspect, a code file corresponding to each of the multiple language types is generated according to the translation texts of each character string of the first language type in multiple language types and the original code files, including:

[0018] According to the storage path corresponding to the second language type, the translation text of the string of the first language type in the second language type and the keyword corresponding to the string of the first language type are written to generate a code file of the second language type; the second language type is any one of multiple language types.

[0019] In this application, a specific implementation method for generating internationalized code files is provided. After obtaining the translated text of each keyword, the keyword and the translated text can be written into a storage path corresponding to the language type according to the language type. Code files of different language types are isolated through different storage paths to ensure that the generated code files can support effective reading and writing.

[0020] In conjunction with the first aspect, in a first possible implementation manner of the first aspect, a process of generating a reference file includes:

[0021] Determine the keywords related to the project, and determine the translation texts of the keywords related to the target project in multiple languages;

[0022] If the translation text includes the first character, the first character in the translation file is replaced with a preset indicator character.

[0023] In the present application, conflicts between characters in the translated text and the separator characters between KV are avoided. For example, characters in the translated text that are identical to the separator characters can be replaced to avoid errors in identifying keywords and reference parts based on the reference file, thereby avoiding errors in translation text recognition and improving the accuracy of automatically generated internationalized code files.

[0024] In combination with the first aspect, in a first possible implementation manner of the first aspect, the method further includes:

[0025] For a code file corresponding to each of the multiple language types, if the value of the keyword in the code file includes a preset indicator character, the indicator character is replaced with the first character.

[0026] In the present application, after replacing the separator characters in the original translation text, after generating code files of different language types, the indicator characters in the code file can be restored to separator characters to ensure the accuracy of the translation text in the code file.

[0027] In combination with the first aspect, in a first possible implementation manner of the first aspect, the method further includes:

[0028] For each keyword in the original code file, if the comparison file does not include the keyword, a translation request is sent to the external server; the translation request is used to instruct the external server to determine the first language type string corresponding to the keyword and the translation text in multiple language types;

[0029] The translated text of the first language type string corresponding to the keyword is obtained from the external server, and the translated text of the first language type string corresponding to the first keyword is written into a code file of the corresponding language type.

[0030] In the present application, when certain keywords are not recorded in the reference file, an 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 results returned by the external server, and a complete code file can be generated, thereby avoiding missing the translated text of the value of certain keywords in the final code file.

[0031] In a second aspect, a code file generating device is provided, comprising:

[0032] An acquisition unit is used to acquire an original code file of a target project; the original code file includes a plurality of key-value pairs, the key-value pairs include a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;

[0033] A determination unit, configured to determine translation texts of each character string of the first language type in the original code file in multiple language types according to a reference file; the reference file is configured to indicate translation texts of the values ​​of keywords related to the target project in multiple language types;

[0034] The generating unit is used to generate a code file corresponding to each language type in multiple language types according to the translation text of each character string of the first language type in multiple language types and the original code file.

[0035] In a third aspect, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the method according to the first aspect or any one of the first aspects when executing the computer program.

[0036] According to a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, the method according to the first aspect or any one of the first aspects is implemented.

[0037] The code file generation method, computer device and readable storage medium provided in the embodiments of the present application can automatically load the reference file after the server obtains the original code file of the project, determine the translation value of each value in the original code file according to the reference file, and further automatically generate code files of other language types (also referred to as internationalization files, internationalization code files) according to the translation value of the value, thereby realizing the automatic generation of internationalization files, saving the generation cost of internationalization files, and improving the creation efficiency of internationalization files. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 A schematic diagram of a system architecture provided for an embodiment of the present application;

[0039] Figure 2A flowchart of a code file generation method provided in an embodiment of the present application;

[0040] Figure 3 Another flowchart of the code file generation method provided in the embodiment of the present application;

[0041] Figure 4 Another flowchart of the code file generation method provided in the embodiment of the present application;

[0042] Figure 5 A structural block diagram of a code generation device provided in an embodiment of the present application;

[0043] Figure 6 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0045] First, in order to facilitate the understanding of the technical method provided in the embodiments of the present application, the terms involved in the embodiments of the present application are explained:

[0046] (1) Code files

[0047] The code file in the embodiment of the present application can be called a script. A script is a collection of multiple program commands, and the program commands in the collection are usually stored in an independent executable file. An executable file refers to a file that can be loaded and executed by an operating system. Under different operating system environments, the presentation of executable programs is different. For example, under the Windows operating system, executable files can be types such as ".exe files", ".sys files", and ".com files".

[0048] The script includes a key-value pair, which includes key and value. The key can be the parameter name in the code file, such as time, location, number of loops, etc.; the value is the specific value of the parameter, such as 10:33:10 on June 28, 2021, Xi'an, etc.

[0049] (2) Language type

[0050] The language type in the embodiment of the present application may be the country to which the language belongs, and different types of languages ​​may be Chinese or English.

[0051] The method provided in the embodiment of the present application is applicable to Figure 1The system architecture is shown. Figure 1 The illustrated architecture includes a client 10 and a server 20 , wherein the client 10 may submit a request to generate a code file to the server, and the server 20 may generate a code file in response to the request of the client 10 and send the code file to the client 10 .

[0052] The present application provides a method for generating a code file, which is suitable for Figure 1 The system architecture shown in the figure can be executed by Figure 1 Servers in the architecture shown. Figure 2 As shown, the method comprises the following steps:

[0053] Step 201: Obtain an original code file of a target project; the original code file includes a plurality of key-value pairs, each of which includes a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type.

[0054] In the specific implementation, the user can write the original steps according to the specific docking project, that is, the above-mentioned original code file. The original code file can be the implementation code of certain functions of the target project, or it can be the running code of the target project as a whole. This application does not limit this. Any code file related to the target project can be considered as the original code file described in the embodiment of this application.

[0055] In addition, in order to avoid users manually translating the values ​​in the original code files and generating internationalized codes for various language types, users can submit the original code files through the client and request the server to automatically generate different nationalized code files based on the original code files.

[0056] In a possible implementation, 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.

[0057] It should be noted that the keyword is the key in the key-value pair, which can be some parameters related to the target project; the value of the keyword can be the actual value of the parameter. The first language type is a language type, for example, the value of the keyword in the key-value pair is a Chinese string.

[0058] Step 202: Determine the translation texts of each character string of the first language type in the original code file in multiple language types according to the comparison file.

[0059] Among them, the comparison file can be generated according to the needs of the target project, and can indicate the translation texts of the values ​​of keywords related to the target project in multiple language types, and different translation texts can support the target project to adapt to different development needs. Exemplarily, the comparison file can indicate multiple translation texts of the values ​​of some keywords related to the target project, for example, English, Korean, Italian, etc.

[0060] In a specific implementation, each value in the original code file is traversed, and the reference file is searched to determine one or more translation texts corresponding to the value. For example, the English translation string corresponding to each Chinese string in the original code of the Chinese version can be determined according to the reference file.

[0061] Step 203: Generate a code file corresponding to each of the multiple language types according to the translation texts of each character string of the first language type in the multiple language types and the original code file.

[0062] In a specific implementation, for each keyword in the original code, the keyword is combined with the translation text corresponding to the keyword obtained in step 202 to generate a code file of another language type.

[0063] For example, the original code file includes N keywords, and the values ​​of the N keywords are N Chinese character strings. In step 202, the N English character strings corresponding to the N Chinese character strings can be determined according to the reference file, and the N keywords and the N English character strings are combined one-to-one to generate an English code file.

[0064] In a possible implementation, the embodiment of the present application Figure 2 The method shown is executed in the Nodejs environment. Specifically, first define the following file directory:

[0065] Input

[0066] ----need.json

[0067] Output

[0068] ----need-en.js

[0069] ----need-zh.js

[0070] Among them, "Input" represents the input of the program, "need.json" is the reference file mentioned above, "Output" represents the output of the program, "need-Zh.js" is the Chinese code file, and "need-en.js" is the English code file. It should be noted that the output code file is not limited to the above-mentioned "need-en.js" and "need-Zh.js", but can also be a code file of other language types. The language type of the output code file depends on the translated text in the reference file.

[0071] In the specific implementation, the Index.js file is also defined. The program code in the Index.js file is used to execute Figure 2When the server runs the node. / index.js. / output. / input / need.json command, the method described in the embodiment of the present application can be executed in the Nodejs environment, for example, calling the need.json file, and the need.json file outputs need-en.js and need-Zh.js.

[0072] In the method provided in the embodiment of the present application, after the server obtains the original code file of the project, it can automatically load the reference file to determine the translation value of each value in the original code file, and further can automatically generate code files of other language types (also referred to as internationalization files, internationalization code files) according to the value translation value, thereby realizing the automatic generation of internationalization files, saving the generation cost of internationalization files, and improving the creation efficiency of internationalization files.

[0073] In a possible implementation, the embodiment of the present application further provides a specific format of a comparison file. Specifically, the comparison file includes keywords related to the target project and a comparison part; the comparison part includes translation texts of the keyword values ​​in multiple language types;

[0074] The first character is included between the comparison parts of the keywords, and the second character is included between the translation texts in different language types in the comparison parts.

[0075] Taking Nodejs as an example, when the method described in the embodiment of the present application is executed in the Nodejs environment, the format of the reference file also has the following limitations:

[0076] (1) The reference file is in json format;

[0077] (2) The value of the keyword in the comparison file is the value used in the target project;

[0078] (3) Keywords and values ​​in the comparison file are separated by characters. For example, key and value are separated by commas.

[0079] In the method provided in the embodiment of the present application, by limiting the format of the comparison file, the server can accurately identify the translation texts of various language types according to the specific separation characters in the comparison file after reading the comparison file. For example, the comparison part in the comparison file, that is, the translation text part, can be accurately identified according to the first character, and the translation texts in different languages ​​can also be accurately identified according to the second character.

[0080] In one possible implementation, in the method provided in the embodiment of the present application, the server can traverse each keyword in the original code file, determine the translation text of the value of each keyword, and can also construct code files of different language types based on the translation text of the value of each keyword.

[0081] Exemplarily, the specific implementation steps of determining the translation texts of each string of the first language type in the original code file in multiple language types according to the reference file are as follows: Figure 3 As shown:

[0082] Step 301 : for each character string of the first language type, a reference file is searched according to a keyword corresponding to the character string of the first language type, and a reference part corresponding to the keyword is determined from the reference file.

[0083] In a specific implementation, each keyword in the original code file is traversed, and the comparison file is searched to determine the comparison part corresponding to the value of the keyword (ie, the character string of the first language type corresponding to the keyword).

[0084] Exemplarily, after loading the comparison file, the keywords and comparison parts in the comparison file can be identified according to the first character, so that the comparison part corresponding to each keyword can be determined. For example, the comparison file includes the following content:

[0085] Project key parameter 1 (key1), Chinese string 1@English string 1@Korean string 1;

[0086] Project key parameter 2 (key2), Chinese string 2@English string 2@Korean string 2;

[0087] Project key parameter 3 (key3), Chinese string 3@English string 3@Korean string 3;

[0088] …

[0089] In the above comparison file, "," is the first character mentioned above, and "@" is the second character mentioned above. According to the first character "," the comparison part of key1 can be identified as "Chinese string 1@English string 1@Korean string 1", the comparison part corresponding to key2 is "Chinese string 2@English string 2@Korean string 2", and the comparison part corresponding to key3 is "Chinese string 3@English string 3@Korean string 3".

[0090] Step 302: extract translation texts of the character string of the first language type in multiple language types from the comparison part corresponding to the keyword.

[0091] In a specific implementation, the translation texts in different language types are identified from the comparison texts corresponding to the respective keywords according to the second character.

[0092] Referring to the example of step 301, three language types of translation texts can be extracted from the comparison part of key1 according to the second character "@", namely "Chinese string 1", "English string 1" and "Korean string 1". Similarly, three language types of translation texts can be extracted from the comparison part of key1, which will not be described in detail here.

[0093] The embodiment of the present application provides a specific implementation method for generating code files of different language types based on a reference file. By identifying the reference part of the keyword, the translation text of the keyword value in different language types is extracted from the reference part of the keyword, so that code files in different language types can be generated based on the identified translation text, avoiding manual translation, reducing the generation cost of internationalized code files, automatically generating internationalized code files, and improving the generation efficiency of internationalized code.

[0094] In the embodiment of the present application, the translation text of the keyword value can be written according to the specified path to generate code files of other language types. Specifically, the specific implementation method of generating code files corresponding to each language type in multiple language types based on the translation text of each string of the first language type in multiple language types and the original code file includes:

[0095] According to the storage path corresponding to the second language type, the translation text of the string of the first language type in the second language type and the keyword corresponding to the string of the first language type are written to generate a code file of the second language type; the second language type is any one of the multiple language types involved in the reference file.

[0096] That is to say, for each language type involved in the reference file, the storage path of the code file corresponding to the language type is pre-set. For example, the storage path of need-en.js mentioned above is the storage path of the English code file. After obtaining the translation text corresponding to each keyword in the original code from the reference file, different storage paths are distinguished by language type, and the translation texts of different language types and corresponding keywords are written in different storage paths to generate code files of different language types.

[0097] 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 need-en.js to generate an English code file.

[0098] The method provided in the embodiment of the present application provides a specific implementation method for generating an internationalized code file. After obtaining the translated text of each keyword, the keyword and the translated text can be written into a storage path corresponding to the language type according to the language type. Code files of different language types are isolated through different storage paths to ensure that the generated code file can support effective reading and writing.

[0099] In one possible implementation, when generating a comparison file, if the translation text of the keyword value includes a separator character between the keyword and the value, the character in the translation text can be replaced with other characters to avoid errors in recognizing the keyword and the comparison part after obtaining the comparison file, thereby failing to recognize the correct translation text. It should be noted that the separator character is used to separate the keyword and the comparison part of the keyword, which is conducive to the server accurately recognizing the keyword and the comparison part.

[0100] For example, Figure 2 The method shown includes: determining keywords related to the target project, determining translation texts of the values ​​of each keyword in the multiple language types; if the translation text includes a first character, replacing the first character in the translation file with a preset indicator character.

[0101] For example, the key and the comparison part in the comparison file are separated by ",", with the key before "," and the comparison part after ",". If the translation text under a certain language type in the comparison part includes ",", the "," in the translation text will be replaced with other characters to avoid errors when identifying the comparison part.

[0102] In the method provided in the embodiment of the present application, conflicts between characters in the translated text and the separator characters between KV are avoided. For example, characters in the translated text that are identical to the separator characters can be replaced to avoid errors in identifying keywords and reference parts based on the reference file, thereby avoiding errors in translation text recognition and improving the accuracy of automatically generated internationalized code files.

[0103] In a possible implementation, if the preset indicator character exists in the translated text of the code file, it indicates that the original translated text includes the first character. To ensure the accuracy of the translated text, the translated text in the code file may be restored to the first character.

[0104] Exemplarily, after the code files corresponding to the multiple language types are generated, for the code files corresponding to each of the multiple language types, if the value of the keyword in the code file includes a preset indicator character, the indicator character is replaced with the first character.

[0105] In the method provided in the embodiment of the present application, after replacing the separator characters in the original translation text, after generating code files of different language types, the indicator characters in the code file can be restored to separator characters to ensure the accuracy of the translation text in the code file.

[0106] In a possible implementation, if the comparison part of a 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.

[0107] Exemplarily, for each keyword in the original code file, if the keyword is not included in the reference file, a translation request is sent to the external server. The translation request is used to instruct the external server to determine the first language type string corresponding to the keyword, and the translation text in multiple language types;

[0108] The translated text of the first language type string corresponding to the keyword is obtained from the external server, and the translated text of the first language type string corresponding to the first keyword is written into a code file of the corresponding language type.

[0109] It should be noted that the type of translation text requested depends on the language type involved in the comparison file. For example, if the comparison file includes Korean values ​​and English values ​​corresponding to keywords, for keywords not recorded in the comparison file, the external server is requested to translate the value of the keyword in the original file into Korean and English.

[0110] In a specific implementation, the external server may be a web server, and the translation of value is implemented with the help of web services.

[0111] In the method provided in the embodiment of the present application, when certain keywords are not recorded in the reference file, an 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 results returned by the external server, and a complete code file can be generated, thereby avoiding missing the translation text of the value of certain keywords in the final code file.

[0112] The following takes the nodejs environment as an example to introduce in detail the code file generation method provided by the embodiment of the present application. Figure 4 As shown, the method comprises the following steps:

[0113] Step 401: Obtain the original code file of the target project, where the value of each keyword in the original code file is a Chinese character string.

[0114] In a specific implementation, the server may obtain the original code file submitted by the client to automatically generate code files of various language types according to the original code file.

[0115] Step 402: read the need.json file through the fs.readFile method, and obtain N target strings corresponding to each keyword in the original code file from the need.json file.

[0116] In a specific implementation, the need.json file is loaded in the nodejs environment, and the fs.readFile method can also be used to identify the translation text of each keyword from the need.json file (i.e., the reference file described in the embodiment of the present application), i.e., the target string described in the embodiment of the present application, and the target string can be an English string. N is the number of language types involved in the need.json file. For example, the need.json file includes the English translation text and the Korean translation text of value, then the above N is equal to 2.

[0117] Step 403: convert the N target strings corresponding to each keyword into objects through the JSON.parse function of nodejs.

[0118] Among them, the object can be a minimum unit of code loop execution, converting the target string into an object, that is, converting the data structure of the target string, so that subsequent operations can be executed based on the object to generate code files of each language type.

[0119] Step 404: Start N jobs to read objects and generate code files in N language types.

[0120] In the specific implementation, N jobs correspond to N language types, which are respectively used to read corresponding objects, write the objects to corresponding paths, and generate code files.

[0121] For example, step 402 obtains two character strings corresponding to key1, namely Chinese character string 1 and English character string 1; two character strings corresponding to key2, namely Chinese character string 2 and English character string 2; and two character strings corresponding to key3, namely Chinese character string 3 and English character string 3.

[0122] The Chinese character string 1 and the English character string 1 are converted into objects 11 and 12 respectively, the Chinese character string 2 and the English character string 2 are converted into objects 21 and 22 respectively, and the Chinese character string 3 and the English character string 3 are converted into objects 31 and 32 respectively.

[0123] Start Job 1 and Job 2 to generate need-zh.js (Chinese code file) and need-en.js (English code file) respectively. Specifically, start Job 1 to write objects 11, 21, and 31 into need-zh.js to generate Chinese code files. Start Job 2 to write objects 12, 22, and 32 into need-en.js to generate English code files.

[0124] In a possible implementation, the code files of different language types can be generated only based on the original code files submitted by the client without the need.json file. Exemplarily, step 402 can be replaced by: requesting the translated text of the Chinese string of each keyword from the web server, and obtaining N target strings corresponding to each keyword in the original code file. The N target strings are the translated texts of value in different language types.

[0125] In the specific implementation, the koa service is started in the nodejs environment, and a translation request is sent to the web server through the interface of the web translation page, requesting the web to translate the Chinese strings of each keyword to obtain N target strings corresponding to each keyword.

[0126] It should be noted that in this manner, except for step 402 which can be replaced by the above implementation, the remaining steps are still applicable, and code files of different language types can be generated with the help of the translation function of the web server.

[0127] Figure 4 In the method shown, the server can determine the translation text of the value of each keyword in the original code based on the pre-configured need.json file, or request the web server to translate the value in the original code file, so that code files of different language types can be generated according to the translation text of the value in the original code file, thereby realizing the automatic generation of internationalized code files.

[0128] The present application embodiment provides a code file generating device, such as Figure 5 As shown, the device includes an acquisition unit 501, a determination unit 502 and a generation unit 503.

[0129] In a possible implementation, the acquisition unit 501 is used to acquire an original code file of a target project; the original code file includes a plurality of key-value pairs, the key-value pairs include a keyword and a value of the keyword, and the value of the keyword is a character string of a first language type;

[0130] A determination unit 502 is used to determine the translation texts of each character string of the first language type in the original code file in multiple language types according to the reference file; the reference file is used to indicate the translation texts of the values ​​of the keywords related to the target project in multiple language types;

[0131] The generating unit 503 is used to generate a code file corresponding to each of the multiple language types according to the translation texts of each character string of the first language type in the multiple language types and the original code file.

[0132] In a possible implementation, the comparison file includes keywords related to the target project and a comparison part; the comparison part includes translation texts of the keyword values ​​in multiple language types;

[0133] The first character is included between the comparison parts of the keywords, and the second character is included between the translation texts in different language types in the comparison parts.

[0134] In a possible implementation, the determining unit 502 is specifically configured to, for each character string of the first language type, search a reference file according to a keyword corresponding to the character string of the first language type, and determine a reference portion corresponding to the keyword from the reference file;

[0135] Extract translation texts of a character string of a first language type in multiple language types from the comparison part corresponding to the keyword.

[0136] In a possible implementation, the generation unit 503 is specifically used to write, according to a storage path corresponding to the second language type, a translation text of a string of the first language type in the second language type and a keyword corresponding to the string of the first 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.

[0137] In a possible implementation, the generation process of the comparison file includes: determining keywords related to the target project, and determining translation texts of the values ​​of the keywords related to the target project in multiple language types;

[0138] If the translation text includes the first character, the first character in the translation file is replaced with a preset indicator character.

[0139] In a possible implementation, the generating unit 503 is further configured to, for a code file corresponding to each language type in the multiple language types, replace the indicator character with the first character if the value of the keyword in the code file includes a preset indicator character.

[0140] In a possible implementation, the determination 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 configured to instruct the external server to determine a first language type string corresponding to the keyword and a translation text in multiple language types; and obtain a translation text of the first language type string corresponding to the keyword from the external server;

[0141] 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 the corresponding language type.

[0142] The present application also provides a computer device, which may be the data source device described above. Figure 6 As shown. The computer device includes a processor, a memory and a network interface connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile 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 the operating system and the computer program in the non-volatile storage medium. The database of the computer device can store configuration information, permission information, etc. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, it implements the embodiments of the present application Figure 6 The steps in the method shown are performed by the server.

[0143] For example, when the computer program is executed by a processor, it implements:

[0144] Obtaining an original code file of a target project; the original code file includes a plurality of key-value pairs, the key-value pairs include a keyword and a value of the keyword, and the value of the keyword is a string of the first language type;

[0145] Determine the translation texts of each character string of the first language type in the original code file in multiple language types according to the reference file; the reference file is used to indicate the translation texts of the values ​​of the keywords related to the target project in multiple language types;

[0146] A code file corresponding to each of the multiple language types is generated according to the translation texts of each character string of the first language type in the multiple language types and the original code file.

[0147] In a possible implementation, the comparison file includes keywords related to the target project and a comparison part; the comparison part includes translation texts of the keyword values ​​in multiple language types;

[0148] The first character is included between the comparison parts of the keywords, and the second character is included between the translation texts in different language types in the comparison parts.

[0149] In a possible implementation, when the computer program is executed by a processor, the computer program is implemented to: for each character string of the first language type, search a reference file according to a keyword corresponding to the character string of the first language type, and determine a reference portion corresponding to the keyword from the reference file;

[0150] Extract translation texts of a character string of a first language type in multiple language types from the comparison part corresponding to the keyword.

[0151] In one possible implementation, when the computer program is executed by a processor, it is implemented as follows: according to a storage path corresponding to the second language type, a translation text of a string of the first language type in the second language type and a keyword corresponding to the string of the first language type are written to generate a code file of the second language type; the second language type is any one of a plurality of language types.

[0152] In a possible implementation, the generation process of the comparison file includes: determining keywords related to the target project, and determining translation texts of the values ​​of the keywords related to the target project in multiple language types;

[0153] If the translation text includes the first character, the first character in the translation file is replaced with a preset indicator character.

[0154] In one possible implementation, when the computer program is executed by a processor, the following is achieved: for a code file corresponding to each language type in a plurality of language types, if the value of a keyword in the code file includes a preset indicator character, the indicator character is replaced with the first character.

[0155] In a possible implementation, the computer program is executed by a processor to implement: for each keyword in the original code file, if the comparison file does not include the keyword, a translation request is sent to an external server; the translation request is used to instruct the external server to determine the first language type character string corresponding to the keyword, and the translation text in multiple language types; obtain the translation text of the first language type character string corresponding to the keyword from the external server;

[0156] The translation text of the first language type character string corresponding to the first keyword is written into a code file of the corresponding language type.

[0157] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0158] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0159] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A code file generation method, characterized in that: include: Get the original code file of the target project; The original code file includes a plurality of key-value pairs, each of which includes a keyword and a value of the keyword, wherein the value of the keyword is a character string of a first language type; and the keyword is a parameter related to the target project; The value of the keyword is the actual value of the parameter; Determine the translation texts of each character string of the first language type in the original code file in multiple language types according to the reference file; the reference file is used to indicate the translation texts of the value of the keyword related to the target project in the multiple language types; the reference file includes the keyword related to the target project and a reference part; the reference part includes the translation texts of the value of the keyword in the multiple language types; A code file corresponding to each of the multiple language types is generated according to the translation texts of each character string of the first language type in the multiple language types and the original code file.

2. The method according to claim 1, characterized in that A first character is included between the keyword and the comparison part of the keyword, and a second character is included between the translation texts in different language types in the comparison part.

3. The method according to claim 2, characterized in that The step of determining the translation texts of each character string of the first language type in the original code file in multiple language types according to the reference file includes: For each character string of the first language type, searching the comparison file according to a keyword corresponding to the character string of the first language type, and determining a comparison part corresponding to the keyword from the comparison file; The translation texts of the character string of the first language type in multiple language types are extracted from the comparison part corresponding to the keyword.

4. The method according to claim 1, characterized in that: The generating, according to the translation texts of each character string of the first language type in the multiple language types and the original code file, a code file corresponding to each language type in the multiple language types, comprises: According to the storage path corresponding to the second language type, the translation text of the string of the first language type in the second language type and the keyword corresponding to the string of the first language type are written to generate a code file of the second language type; the second language type is any one of the multiple language types.

5. The method according to claim 2, characterized in that: The generation process of the control file includes: Determine keywords related to the target project, and determine translation texts of values ​​of the keywords related to the target project in the multiple language types; If the translated text includes the first character, the first character in the translated text is replaced with a preset indicator character.

6. The method according to claim 5, characterized in that The method further comprises: For a code file corresponding to each language type in the multiple language types, if the value of a keyword in the code file includes the preset indicator character, the indicator character is replaced with the first character.

7. The method according to claim 1, characterized in that The method further comprises: For each keyword in the original code file, if the comparison file does not include the keyword, a translation request is sent to an external server; the translation request is used to instruct the external server to determine the first language type character string corresponding to the keyword and the translation text in the multiple language types; The translated text of the first language type character string corresponding to the keyword is obtained from the external server, and the translated text of the first language type character string corresponding to the keyword is written into a code file of a corresponding language type.

8. A code file generating device, characterized in that: include: The acquisition unit is used to obtain the original code file of the target project; The original code file includes a plurality of key-value pairs, each of which includes a keyword and a value of the keyword, wherein the value of the keyword is a character string of a first language type; and the keyword is a parameter related to the target project; The value of the keyword is the actual value of the parameter; a determination unit, configured to determine translation texts of each character string of the first language type in the original code file in multiple language types according to a comparison file; the comparison file is configured to indicate translation texts of the value of the keyword related to the target project in the multiple language types; the comparison file includes the keyword related to the target project and a comparison part; the comparison part includes the translation texts of the value of the keyword in the multiple language types; A generating unit is used to generate a code file corresponding to each of the multiple language types according to the translation text of each character string of the first language type in the multiple language types and the original code file.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • A multi-language configuration file generating and displaying method and device and a medium

    CN109284145A