Source code processing method, apparatus and device, and computer readable storage medium

By converting source code into an abstract syntax tree and using the platform to generate data sets, the problems of low efficiency and high intrusiveness of Chinese text conversion were solved, and efficient target language conversion was achieved.

CN120723243APending Publication Date: 2025-09-30BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410369958.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-28
Publication Date
2025-09-30

AI Technical Summary

Technical Problem

In the process of converting Chinese text into the target language in the existing technology, the conversion efficiency is low and the intrusion to the source code is relatively large.

Method used

Convert the source code into an abstract syntax tree, obtain Chinese text and its location information, and generate a data set through the platform, replacing it with the target data structure to avoid manual operations.

Benefits of technology

Improves the efficiency of converting Chinese text into the target language and reduces the intrusion into the source code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120723243A_ABST
    Figure CN120723243A_ABST
Patent Text Reader

Abstract

The invention relates to a source code processing method and device, equipment and a computer readable storage medium, and the method comprises the steps: converting a source code into an abstract syntax tree, obtaining at least one Chinese text in the source code, and obtaining the position information of each Chinese text in the source code; and sending the information to the first platform to obtain a data set corresponding to each Chinese text. And further, receiving a data set, and replacing each Chinese text in the source code with the target data structure according to the data set to obtain a first code. On one hand, when the Chinese text of the source code needs to be converted into the target language, each Chinese text does not need to be manually searched and replaced, and the conversion efficiency is improved; and on the other hand, in the source code development process, when each Chinese text in the source code is replaced with the target data structure, the Chinese text in the source code is not changed, and the code invasiveness is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a source code processing method, apparatus, device, and computer-readable storage medium. Background Art

[0002] With the continuous development of computer technology, devices with computing and data processing functions realize specific application functions by running source code.

[0003] Typically, a project file includes source code, which includes Chinese text. In some scenarios, it is necessary to convert Chinese text into a target text in a target language, for example, converting Chinese text into English text. One way is to manually convert the Chinese text into a function, and then convert the function into a target text in the target language by referencing the JS Object Notation (JSON) file in the project file, where JS is the English abbreviation for JavaScript. JavaScript can usually be translated as JavaScript, which is a programming language mainly used for script programming of special effects and functions of web pages. It is a very powerful scripting language. Another way is to convert the JS file in the project file into an abstract syntax tree (AST). The JS file is a source code file of the JavaScript language. Further, after searching for Chinese text in the AST and automatically converting the Chinese text into a function, the JSON file in the project file is referenced to convert the function into the target text in the target language.

[0004] However, the process of converting Chinese text into target text in the target language in the existing technology has the problems of low conversion efficiency and high intrusion into the source code. Summary of the Invention

[0005] To solve the above technical problems, or at least partially solve the above technical problems, the present disclosure provides a source code processing method, apparatus, device, and computer-readable storage medium. These methods eliminate the need to manually search and replace each Chinese text in the source code when converting it into a target language, thereby improving conversion efficiency. During source code development, replacing each Chinese text in the source code with a target data structure does not alter the Chinese text in the source code, thereby reducing the code's invasiveness.

[0006] In a first aspect, an embodiment of the present disclosure provides a source code processing method, including:

[0007] Converting a source code into an abstract syntax tree, wherein the abstract syntax tree includes at least one Chinese text in the source code and position information of each Chinese text in the source code;

[0008] sending the at least one Chinese text, location information of each Chinese text in the source code, and the target language to a first platform, wherein the first platform is configured to generate a data set including each Chinese text, a target text in the target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text;

[0009] The data set is received from the first platform, and based on the data set, each Chinese text in the source code is replaced with a target data structure to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

[0010] In a second aspect, an embodiment of the present disclosure provides a source code processing method, including:

[0011] receiving at least one Chinese text, location information of each Chinese text in the source code, and a target language from a terminal device, wherein the at least one Chinese text and the location information of each Chinese text in the source code are information included in an abstract syntax tree, and the abstract syntax tree is an abstract syntax tree converted by the terminal device from the source code;

[0012] generating a data set, the data set including each Chinese text, a target text in a target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text;

