Internationalization processing method and device of codes, electronic equipment and storage medium

By traversing the source code files, using babel parser and Webpack tools to automatically process international functions in the code, solving the problems of inefficient and error-prone traditional international processing, and is suitable for large-scale software development projects.

CN119127141APending Publication Date: 2024-12-13SHANGHAI ECAR TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411143250.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-19
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

In projects with large code volume and frequent updates, traditional international processing methods are inefficient and prone to errors, and require manual processing of Chinese text in the code file.

Method used

By traversing the source code file, using the babel parser to obtain the abstract syntax tree, find the part to be processed internationally, determine the translation identification information, create the international function, and replace it with the source code file. Use the Webpack module packaging tool to build it Automatically realize international processing.

Benefits of technology

It realizes international processing automation in code files, improves efficiency, reduces human operation errors, and is suitable for large-scale software development projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127141A_ABST
    Figure CN119127141A_ABST
Patent Text Reader

Abstract

The invention provides a code internationalization processing method and device, electronic equipment and a storage medium. The method comprises the following steps: traversing a source code file, and searching a part to be internationalized in the source code file; determining translation identification information corresponding to the part to be internationalized; creating an internationalization function of the translation identification information; and replacing the part to be internationalized in the source code file with the internationalized function. According to the method, the internationalization function does not need to be manually inserted into the part to be subjected to internationalization processing in the code writing process, the method is suitable for software development projects with large code quantity and frequent updating, the internationalization processing efficiency is high, and errors are not prone to occurring.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a method, device, electronic device and storage medium for internationalizing a code. Background Art

[0002] In software development, especially when it comes to project development with multi-language support, the language used by developers during development is different from the language that needs to be displayed on the front end (for example, the text is in Chinese, but needs to be displayed in English or Korean, etc.). Therefore, internationalization of code files (such as i18n, the first and last characters of Internationalization are I and n, and 18 is the number of characters in the middle) is a very important step in the development process.

[0003] At present, the traditional internationalization method is that developers manually internationalize Chinese text in code files during the code development process. In projects with large amounts of code and frequent updates, this method is inefficient and prone to errors. Summary of the invention

[0004] The present application provides a method, device, electronic device and storage medium for internationalizing a code, which are used to solve the problem that some texts in a code file need to be manually internationalized, which is cumbersome, inefficient and error-prone.

[0005] In a first aspect, an embodiment of the present application provides a method for internationalizing a code, comprising traversing a source code file and searching for a portion to be internationalized in the source code file;

[0006] Determine the translation identification information corresponding to the part to be internationalized;

[0007] Creating an internationalization function for the translation identification information;

[0008] The part to be internationalized in the source code file is replaced with the internationalization function.

[0009] In a possible implementation, traversing the source code file to find the part to be internationalized in the source code file includes:

[0010] Obtaining an abstract syntax tree expression of the source code in the source code file based on a babel parser;

[0011] Each node of the abstract syntax tree of the source code is traversed, and the part to be processed by internationalization is searched through each node of the abstract syntax tree.

[0012] In a possible implementation, after replacing the to-be-internationalized portion in the source code file with the internationalization function, the method further includes:

[0013] Obtaining an abstract syntax tree expression of the internationalization function based on a babel parser;

[0014] Based on the abstract syntax tree expression of the internationalized function, updating the abstract syntax tree;

[0015] The updated abstract syntax tree is converted into target code, and the target code is output.

[0016] In a possible implementation manner, before determining the translation identification information corresponding to the part to be internationalized, the method further includes:

[0017] Detecting the to-be-internationalized parts of the source code file based on the positive side expression, and extracting all the detected to-be-internationalized parts;

[0018] Forming a translation JSON file of the part to be internationalized, wherein the translation JSON file includes the part to be internationalized and translation identification information corresponding to the part to be internationalized;

[0019] The step of determining the translation identification information corresponding to the part to be internationalized includes:

[0020] The translation identification information corresponding to the part to be internationalized is determined from the translation JSON file.

[0021] In a possible implementation, before traversing the source code file to find the part to be internationalized in the source code file, the process further includes:

[0022] Obtain a configuration file through Webpack, and build an internationalization processing project for the code based on the configuration file, wherein the configuration file includes a file path of a source code file and a specified path of a translation JSON file;

[0023] The source code file is obtained according to the file path of the source code file in the configuration file.

[0024] In one possible implementation,

[0025] Add the internationalization plug-in corresponding to the internationalization function in webpack.

[0026] In a second aspect, an embodiment of the present application further provides a device for internationalizing a code, the device comprising:

[0027] A search module, used for traversing the abstract syntax tree nodes of the source code to search for the part to be internationalized in the source code;

[0028] A determination module, used to determine the translation identification information corresponding to the part to be internationalized;

[0029] A creation module, used for creating an internationalization function of the translation identification information;

[0030] A processing module is used to replace the part to be processed by internationalization with the internationalization function.

[0031] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0032] The memory is used to store computer-executable instructions;

[0033] The processor executes the computer-executable instructions stored in the memory to implement the above first aspect and / or various possible implementations of the first aspect.

[0034] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the first aspect above and / or various possible implementations of the first aspect.

[0035] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the above first aspect and / or various possible implementation methods of the first aspect.

[0036] The code internationalization processing method, device, electronic device and storage medium provided in the present application traverse the source code file to find the part to be internationalized in the source code file; then create an internationalization function of the translation identification information according to the translation identification information corresponding to the part to be internationalized; replace the part to be internationalized in the source code file with the internationalization function, so as to automatically insert the internationalization function into the part to be internationalized in the source code file, and eliminate the need to manually insert the internationalization function into the part to be internationalized during the code writing process. The method is suitable for software development projects with large amounts of code and frequent updates, and has high internationalization processing efficiency and is less prone to errors. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0038] Figure 1 A flowchart of a method for internationalizing a code provided in one embodiment of the present application;

[0039] Figure 2A flowchart of a method for internationalizing a code provided in another embodiment of the present application;

[0040] Figure 3 A flowchart of a method for internationalizing a code provided in another embodiment of the present application;

[0041] Figure 4 A schematic diagram of a code internationalization processing device provided in an embodiment of the present application;

[0042] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0043] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0044] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application.

[0045] In the description of this application, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0046] In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "connected" and "connection" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.

[0047] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0048] In software development, especially when it comes to project development with multi-language support, the language used by developers during development is different from the language that the front-end needs to display. Therefore, internationalization of the code (for example, i18n, where the first and last characters of Internationalization are I and n, and 18 is the number of characters in the middle) is a very important step in the development process.

[0049] At present, the traditional internationalization method is that developers manually internationalize Chinese text in the code during the code development process. In projects with large amounts of code and frequent updates, this method is inefficient, error-prone, and difficult to maintain.

[0050] In response to the above problems, this application proposes a method for internationalization of code. The method uses the webpack module packaging tool to automatically convert Chinese text in the development project into i18n function calls during construction, thereby automating internationalization processing without manual replacement.

[0051] The technical solution of the present application is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.

[0052] In this application, the electronic device is used as the execution subject to execute the internationalization processing method of the code of the following embodiment. Specifically, the execution subject can be a hardware device of the electronic device, or a software application that implements the following embodiment in the electronic device, or a computer-readable storage medium installed with the software application that implements the following embodiment, or the code of the software application that implements the following embodiment.

[0053] In the embodiment of the present application, the electronic device may be a computer device or other device.

[0054] Figure 1 This is a schematic diagram of a code internationalization processing method provided in an embodiment of the present application. Figure 1 ,like Figure 1 As shown, the method includes:

[0055] S101, traversing the source code files to find the parts to be internationalized in the source code files;

[0056] In this step, the source code file refers to the code file corresponding to the software development, and the source code file includes code and text other than the code (such as text written in a certain language (or language)).

[0057] In the embodiments of the present application, the software development project involved is an international project that needs to support multiple languages. The text other than the code is generally a specific language used by the programmer for the convenience of writing. In order to adapt to internationalization, it is necessary to internationalize it to form a text in the corresponding language (or language) according to the needs. In the embodiments of the present application, this text that needs to be internationalized is defined as the part to be internationalized.