[0013] The data set is sent to the terminal device, and the terminal device is used to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

[0014] In a third aspect, an embodiment of the present disclosure provides a source code processing apparatus, comprising:

[0015] a conversion module, configured to convert a source code into an abstract syntax tree, wherein the abstract syntax tree includes at least one Chinese text in the source code and position information of each Chinese text in the source code;

[0016] a sending module, configured to send the at least one Chinese text, the location information of each Chinese text in the source code, and the target language to a first platform, wherein the first platform is configured to generate a data set, the data set including each Chinese text, the target text in the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text;

[0017] A receiving module, configured to receive the data set from the first platform;

[0018] A first replacement module is configured to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

[0019] In a fourth aspect, an embodiment of the present disclosure provides a source code processing apparatus, including:

[0020] a receiving module, configured to receive at least one Chinese text, location information of each Chinese text in the source code, and a target language sent by a terminal device, wherein the at least one Chinese text and the location information of each Chinese text in the source code are information included in an abstract syntax tree, and the abstract syntax tree is an abstract syntax tree converted by the terminal device from the source code;

[0021] A generating module, configured to generate a data set, wherein the data set includes each Chinese text, a target text in a target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text;

[0022] A sending module is used to send the data set to the terminal device, and the terminal device is used to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

[0023] In a fifth aspect, an embodiment of the present disclosure provides a source code processing device, including:

[0024] Memory;

[0025] processor; and

[0026] computer programs;

[0027] The computer program is stored in the memory and is configured to be executed by the processor to implement the method as described in the first aspect or the second aspect.

[0028] In a sixth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the method described in the first aspect or the second aspect.

[0029] In a seventh aspect, an embodiment of the present disclosure further provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, the method described in the first aspect or the second aspect is implemented.

[0030] The source code processing method, apparatus, device and computer-readable storage medium provided by the embodiments of the present disclosure convert the source code into an abstract syntax tree to obtain at least one Chinese text in the source code and the position information of each Chinese text in the source code. The at least one Chinese text, the position information of each Chinese text in the source code, and the target language to which the Chinese text needs to be translated are sent to the first platform to obtain a data set corresponding to each Chinese text. Further, the data set is received from the first platform, and based on the data set, each Chinese text in the source code is replaced with a target data structure to obtain a first code. On the one hand, when the Chinese text in the source code needs to be converted into the target language, there is no need to manually search and replace each Chinese text, thereby improving the conversion efficiency; on the other hand, during the source code development process, when each Chinese text in the source code is replaced with a target data structure, the Chinese text in the source code is not changed, thereby reducing the invasiveness of the code. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0032] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0033] Figure 1 A flow chart of a source code processing method provided in an embodiment of the present disclosure;

[0034] Figure 2 A schematic diagram of an application scenario provided by an embodiment of the present disclosure;

[0035] Figure 3A schematic diagram of another application scenario provided by an embodiment of the present disclosure;

[0036] Figure 4 A flow chart of a source code processing method provided by another embodiment of the present disclosure;

[0037] Figure 5 A schematic diagram of the structure of a source code processing device provided in an embodiment of the present disclosure;

[0038] Figure 6 A schematic structural diagram of a source code processing device provided by another embodiment of the present disclosure;

[0039] Figure 7 A schematic diagram of the structure of a source code processing device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0040] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features therein can be combined with each other in the absence of conflict.

[0041] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0042] Typically, a project file includes source code, which includes Chinese text. In some scenarios, it is necessary to convert Chinese text into a target text in a target language, for example, converting Chinese text into English text. One way is to manually convert the Chinese text into a function, and then convert the function into the target text in the target language by referencing the JS Object Notation (JSON) file in the project file, where JS is the abbreviation of JavaScript. JavaScript can usually be translated as JavaScript, a programming language mainly used for script programming of special effects and functions of web pages, and is a very powerful scripting language. Another way is to convert the JS file in the project file into an abstract syntax tree (AST). The JS file is a source code file of the JavaScript language. Further, after searching the Chinese text in the AST and automatically converting the Chinese text into a function, the JSON file in the project file is referenced to convert the function into the target text in the target language. However, the process of converting Chinese text into the target text in the target language in the prior art has the problems of low conversion efficiency and high invasiveness to the source code. To address this problem, the present disclosure provides a source code processing method, which is described below in conjunction with specific embodiments.