[0058] For example: source code files generally include code and some texts used to express logs, comments, names, prompts, etc. When coding, based on the habits of coders, they usually use a language they are familiar with to express these texts, such as Chinese text. Based on internationalization requirements, these Chinese texts need to be internationalized, so these contents that need to be internationalized are defined as the above-mentioned part to be internationalized. Alternatively, coders are accustomed to expressing in English text. Based on internationalization requirements, this English text is also a part that needs to be internationalized, defined as the part to be internationalized. It should be noted that the part to be internationalized refers to the part that is written in a certain language but does not meet the internationalization requirements and needs to be converted into a characteristic language. The certain language includes but is not limited to Chinese.

[0059] Based on the definition of the part to be internationalized, the query conditions are pre-set. For example, if the part to be internationalized is Chinese text, the text character can be set as the query condition, and then the source code file is traversed to find the part to be internationalized (Chinese text) in the source code file.

[0060] As an example, the source code text is processed by calling the webpack tool. For example, after the writer finishes writing the project code, a source code file is formed, and then the webpack tool is called to internationalize the source code file.

[0061] As an example, the specific processing method of the above S101 includes:

[0062] Get the abstract syntax tree representation of the source code in the source code file based on the babel parser;

[0063] After obtaining the source code file, the babel parser is used to parse the source code file and parse the source code into an abstract syntax tree (AST) expression to divide the source code file into multiple nodes, where each node represents a structure of the source code file, such as an expression, statement function, etc.

[0064] Traverse each node of the abstract syntax tree of the source code, and search for the part to be internationalized through each node of the abstract syntax tree.

[0065] Traverse the nodes of the abstract syntax tree to identify whether the node is a part to be processed by internationalization. If so, execute step S102. If not, continue to traverse the next node until all nodes are traversed.

[0066] S102, determining translation identification information corresponding to the part to be internationalized;

[0067] In this step, the translation identification information is a translation key.

[0068] When the part to be processed internationally is identified, the translation identification information of the part to be processed internationally is determined, and the translation information of the part to be processed internationally is easily found through the translation identification information.

[0069] It should be noted that the translation identification information corresponding to different parts to be processed internationally is different. The translation identification information of each part to be processed internationally in different languages ​​is the same.

[0070] For example, the language used in the part to be internationalized is Chinese, and each Chinese word (or phrase or sentence) corresponds to a unique translation identification information. In English, Korean or other languages, the translation identification information corresponding to the Chinese word is the same. Assuming that the Chinese word is "date", its corresponding translation identification information is key1. The translation identification information of "date" in the English translation file is key1, and the translation identification information in the Korean translation file is also key1. In this way, the translation information corresponding to different languages ​​can be found through one translation identification information.

[0071] As an example, before determining the translation identification information corresponding to the part to be internationalized, it is also necessary to mark the translation identification information of the part to be internationalized in the source code file, so as to create an internationalization function of the translation identification information.

[0072] Specifically, based on the positive side expression, the part to be processed in the source code file is detected, and all the detected parts to be processed in the source code file are extracted; a translation JSON file of the part to be processed in the source code file is formed, wherein the translation JSON file includes the part to be processed in the source code file and the translation identification information corresponding to the part to be processed in the source code file. In this way, when searching for the part to be processed in the source code file, the translation identification information corresponding to the part to be processed in the source code file can be determined from the translation JSON file.

[0073] After extracting all the parts to be internationalized in the source code file, a translation JSON file is formed. The translation JSON file is formed to mark the translation identification information of all the parts to be internationalized in the source code file, and to form a file that can be recognized and read by the webpack tool.

[0074] S103, creating an internationalization function for translating identification information;

[0075] After determining the translation identification information of the part to be internationalized on the node, an internationalization function is created based on the translation identification information. Optionally, the expression of the internationalization function can be: intl.get('key') function, intl.get refers to the i18n function, and key refers to the translation identification information.

[0076] S104, replacing the part to be internationalized in the source code file with the internationalization function;