[0043] Figure 1 Flowchart of the source code processing method provided by the embodiment of the present disclosure. The method can be executed by a source code processing device, which can be implemented in software and / or hardware. The source code processing device can be configured in an electronic device, such as a server or a terminal device, wherein the terminal device includes but is not limited to a smart phone, a PDA, a tablet computer, a wearable device with a display screen, a desktop computer, a laptop computer, an all-in-one computer, a smart home device, etc. In addition, the server can specifically be a cloud server, a server cluster, a server in a server cluster, etc. In addition, the method can be applied to Figure 2 The application scenario shown includes a terminal device 21 and a server 22. It is understandable that the source code processing method provided in the embodiment of the present disclosure can also be applied in other scenarios.

[0044] The following combination Figure 2 The application scenario shown is Figure 1 The source code processing method shown is introduced, for example, Figure 2 The terminal device in the embodiment can execute the method. The method includes the following specific steps:

[0045] S101: Convert a source code into an abstract syntax tree, where the abstract syntax tree includes at least one Chinese text in the source code and location information of each Chinese text in the source code.

[0046] During the development process, terminal device 21 executes the project's source code to implement specific application functions. During source code processing, terminal device 21 converts the project's source code into an abstract syntax tree (AST). By traversing the nodes in the AST, terminal device 21 obtains at least one Chinese text in the source code and the location of each Chinese text in the source code.

[0047] The terminal device 21 includes three parsers, namely Js parser (JavaScript Parser), Vue parser (pronounced as / vju / , similar to view, VueParser) and Pug parser (renamed from Jade, PugParser). The JS parser uses Babel (compiler) to parse files with the suffix .js / .ts / .jsx and the script code (script element code) in the .vue file into a JS abstract syntax tree (JavaScript Abstract Syntax Tree, JsAST). The compiler traverses the nodes to find at least one Chinese text in the source code and the location information of each Chinese text in the source code; the Vue parser parses files with the suffix .vue into a Vue abstract syntax tree. For the vue syntax in the template code (content template element code) in the .vue file, it finds the templateAST from the VueAST, traverses the nodes, finds at least one Chinese text in the source code, and calculates the location information of each Chinese text in the source code; the Pug parser parses files with the suffix .pug / .jade and the pug template syntax in the template code in the .vue file into a Pug abstract syntax tree, traverses the nodes, finds at least one Chinese text in the source code, and calculates the location information of each Chinese text in the source code. The terminal device 21 can use the above three parsers to convert frameworks, languages, and template engines such as Vue, React (a library for building Web and native interactive interfaces), PUG, JavaScript, and TypeScript (a superset of JavaScript) into abstract syntax trees, and obtain at least one Chinese text in the source code, as well as the location information of each Chinese text in the source code, thereby improving the terminal device's ability to parse different frameworks, languages, and template engines, and improving efficiency by converting the source code into an abstract syntax tree.

[0048] S102: Send the at least one Chinese text, location information of each Chinese text in the source code, and the target language to a first platform, wherein the first platform is configured to generate a data set, the data set including each Chinese text, a target text in the target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text.

[0049] When the terminal device 21 obtains at least one Chinese text in the source code and the position information of each Chinese text in the source code, it sends the at least one Chinese text, the position information of each Chinese text in the source code, and the target language into which the Chinese text needs to be translated to the first platform. In this embodiment, the first platform can be as follows: Figure 2 The server 22 shown is, in other embodiments, the first platform can also be a server cluster consisting of multiple servers or multiple computers. Further, the server 22 generates a data set based on each Chinese text, the target text of the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text.

[0050] S103. Receive the data set from the first platform, and replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

[0051] When the server 22 generates a data set based on each Chinese text, the target text of the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text, the server 22 can store the data set in a storage system associated with the server 22. The storage system can be integrated in the server 22, or the storage system can exist independently of the server 22 and be communicatively connected to the server 22.

[0052] Furthermore, the server 22 can send the data set to the terminal device 21. Upon receiving the data set from the server 22, the terminal device 21 can replace each Chinese text in the source code with a target data structure corresponding to the Chinese text based on the data set, thereby generating the first code. Specifically, the target data structure corresponding to the Chinese text includes an identifier, the Chinese text, the target language, the part of speech corresponding to the Chinese text, and a target text in the target language corresponding to the Chinese text.

[0053] The disclosed embodiment converts source code into an abstract syntax tree, which includes at least one Chinese text in the source code and the location information of each Chinese text in the source code. The at least one Chinese text, the location information of each Chinese text in the source code, and the target language are sent to a first platform. The first platform is configured to generate a data set, which includes each Chinese text, the target text in the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text. The data set is received from the first platform, and based on the data set, each Chinese text in the source code is replaced with a target data structure to obtain a first code. The target data structure corresponding to each Chinese text includes an identifier, the Chinese text, the target language, the part of speech corresponding to the Chinese text, and the target text in the target language corresponding to the Chinese text. This improves conversion efficiency when converting Chinese text in the source code into the target language, as manual search and conversion of each Chinese text into a function is not required. Furthermore, during the source code development process, replacing each Chinese text in the source code with the target data structure does not alter the Chinese text in the source code, reducing the invasiveness of the code.

[0054] On the basis of the above embodiment, according to the data set, each Chinese text in the source code is replaced with a target data structure to obtain a first code, and the method also includes: replacing each target data structure in the first code with an executable function to obtain a second code; packaging the second code and the identification information of the data set to obtain packaged data; and generating a browser page displayed on the terminal device based on the packaged data.

[0055] Specifically, the terminal device 21 replaces each Chinese text in the source code with the target data structure based on the received data set. When the first code is obtained, the terminal device 21 can also convert the first code into an AST through a Js parser, and further traverse each node in the AST to find the location information of the target data structure in the AST, and replace each target data structure in the first code with an executable function to obtain the second code. The terminal device 21 packages the obtained second code and the unique identification information of the data set to obtain packaged data. The terminal device 21 generates a browser page displayed by the terminal device 21 based on the packaged data. The browser page can specifically be a browser page with the target text in the target language.

[0056] Optionally, receiving the data set from the first platform includes: receiving the data set and identification information of the data set from the first platform.

[0057] When the server 22 generates a data set based on each Chinese text, the target text in the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text, it also generates unique identification information for the data set. The terminal device 21 receives the data set and the unique identification information for the data set from the server 22.

[0058] The disclosed embodiment replaces each target data structure in the first code with an executable function to obtain a second code, and then packages the second code and the identification information of the data set to obtain packaged data. Furthermore, a browser page displayed on the terminal device is generated based on the packaged data. By using the unique identification information of the data set of the first platform, data maintenance is facilitated, thereby achieving internationalization.

[0059] On the basis of the above embodiment, according to the data set, each Chinese text in the source code is replaced with a target data structure to obtain a first code, and the method further includes: sending the first code to a second platform, the second platform is used to replace each target data structure in the first code with an executable function to obtain a second code, and packaging the second code and the identification information of the data set to obtain packaged data; receiving the packaged data from the second platform; and generating a browser page displayed by the terminal device according to the packaged data.

[0060] For example Figure 3 The application scenario shown includes a terminal device 21, a server 22, and a server 23. The terminal device 21 sends the obtained first code to a second platform, such as the server 23. Similarly, in other embodiments, the second platform may be a server cluster composed of multiple servers or multiple computers. The server 22 sends the unique identification information of the generated data set to the server 23. The server 23 replaces each target data structure in the obtained first code with an executable function to obtain the second code, and packages the generated second code and the unique identification information of the received data set to obtain packaged data. The server 23 sends the packaged data to the terminal device 21. The terminal device 21 generates a browser page displayed by the terminal device 21 based on the packaged data. The browser page may specifically be a browser page with a target text in the target language.