[0077] In this step, the part to be processed internationalized in the source code file is replaced with the internationalization function, that is, the part to be processed internationalized is expressed by the internationalization function. After the code is formed, the internationalization function triggers the corresponding internationalization plug-in to perform the translation operation, finds the translation text of the target language through the corresponding translation identification information, and then displays the corresponding translation text at this position, so that the original part to be processed internationalized is displayed as the corresponding translation text.

[0078] For example, if the part to be internationalized is the Chinese word "date", through the above step S104, "date" is replaced with the corresponding internationalization function, and then a new code is formed. When the code is displayed, the internationalization plug-in corresponding to the internationalization function performs a reaction operation, and finds the corresponding English "date" through the corresponding translation identification information. That is, through this internationalization function, the coder can use the language he is accustomed to when coding, and when the code is running, it is automatically translated into the target language, which is suitable for international project development. By automatically inserting the internationalization function into the part to be internationalized corresponding to the source code file, instead of manual insertion, and batch insertion, the efficiency of internationalization processing is improved, especially in projects with large code volume and frequent updates, the error rate can be reduced.

[0079] As an example, since the internationalization function is replaced in the node of the abstract syntax tree, it is necessary to unify the expression of the internationalization function and the code. Based on this, after determining the internationalization function corresponding to the part to be processed on the node, or replacing the part to be processed with the internationalization function, the abstract syntax tree expression of the internationalization function is obtained based on the babel parser; based on the abstract syntax tree expression of the internationalization function, the abstract syntax tree is updated, so that the abstract syntax tree expression of the part to be processed on the node is replaced with the abstract syntax tree expression of the internationalization function.

[0080] After all internationalization processing functions are converted into abstract syntax tree expressions, the updated abstract syntax tree is converted into target code, and the target code is output. The target code is the target code after the source code file is automatically nationalized before S101. In the target code, the corresponding part to be internationalized will be automatically displayed in the target language based on the internationalization processing function, so as to achieve the purpose of translation.

[0081] In this embodiment, the part to be internationalized in the source code file is found by traversing the source code file; then, according to the translation identification information corresponding to the part to be internationalized, an internationalization function of the translation identification information is created; the part to be internationalized in the source code file is replaced with the internationalization function, so that the internationalization function is automatically inserted into the part to be internationalized in the source code file, and there is no need to manually insert the internationalization function into the part to be internationalized during the code writing process. This is suitable for software development projects with large amounts of code and frequent updates. The internationalization processing efficiency is high, and the automated processing reduces errors in human operations, thereby ensuring the accuracy of the replacement of the part to be internationalized and making it less prone to errors.

[0082] Figure 2 This is a schematic diagram of a code internationalization processing method provided in an embodiment of the present application. Figure 2 ,like Figure 2 As shown, this embodiment is based on the above embodiment, and the method includes:

[0083] S201, obtain the configuration file through Webpack, and build the internationalization processing project of the code based on the configuration file;

[0084] In the example of using Webpack for code internationalization, you need to set up a configuration file in Webpack first, and then build an internationalization processing project in Webpack based on the configuration file to process the project corresponding to the source code file to automatically add internationalization functions.

[0085] Optionally, the configuration file includes the file path of the source code file and the specified path of the translation JSON file. The configuration of the file path of the source code file is to facilitate finding the source code file; the configuration of the specified path of the translation JSON file is to facilitate saving the generated translation JSON file to the specified path, and when determining the translation identification information, the translation JSON file can be quickly retrieved, and then the translation identification information corresponding to the part to be internationalized can be obtained, thereby ensuring that the Chinese resource mapping file can be correctly found and loaded.

[0086] S202, obtaining a source code file according to the file path of the source code file in the configuration file.

[0087] After Webpack builds the internationalization processing project, it automatically obtains the source code file through the source code file path, and then internationalizes the source code file.

[0088] Optionally, the processing method includes but is not limited to the following steps:

[0089] S203, traversing the source code file to find the part to be internationalized in the source code file;

[0090] S204, determining translation identification information corresponding to the part to be internationalized;

[0091] S205, creating an internationalization function for translating identification information;