[0061] In the disclosed embodiment, each target data structure in the first code is replaced with an executable function via a second platform to obtain second code. The second code and the identification information of the data set are packaged to obtain packaged data. Furthermore, the packaged data is sent to a terminal device, which generates a browser page for display on the terminal device. Using the second platform to obtain the packaged data reduces the burden on the terminal device, thereby better achieving internationalization.

[0062] Figure 4 This is a flow chart of a source code processing method provided by another embodiment of the present disclosure, which can be executed by a first platform. The first platform can be Figure 2 Server 22 is shown.

[0063] like Figure 4 As shown, the method includes the following steps:

[0064] S401: Receive at least one Chinese text, location information of each Chinese text in the source code, and a target language from a terminal device, wherein the at least one Chinese text and the location information of each Chinese text in the source code are information included in an abstract syntax tree, and the abstract syntax tree is an abstract syntax tree into which the terminal device converts the source code.

[0065] The server 22 receives at least one Chinese text sent by the terminal device 21 , the location information of each Chinese text in the source code, and the target language into which the Chinese text needs to be translated.

[0066] S402: Generate a data set, where the data set includes each Chinese text, a target text of a target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text.

[0067] The server 22 generates a data set based on the received at least one Chinese text, the location information of each Chinese text in the source code, and the target language into which the Chinese text needs to be translated. The data set includes each Chinese text, the target text in the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text.

[0068] S403. Send the data set to the terminal device, and the terminal device is used to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

[0069] The server 22 sends the generated data set to the terminal device 21. Upon receiving the data set from the server 22, the terminal device 21 can replace each Chinese text in the source code with a target data structure corresponding to the Chinese text, including an identifier, the Chinese text, the target language, the part of speech corresponding to the Chinese text, and the target text in the target language corresponding to the Chinese text, to obtain a first code.

[0070] The embodiment of the present disclosure generates a data set by receiving at least one Chinese text sent by a terminal device, the position information of each Chinese text in the source code, and the target language, wherein the data set includes each Chinese text, the target text of the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text. The data set is sent, and the terminal device replaces each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, any Chinese text, the target language, the part of speech corresponding to any Chinese text, and the target text of the target language corresponding to any Chinese text. On the one hand, when the Chinese text in the source code needs to be converted into the target language, there is no need to manually search and convert each Chinese text into a function, thereby improving the conversion efficiency; on the other hand, during the source code development process, when each Chinese text in the source code is replaced with the target data structure, the Chinese text in the source code will not be changed, thereby reducing the invasiveness of the code.

[0071] On the basis of the above embodiment, a data set is generated, including: for each Chinese text, if the Chinese text is included in the database pre-stored by the first platform, and the Chinese text corresponds to a part of speech in the database, then according to the target language, the Chinese text is translated into a target text in the target language; if the Chinese text is included in the database pre-stored by the first platform, and the Chinese text corresponds to multiple parts of speech in the database, then the Chinese text, the multiple parts of speech and the target language are sent to the terminal device, and after the user of the terminal device selects a part of speech from the multiple parts of speech, the Chinese text is translated into the target text in the target language according to the part of speech selected by the user; if the Chinese text is not included in the database pre-stored by the first platform, the Chinese text is translated into the target text in the target language, and a default part of speech is configured for the Chinese text.

[0072] Server 22 generates a data set based on the received at least one Chinese text, the location of each Chinese text in the source code, and the target language into which the Chinese text is to be translated. When generating the data set, server 22 processes each Chinese text. If the Chinese text exists in a database pre-stored by server 22 and corresponds to a part of speech, server 22 translates the Chinese text into the target language according to the target language into which the Chinese text is to be translated.

[0073] If the Chinese text exists in the database pre-stored by server 22, but the Chinese text has multiple parts of speech in the database, the Chinese text, the multiple parts of speech, and the target language are sent to terminal device 21. After the user of terminal device 21 selects the desired part of speech from the multiple parts of speech, server 22 translates the Chinese text into a target text in the target language based on the part of speech selected by the user of terminal device 21.

[0074] If the Chinese text does not exist in the database pre-stored in the server 22, then after translating the Chinese text into a target text in the target language, a default part of speech is assigned to the Chinese text.