[0092] S206, replacing the part to be internationalized in the source code file with the internationalization function;

[0093] In this embodiment, the specific implementation method of S203 to S206 is the same as above. Figure 1 S101 to S104 in the illustrated embodiment are the same, and the specific implementation process may refer to the above embodiment, which will not be described again.

[0094] As an example, if the internationalization function is not loaded in webpack, it is necessary to add the internationalization function in webpack before S201. This is to facilitate calling when creating the internationalization function of the translation identification information. Optionally, the internationalization function can be added to the configuration file, and webpack can obtain the internationalization function through the configuration file, and create the internationalization function of each translation identification information according to the translation identification information corresponding to each part to be internationalized, so as to realize automatic insertion and replacement of the internationalization function.

[0095] In the embodiment of the present application, the source code file is internationalized through Webpack, which is a module packaging tool that can process the code during construction, specifically by converting the source code file to AST, then finding the part to be internationalized in the AST node, and then replacing the part to be internationalized with the internationalization function. Based on the inserted internationalization plug-in, the internationalization function can be translated, and the internationalization function is automatically inserted without manual insertion, which improves the efficiency and accuracy of internationalization processing. In addition, as a webpack plug-in, it is easy to integrate into the existing front-end project, without the need to significantly modify the existing project structure, simplifying the process of internationalization processing.

[0096] Figure 3 This is a schematic flow chart of a method for internationalizing a code provided in an embodiment of the present application. Figure 3 This embodiment is based on all the above embodiments, and is used to internationalize Chinese. In order to describe in detail the process of calling webpack to internationalize the code, such as Figure 3 As shown, the method includes:

[0097] S301, configure the webpack configuration file and add the internationalization plug-in to the configuration file.

[0098] Optionally, in this step, the internationalization function is an intl.get('key') function, intl.get refers to an i18n function, key refers to translation identification information, and the internationalization plug-in is an i18n plug-in.

[0099] The configuration file includes the file path of the source code file and the specified path of the translation JSON file;

[0100] In this step, configure the webpack configuration file so that the loader can correctly find and load the Chinese resource mapping file.

[0101] S302, obtain the configuration file through Webpack, and build the internationalization processing project of the code based on the configuration file.

[0102] Webpack reads the configuration file and starts building the project, through which batch internationalization functions are automatically inserted into the source code files.

[0103] S303, obtaining the source code file according to the file path of the source code file in the configuration file.

[0104] According to the configuration rules of the configuration file, the files to be processed (such as files ending with tsx and / or jsx) are found in the file path.

[0105] S304, calling the loader to process the acquired source code file;

[0106] In this step, webpack uses the configured loader (such as intl-loader.js) to process the source code files.

[0107] As an example, the specific process of loader processing source code files is as follows:

[0108] First, intl-loader.js reads the source code file content and parses it into AST through babel;

[0109] Traverse AST, find each node of the source code file, and determine the Chinese text;

[0110] Then determine the key of the Chinese text and generate the internationalization function intl.get(key);

[0111] Replace the Chinese text with the internationalization function intl.get(key), and call the internationalization plug-in to translate the Chinese text;

[0112] Generate new code.

[0113] In this example, the specific process of loader processing the source code file can be referred to above Figure 1 For details of S101 to S104 in the embodiment, please refer to the above Figure 1 The illustrated embodiments will not be described in detail here.

[0114] S305, receiving the modified code returned by the loader, and webpack processes the modified code;

[0115] After Webpack receives the modified code, it packages and optimizes the code.

[0116] S306, webpack completes the processing and packaging of all files, generates the final target project, and outputs the target project.

[0117] The target project is the code file after the internationalization function is inserted into the source code file as required by the user.

[0118] In this embodiment, based on the call of webpack and the processing of the source code file by the loader, the internationalization function is automatically inserted into the source code file to replace the part of the source code file to be internationalized. There is no need for manual insertion by the user, which improves processing efficiency and is less prone to errors.

[0119] like Figure 4As shown, an embodiment of the present application provides a device for internationalizing a code, such as Figure 4 As shown, the internationalization processing device 40 includes:

[0120] A search module 401 is used to traverse the abstract syntax tree nodes of the source code to search for the part to be internationalized in the source code;

[0121] Determination module 402, used to determine the translation identification information corresponding to the part to be internationalized;

[0122] A creation module 403 is used to create an internationalization function for translating identification information;

[0123] The processing module 404 is used to replace the part to be processed by internationalization with the internationalization function.

[0124] The internationalization processing device 40 provided in the embodiment of the present application can execute the above method embodiment. Its specific implementation principle and technical effects can be found in the above method embodiment, which will not be described in detail in this embodiment.

[0125] like Figure 5 As shown, an embodiment of the present application provides an electronic device 500 , which includes a memory 501 and a processor 502 .

[0126] The memory 501 is used to store computer-executable instructions executable by the processor;

[0127] The processor 502 implements each step of the method in the above embodiment when executing the computer execution instruction. For details, please refer to the relevant description in the above method embodiment.

[0128] Optionally, the memory 501 can be independent or integrated with the processor 502. When the memory 501 is independently provided, the electronic device further includes a bus 503 for connecting the memory 501 and the processor 502.

[0129] The embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, each step of the method in the above embodiment is implemented.

[0130] The embodiment of the present application also provides a computer program product, including computer executable instructions, which implement the various steps of the method in the above embodiment when executed by a processor.

[0131] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0132] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A method for internationalizing a code, characterized in that: The method comprises: Traversing the source code files to find the parts to be internationalized in the source code files; Determine the translation identification information corresponding to the part to be internationalized; Creating an internationalization function for the translation identification information; The part to be internationalized in the source code file is replaced with the internationalization function.

2. The internationalization processing method according to claim 1, characterized in that: The traversing the source code file to find the part to be internationalized in the source code file includes: Obtaining an abstract syntax tree expression of the source code in the source code file based on a babel parser; Each node of the abstract syntax tree of the source code is traversed, and the part to be processed by internationalization is searched through each node of the abstract syntax tree.

3. The internationalization processing method according to claim 2, characterized in that: After replacing the part to be internationalized in the source code file with the internationalization function, the method further includes: Obtaining an abstract syntax tree expression of the internationalization function based on a babel parser; Based on the abstract syntax tree expression of the internationalized function, updating the abstract syntax tree; The updated abstract syntax tree is converted into target code, and the target code is output.

4. The internationalization processing method according to claim 1, characterized in that: Before determining the translation identification information corresponding to the part to be internationalized, the method further includes: Detecting the to-be-internationalized parts of the source code file based on the positive side expression, and extracting all the detected to-be-internationalized parts; Forming a translation JSON file of the part to be internationalized, wherein the translation JSON file includes the part to be internationalized and translation identification information corresponding to the part to be internationalized; The step of determining the translation identification information corresponding to the part to be internationalized includes: The translation identification information corresponding to the part to be internationalized is determined from the translation JSON file.

5. The internationalization processing method according to any one of claims 1 to 4, characterized in that: Before traversing the source code file to find the part to be processed by internationalization in the source code file, the method further includes: Obtain a configuration file through Webpack, and build an internationalization processing project for the code based on the configuration file, wherein the configuration file includes a file path of a source code file and a specified path of a translation JSON file; The source code file is obtained according to the file path of the source code file in the configuration file.

6. The internationalization processing method according to any one of claims 1 to 4, characterized in that: Add the internationalization plug-in corresponding to the internationalization function in webpack.

7. A device for processing code internationalization, characterized in that: The device comprises: A search module, used for traversing the abstract syntax tree nodes of the source code to search for the part to be internationalized in the source code; A determination module, used to determine the translation identification information corresponding to the part to be internationalized; A creation module, used for creating an internationalization function of the translation identification information; A processing module is used to replace the part to be processed by internationalization with the internationalization function.

8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory is used to store computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.

10. A computer program product, characterized in that The method comprises computer-executable instructions, which implement the method according to any one of claims 1 to 6 when executed by a processor.

Citation Information

Cited By

  • Internationalized data-based front and back end separation method, apparatus and device, and medium

    CN120653287A