[0075] Optionally, after generating the data set, the method further includes: configuring identification information for the data set.

[0076] After generating a data set based on the received at least one Chinese text, the location information of each Chinese text in the source code, and the target language into which the Chinese text needs to be translated, the server 22 configures identification information for the data set.

[0077] The disclosed embodiment generates a data set based on at least one received Chinese text, the location of each Chinese text in the source code, and the target language into which the Chinese text is to be translated, and configures identification information for the data set. The user selects the appropriate target language text based on the part of speech of the Chinese text being used, resulting in a more accurate translation of the target language text.

[0078] Figure 5 This is a schematic diagram of the structure of the source code processing device provided in the embodiment of the present disclosure. The source code processing device is configured in a terminal device. For example, the source code processing device can be the terminal device 21 described in the above embodiment, or the source code processing device can be a component or assembly in the terminal device 21. The source code processing device provided in the embodiment of the present disclosure can execute the processing flow provided in the source code processing method embodiment, such as Figure 5As shown, the source code processing device 50 includes: a conversion module 51, a sending module 52, a receiving module 53, and a first replacement module 54. The conversion module 51 is configured to convert the source code into an abstract syntax tree, wherein the abstract syntax tree includes at least one Chinese text in the source code and location information of each Chinese text in the source code. The sending module 52 is configured to send the at least one Chinese text, the location information of each Chinese text in the source code, and the target language to a first platform, wherein the first platform is configured to generate a data set, wherein the data set includes each Chinese text, a target text in the target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text. The receiving module 53 is configured to receive the data set from the first platform. The first replacement module 54 is configured to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and the target text in the target language corresponding to the any Chinese text.

[0079] Optionally, the source code processing device 50 further includes:

[0080] a second replacement module 55 for replacing each Chinese text in the source code with a target data structure according to the data set to obtain a first code, and then replacing each target data structure in the first code with an executable function to obtain a second code;

[0081] a packaging module 56, configured to package the second code and the identification information of the data set to obtain packaged data;

[0082] The generating module 57 is configured to generate a browser page displayed on the terminal device according to the packaged data.

[0083] Optionally, when the receiving module 53 receives the data set from the first platform, it is specifically configured to: receive the data set and identification information of the data set from the first platform.

[0084] Optionally, the sending module 52 is further configured to: after the first replacing module replaces each Chinese text in the source code with a target data structure based on the data set to obtain a first code, send the first code to a second platform; the second platform is configured to replace each target data structure in the first code with an executable function to obtain a second code; and package the second code and the identification information of the data set to obtain packaged data;

[0085] The receiving module 53 is further configured to: receive the packaged data from the second platform;

[0086] The source code processing apparatus further includes: a generating module 57, configured to generate a browser page displayed by the terminal device according to the packaged data.

[0087] Figure 5 The source code processing device of the illustrated embodiment can be used to execute the technical solution of the above method embodiment. Its implementation principle and technical effects are similar and will not be described in detail here.

[0088] Figure 6 This is a schematic diagram of the structure of the source code processing device provided in the embodiment of the present disclosure. The source code processing device is configured on the first platform. For example, the source code processing device can be the server 22 described in the above embodiment, or the source code processing device can be a component or assembly in the server 22. The source code processing device provided in the embodiment of the present disclosure can execute the processing flow provided in the source code processing method embodiment, such as Figure 6 As shown, the source code processing device 60 includes: a receiving module 61, a generating module 62, and a sending module 63; wherein the receiving module 61 is configured to receive at least one Chinese text, position information of each Chinese text in the source code, and a target language sent by a terminal device, wherein the at least one Chinese text and the position information of each Chinese text in the source code are information included in an abstract syntax tree, and the abstract syntax tree is the abstract syntax tree into which the terminal device converts the source code; the generating module 62 is configured to generate a data set, wherein the data set includes each Chinese text, a target text in the target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text; and the sending module 63 is configured to send the data set to the terminal device, wherein the terminal device is configured to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and the target text in the target language corresponding to the any Chinese text.

[0089] Optionally, when generating the data set, the generating module 62 is specifically configured to:

[0090] For each Chinese text, if the Chinese text is included in the database pre-stored in the first platform and the Chinese text has a corresponding part of speech in the database, then translating the Chinese text into a target text in the target language according to the target language;

[0091] If the Chinese text is included in a database pre-stored in the first platform, and the Chinese text corresponds to multiple parts of speech in the database, the Chinese text, the multiple parts of speech, and the target language are sent to the terminal device. After a user of the terminal device selects a part of speech from the multiple parts of speech, the Chinese text is translated into a target text in the target language according to the part of speech selected by the user.

[0092] If the Chinese text is not included in the database pre-stored in the first platform, the Chinese text is translated into a target text in the target language, and a default part of speech is configured for the Chinese text.

[0093] Optionally, the source code processing device 60 further includes: a configuration module 64, configured to configure identification information for the data set.

[0094] Figure 6 The source code processing device of the illustrated embodiment can be used to execute the technical solution of the above method embodiment. Its implementation principle and technical effects are similar and will not be described in detail here.

[0095] Figure 7 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. The electronic device may be a terminal as described in the above embodiment. The electronic device provided by an embodiment of the present disclosure may execute the processing flow provided by the source code processing method embodiment, such as Figure 7 As shown, the electronic device 70 includes: a memory 71, a processor 72, a computer program and a communication interface 73; wherein the computer program is stored in the memory 71 and is configured so that the processor 72 executes the source code processing method described above.

[0096] In addition, an embodiment of the present disclosure further provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the source code processing method described in the above embodiment.

[0097] In addition, an embodiment of the present disclosure further provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, the source code processing method described above is implemented.

[0098] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0099] The foregoing description is intended only to provide specific embodiments of the present disclosure, intended to enable those skilled in the art to understand and implement the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but rather to be construed in the broadest manner consistent with the principles and novel features disclosed herein.

Claims

1. A source code processing method, characterized in that: The method is applied to a terminal device, and the method includes: Converting a source code into an abstract syntax tree, wherein the abstract syntax tree includes at least one Chinese text in the source code and position information of each Chinese text in the source code; sending the at least one Chinese text, location information of each Chinese text in the source code, and the target language to a first platform, wherein the first platform is configured to generate a data set including each Chinese text, a target text in the target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text; The data set is received from the first platform, and based on the data set, each Chinese text in the source code is replaced with a target data structure to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

2. The method according to claim 1, characterized in that After replacing each Chinese text in the source code with a target data structure based on the data set to obtain a first code, the method further includes: Replacing each target data structure in the first code with an executable function to obtain a second code; Packaging the second code and the identification information of the data set to obtain packaged data; A browser page displayed on the terminal device is generated according to the packaged data.

3. The method according to claim 2, characterized in that Receiving the data set from the first platform includes: The data set and identification information of the data set are received from the first platform.

4. The method according to claim 1, wherein After replacing each Chinese text in the source code with a target data structure based on the data set to obtain a first code, the method further includes: Sending the first code to a second platform, the second platform being configured to replace each target data structure in the first code with an executable function to obtain a second code, and packaging the second code and identification information of the data set to obtain packaged data; receiving the packaged data from the second platform; A browser page displayed on the terminal device is generated according to the packaged data.

5. A source code processing method, characterized in that: The method is applied to a first platform and includes: receiving at least one Chinese text, location information of each Chinese text in the source code, and a target language from a terminal device, wherein the at least one Chinese text and the location information of each Chinese text in the source code are information included in an abstract syntax tree, and the abstract syntax tree is an abstract syntax tree converted by the terminal device from the source code; generating a data set, the data set including each Chinese text, a target text in a target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text; The data set is sent to the terminal device, and the terminal device is used to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

6. The method according to claim 5, characterized in that Generate a data set, including: For each Chinese text, if the Chinese text is included in the database pre-stored in the first platform and the Chinese text has a corresponding part of speech in the database, then translating the Chinese text into a target text in the target language according to the target language; If the Chinese text is included in a database pre-stored in the first platform, and the Chinese text corresponds to multiple parts of speech in the database, the Chinese text, the multiple parts of speech, and the target language are sent to the terminal device. After a user of the terminal device selects a part of speech from the multiple parts of speech, the Chinese text is translated into a target text in the target language according to the part of speech selected by the user. If the Chinese text is not included in the database pre-stored in the first platform, the Chinese text is translated into a target text in the target language, and a default part of speech is configured for the Chinese text.

7. The method according to claim 5 or 6, characterized in that After generating the data set, the method further includes: The data set is configured with identification information.

8. A source code processing device, characterized in that: The device is configured in a terminal device, and includes: a conversion module, configured to convert a source code into an abstract syntax tree, wherein the abstract syntax tree includes at least one Chinese text in the source code and position information of each Chinese text in the source code; a sending module, configured to send the at least one Chinese text, the location information of each Chinese text in the source code, and the target language to a first platform, wherein the first platform is configured to generate a data set, the data set including each Chinese text, the target text in the target language corresponding to each Chinese text, and the part of speech corresponding to each Chinese text; A receiving module, configured to receive the data set from the first platform; A first replacement module is configured to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

9. The device according to claim 8, characterized in that The device further comprises: a second replacement module configured to, after the first replacement module replaces each Chinese text in the source code with a target data structure based on the data set to obtain a first code, replace each target data structure in the first code with an executable function to obtain a second code; a packaging module, configured to package the second code and the identification information of the data set to obtain packaged data; A generating module is used to generate a browser page displayed by the terminal device according to the packaged data.

10. The device according to claim 9, characterized in that When the receiving module receives the data set from the first platform, it is specifically configured to: receive the data set and identification information of the data set from the first platform.

11. The device according to claim 8, characterized in that The sending module is further configured to: after the first replacing module replaces each Chinese text in the source code with a target data structure based on the data set to obtain a first code, send the first code to a second platform; the second platform is configured to replace each target data structure in the first code with an executable function to obtain a second code; and package the second code and the identification information of the data set to obtain packaged data; The receiving module is further configured to: receive the packaged data from the second platform; The apparatus further includes: a generating module configured to generate a browser page displayed by the terminal device according to the packaged data.

12. A source code processing device, characterized in that: The device is configured on a first platform, and includes: a receiving module, configured to receive at least one Chinese text, location information of each Chinese text in the source code, and a target language sent by a terminal device, wherein the at least one Chinese text and the location information of each Chinese text in the source code are information included in an abstract syntax tree, and the abstract syntax tree is an abstract syntax tree converted by the terminal device from the source code; A generating module, configured to generate a data set, wherein the data set includes each Chinese text, a target text in a target language corresponding to each Chinese text, and a part of speech corresponding to each Chinese text; A sending module is used to send the data set to the terminal device, and the terminal device is used to replace each Chinese text in the source code with a target data structure based on the data set to obtain a first code, wherein the target data structure corresponding to any Chinese text includes an identifier, the any Chinese text, the target language, the part of speech corresponding to the any Chinese text, and a target text in the target language corresponding to the any Chinese text.

13. The device according to claim 12, characterized in that When the generating module generates a data set, it is specifically used to: For each Chinese text, if the Chinese text is included in the database pre-stored in the first platform and the Chinese text has a corresponding part of speech in the database, then translating the Chinese text into a target text in the target language according to the target language; If the Chinese text is included in a database pre-stored in the first platform, and the Chinese text corresponds to multiple parts of speech in the database, the Chinese text, the multiple parts of speech, and the target language are sent to the terminal device. After a user of the terminal device selects a part of speech from the multiple parts of speech, the Chinese text is translated into a target text in the target language according to the part of speech selected by the user. If the Chinese text is not included in the database pre-stored in the first platform, the Chinese text is translated into a target text in the target language, and a default part of speech is configured for the Chinese text.

14. The device according to claim 12 or 13, characterized in that The device further includes: a configuration module, configured to configure identification information for the data set.

15. An electronic device, characterized in that: include: Memory; processor; as well as computer programs; The computer program is stored in the memory and configured to be executed by the processor to implement the method according to any one of claims 1 to 7.

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