Page language translation method, device and equipment, computer readable storage medium and computer program product

By generating an abstract syntax tree to determine the location of target terms and automatically integrating them into the translation function, the high cost and omissions of manual multilingual transformation in existing technologies are solved, achieving efficient and accurate page language translation.

CN121835700APending Publication Date: 2026-04-10TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-10
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

In existing technologies, applications are not designed with multilingual requirements in mind. Subsequent multilingual modifications require manual processing of entries, resulting in high costs and the risk of missing entries.

Method used

By generating an abstract syntax tree for the application, the location information of target terms not included in the translation function is determined and automatically incorporated into the translation function, thus achieving automated translation.

Benefits of technology

It improved translation efficiency, reduced labor costs, and minimized omissions of terms, ensuring the accuracy and consistency of the translation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121835700A_ABST
    Figure CN121835700A_ABST
Patent Text Reader

Abstract

The invention provides a page language translation method, device and equipment, a computer program product and a computer readable storage medium. The method comprises the steps of generating an abstract syntax tree corresponding to a page code file based on the page code file of an application program; based on the abstract syntax tree, determining position information of a target entry in the page code file; wherein the target vocabulary entry is a vocabulary entry which is not contained by a translation function in the page code file, and the translation function is used for translating the language of the vocabulary entry in the page code file from a source language to a target language; based on the position information of the target entry, fusing the target entry into the translation function of the page code file, so that the target entry is contained by the translation function; and executing the translation function to translate a source language page of the application program into a target language page. Through the method, the page language translation efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to computer technology, and more particularly to a method, apparatus, device, computer-readable storage medium, and computer program product for translating page language. Background Technology

[0002] In the context of globalization, multilingual support for software and internet products has become increasingly important. Users come from different cultural backgrounds and use different languages ​​to communicate and obtain information. To meet the needs of these users, developers need to translate interfaces, help documentation, error messages, and other content into multiple languages.

[0003] In the solutions provided by related technologies, if a project (such as an application) did not consider multilingual requirements in its initial design, and later wants to modify it to be multilingual, it is necessary to manually process the terms that need to be processed for multilingual purposes using specific translation functions (such as wrapping them with the t function), and then use the i18next tool to scan out the terms for use. This process will require a lot of manpower to extract terms at the beginning, and there is a risk of missing terms. Summary of the Invention

[0004] This application provides a page language translation method, apparatus, computer-readable storage medium, and computer program product, which can improve the efficiency of page language translation.

[0005] The technical solution of this application embodiment is implemented as follows:

[0006] This application provides a method for translating page language, the method comprising:

[0007] Based on the application's page code file, an abstract syntax tree corresponding to the page code file is generated;

[0008] Based on the abstract syntax tree, the location information of the target term in the page code file is determined;

[0009] The target term is a term in the page code file that is not included in the translation function. The translation function is used to translate the language of the term in the page code file from the source language to the target language.

[0010] Based on the location information of the target term, the target term is integrated into the translation function of the page code file so that the target term is included in the translation function;

[0011] The translation function is executed to translate the source language page of the application into the target language page.

[0012] This application also provides a page language translation device, including:

[0013] The abstract syntax tree generation module is used to generate an abstract syntax tree corresponding to the page code file based on the application's page code file.

[0014] The location information determination module is used to determine the location information of the target term in the page code file based on the abstract syntax tree; wherein, the target term is a term in the page code file that is not included by the translation function, and the translation function is used to translate the language of the term in the page code file from the source language to the target language;

[0015] The function processing module is used to integrate the target term into the translation function of the page code file based on the location information of the target term, so that the target term is included in the translation function;

[0016] A page translation module is used to execute the translation function to translate the source language page of the application into a target language page.

[0017] In the above scheme, the location information determination module is further used to determine the node of the target type in the abstract syntax tree; extract the text content in the node of the target type; extract the target term from the text content, and determine the location information of the target term in the page code file.

[0018] In the above scheme, the location information determination module is also used to traverse the nodes of the target type in the abstract syntax tree, and perform the following operation on the traversed nodes: by calling the text extraction function, extract the text content from the node according to the type and structure of the node.

[0019] In the above scheme, the location information determination module is further configured to use regular expressions to extract the source language text content from the text content extracted from each of the nodes as candidate terms, and obtain at least one candidate term; and to filter from the at least one candidate term to obtain candidate terms not included in the translation function as the target term.

[0020] In the above scheme, the location information determination module is further used to obtain the term information quadruple corresponding to the target term, the term information quadruple including the term content of the target term, the type of the target term, the node to which the target term belongs and the type of the corresponding node; based on the term information quadruple corresponding to the target term, the location information of the target term in the page code file is determined.

[0021] In the above scheme, the location information includes source code location information, which is used to indicate the line number of the target term in the page code file; the application has a term location information database for recording the location information of terms;

[0022] The location information determination module is further configured to, if the location information of the target term is not recorded in the term location information database, generate a term location information tuple for the target term based on the term information quadruple corresponding to the target term, and add the term location information tuple to the term location information database; wherein, the term location information tuple includes the identifier of the target term and the source code location information of the target term; if the location information of the target term is recorded in the term location information database, update the location information of the target term in the term location information database based on the source code location information of the target term.

[0023] In the above scheme, there are multiple target terms; the function processing module is further used to sort the multiple target terms in descending order of content length to obtain a target term sequence; based on the position information of the target terms, according to the order of the target terms in the target term sequence, each target term is sequentially integrated into the translation function of the page code file so that the target terms are included by the translation function.

[0024] In the above scheme, the location information includes the line number of the target term in the page code file; the function processing module is further configured to search for the code content corresponding to the line number in the page code file based on the line number of the target term in the page code file; and to integrate the target term in the code content into the translation function of the page code file, so that the target term in the code content is included by the translation function.

[0025] In the above scheme, the page language translation device further includes a quotation statement addition module.

[0026] The citation statement adding module is used to perform citation statement detection on the page code file containing the target term and obtain the detection result; if the detection result indicates that the page code file does not contain the target citation statement, the target citation statement is added to the page code file.

[0027] In the above scheme, the page language translation device further includes a code file determination module.

[0028] The code file determination module is used to obtain a list of paths storing the code files of the application; and to scan the list of paths using wildcard expansion to determine the page code files of the application.

[0029] In the above scheme, the abstract syntax tree generation module is further used to divide multiple characters in the page code file of the application into multiple lexical units; construct multiple syntax structures of the page code file according to the syntax rules of the page code file and the multiple lexical units; and generate an abstract syntax tree corresponding to the page code file using the syntax structures as nodes.

[0030] This application also provides a page language translation device, including:

[0031] Memory is used to store executable instructions or computer programs.

[0032] The processor, when executing computer-executable instructions or computer programs stored in the memory, implements the page language translation method provided in the embodiments of this application.

[0033] This application provides a computer-readable storage medium storing a computer program or computer-executable instructions, which, when executed by a processor, implements the page language translation method provided in this application.

[0034] This application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, they implement the page language translation method provided in this application.

[0035] The embodiments of this application have the following beneficial effects:

[0036] Based on the application's page code file, an abstract syntax tree (AST) is generated corresponding to the page code file. Using the AST, the location information of terms not included in the translation function is determined. These unincluded terms are then incorporated into the page code file's translation function based on their location information, thus ensuring they are included. This automates the inclusion of unincluded terms in the code file using the translation function, reducing the cost of multilingual adaptation of the application, improving the efficiency of term processing based on translation functions, and significantly minimizing term omissions caused by manual processing. Attached Figure Description

[0037] Figure 1 This is an optional architecture diagram of the page language translation system provided in this application embodiment;

[0038] Figure 2 This is a schematic diagram of the structure of the page language translation device provided in the embodiments of this application;

[0039] Figure 3A This is an optional flowchart illustrating the page language translation method provided in this application embodiment;

[0040] Figure 3B This is an optional flowchart illustrating the page language translation method provided in this application embodiment;

[0041] Figure 3C This is an optional flowchart illustrating the page language translation method provided in this application embodiment;

[0042] Figure 3D This is an optional flowchart illustrating the page language translation method provided in this application embodiment;

[0043] Figure 4 This is a schematic diagram of a code file containing reference statements provided in an embodiment of this application;

[0044] Figure 5A This is a schematic diagram of the Chinese page of the application provided in the embodiments of this application;

[0045] Figure 5B This is an English page illustration of the application provided in the embodiments of this application;

[0046] Figure 6A This is a schematic diagram of the term location information extraction process in the page language translation method provided in this application;

[0047] Figure 6B This is a schematic diagram of the term processing flow in the page language translation method provided in this application embodiment; Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0049] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0050] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0051] Unless otherwise defined, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in the embodiments of this application is for the purpose of describing the embodiments of this application only and is not intended to limit this application.

[0052] In the implementation of this application, the collection and processing of relevant data should strictly comply with the requirements of relevant laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.

[0053] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.

[0054] 1) An Abstract Syntax Tree (AST) is a tree-like representation of the abstract syntactic structure of source code. It typically includes nodes, edges, and leaf nodes. Each node represents a construct in the source code, the edges represent relationships between nodes, and the leaf nodes are usually literals or identifiers from the source code. An AST does not represent every detail of the actual syntax, is independent of the source language's syntax, and is unrelated to specific syntactic details and parsing details. For example, when the source code is the application's source code, the leaf nodes of the AST can be literals, identifiers, expressions, etc., from the application's source code, and the edges can represent parent-child relationships, sibling relationships, etc.

[0055] 2) A term refers to the content in a code file that needs to be displayed in the corresponding language according to the user's specified language.

[0056] 3) A term library is a repository used to store terms extracted from code files.

[0057] 4) Wildcard expansion is a technique that can be used to match filename patterns. It matches one or more characters in a filename or pathname. Wildcards include *, ?, [], etc.

[0058] 5) Regular expressions are tools for matching and manipulating text. They consist of a series of characters and special characters that describe a pattern of text to be matched. They can be used to find, replace, extract, and validate specific patterns in text. For example, `color?` can match either `color` or `colour`, and the question mark (`?`) indicates that the preceding character can appear at most once (0 or 1 times).

[0059] During their research, the inventors discovered that in related technologies, when an application was not designed with multilingual requirements in mind, subsequent modifications to support multilingual support require manual methods. This involves using a translation function (t) to extract terms from the source language of the code file. After the terms are included in the t function, the i18next tool is used to scan them for later use. This process initially requires significant manpower for term extraction and is prone to omissions.

[0060] Therefore, it is evident that in related technologies, the process of including terms using the t-function is done manually. However, when the scale of multilingual projects is large, it requires a significant amount of manpower and resources, and the t-function inclusion of terms is inefficient and prone to omissions.

[0061] To address the aforementioned technical problems, embodiments of this application provide a page language translation method, apparatus, device, computer-readable storage medium, and computer program product, which can efficiently and accurately integrate terms not included in the translation function into the translation function of the page code file, so that the target terms are included in the translation function.

[0062] See Figure 1 , Figure 1 This is an optional architecture diagram of the page language translation system provided in this application embodiment. To support a page language translation application, in... Figure 1 In the page language translation system 100, the terminal 400 connects to the server 200 through the network 300, which can be a wide area network or a local area network, or a combination of both.

[0063] Terminal 400 is used to respond to user operations in client 410 by sending a page language translation request for the application's page code file to server 200 via network 300.

[0064] Server 200 is used to obtain the page code file corresponding to the term to be processed based on the page language translation request; generate the corresponding abstract syntax tree based on the page code file; determine the location information of the target term in the page code file based on the abstract syntax tree, where the target term is a term in the page code file that is not included in the translation function, and the translation function is used to translate the language of the term in the page code file from the source language to the target language; incorporate the target term into the translation function of the page code file based on the location information of the target term, so that the target term is included in the translation function; and execute the translation function to translate the source language page of the application into the target language page.

[0065] Server 200 is also used to send the results of page language translation to terminal 400.

[0066] In other embodiments, a client 410 capable of implementing a page language translation method is installed on the terminal 400. When a user requests page language translation in the client 410, the client 410 obtains the page code file corresponding to the term to be processed, generates a corresponding abstract syntax tree based on the page code file, determines the position information of the target term in the page code file based on the abstract syntax tree, integrates the target term into the translation function of the page code file based on the position information of the target term, so that the target term is included in the translation function, and executes the translation function to translate the source language page of the application into the target language page.

[0067] A page language translation plugin can also be embedded in the client 410 running on the terminal 400 to implement the page language translation method locally on the client 410. For example, after the terminal 400 receives a page language translation request for a page code file, it calls the page language translation plugin to implement the page language translation method. This involves generating a corresponding abstract syntax tree based on the page code file, determining the location information of the target term in the page code file based on the abstract syntax tree, integrating the target term into the translation function of the page code file based on the location information of the target term, ensuring that the target term is included in the translation function, and executing the translation function to translate the application's source language page into the target language page.

[0068] In some embodiments, server 200 may be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. Terminals and servers can be connected directly or indirectly via wired or wireless communication, which is not limited in this embodiment.

[0069] In this way, the target terms can be automatically integrated into the translation function of the page code file, improving processing efficiency and accuracy.

[0070] See Figure 2 , Figure 2 This is a schematic diagram of the structure of the page language translation device 500 provided in the embodiments of this application. In practical applications, the page language translation device can be implemented as various types of terminals such as laptops, tablets, desktop computers, smartphones, smart speakers, smartwatches, smart TVs, and vehicle terminals. It can also be implemented as a server or as a device cluster composed of servers and terminals. Figure 2 The page language translation device 500 shown includes at least one processor 510, a memory 550, at least one network interface 520, and a user interface 530. The various components in the device 500 are coupled together via a bus system 540. It is understood that the bus system 540 is used to implement communication between these components. In addition to a data bus, the bus system 540 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 2 The general labeled all buses as Bus System 540.

[0071] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.

[0072] User interface 530 includes one or more output devices 531 that enable the presentation of media content, including one or more speakers and / or one or more visual displays. User interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.

[0073] The memory 550 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 550 may optionally include one or more storage devices physically located away from the processor 510.

[0074] The memory 550 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 550 described in this application embodiment is intended to include any suitable type of memory.

[0075] In some embodiments, memory 550 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.

[0076] Operating system 551 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, for implementing various basic business functions and handling hardware-based tasks.

[0077] The network communication module 552 is used to reach other page language translation devices via one or more (wired or wireless) network interfaces 520, such as Bluetooth, WiFi, and Universal Serial Bus (USB).

[0078] Presentation module 553 enables the presentation of information (e.g., a user interface for operating peripheral devices and displaying content and information) via one or more output devices 531 (e.g., a display screen, a speaker, etc.) associated with user interface 530.

[0079] The input processing module 554 is used to detect and translate one or more user inputs or interactions from one or more input devices 532.

[0080] In some embodiments, the page language translation device provided in this application can be implemented in software. Figure 2 A page language translation device 555 stored in memory 550 is shown. This device can be software in the form of programs and plug-ins, and includes the following software modules: an abstract syntax tree generation module 5551, a location information determination module 5552, and a function processing module 5553. These modules are logically linked and can therefore be arbitrarily combined or further divided according to their implemented functions. The functions of each module will be described below.

[0081] In other embodiments, the page language translation device provided in this application can be implemented in hardware. As an example, the device provided in this application can be a processor in the form of a hardware decoding processor, which is programmed to execute the page language translation method provided in this application. For example, the processor in the form of a hardware decoding processor can be one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.

[0082] The following will describe the page language translation method provided in this application embodiment, with reference to exemplary applications and implementations of the page language translation device and system provided in the embodiments of this application.

[0083] See Figure 3A , Figure 3A This is an optional flowchart illustrating the page language translation method provided in this application embodiment. In practical applications, this method can be implemented by the terminal or the server alone, or by the terminal and the server working together. The following example uses a server implementation and will be combined with... Figure 3A The steps shown illustrate the page language translation method provided in the embodiments of this application.

[0084] In step 101, an abstract syntax tree corresponding to the page code file is generated based on the application's page code file.

[0085] Here, the page code file is the target source code file of the application, that is, the code file in which the target terms need to be incorporated into the translation function of the page code file. Incorporating the target terms into the translation function of the page code file means including terms that are not included in the translation function. The translation function is used to convert the included terms from the source language to the target language.

[0086] In some embodiments, there may be one or more page code files. When there are multiple page code files, the same processing as steps 101 to 103 is performed on each page code file. During the processing of multiple page code files, the multiple page code files can be sorted and translated into page language sequentially according to a specified order; or, one page code file can be randomly selected from the multiple page code files each time for page language translation.

[0087] In some instances, based on the application's page code file, specific functions can be used to perform AST parsing to generate the corresponding abstract syntax tree for the page code file.

[0088] As an example, the transformFileSync function provided by the core library @babel / core can be used to parse the application's page code file, converting the entire page code file into an AST in one go and outputting the converted code.

[0089] In some instances, the Abstract Syntax Tree Builder can also be used to generate an AST based on the application's page code files.

[0090] As an example, the builder reads the source code of the page code file, decomposes the character stream into a series of lexical units, organizes the lexical units into a tree structure according to the specified syntax rules, identifies various syntactic constructs in the code and converts them into corresponding AST nodes, recursively creates nodes and establishes parent-child relationships between nodes, and completes the construction of the AST after all lexical units have been organized into AST nodes.

[0091] This application's embodiments utilize various methods for generating abstract syntax trees based on code files, enabling efficient and in-depth analysis and manipulation of code. Automated tools can perform complex code transformations, optimizations, formatting, and error detection, improving code readability and maintainability.

[0092] In step 102, the location information of the target term in the page code file is determined based on the abstract syntax tree.

[0093] Here, the target term is a term in the page code file that is not included in the translation function. The translation function is used to translate the language of the term in the page code file from the source language to the target language. The translation function can be the t function.

[0094] As an example, the `t` function can register a service and obtain an online translation API key, such as the Google Translate API or the Baidu Translate API. It then sends the source language terms and target language terms to the selected translation service, which translates the source language terms into the target language terms. Finally, it receives the target language terms returned by the translation service and outputs them.

[0095] As another example, the t function can also call a local translation library (such as the translate library) to translate the language of the entry from the source language to the target language and output the target language entry.

[0096] Here, the source language can be different types or categories of languages, such as Chinese, English, French, Spanish, Arabic, etc., and the target language can also be different types or categories of languages, such as Chinese, English, French, Spanish, Arabic, etc.

[0097] As an example, when the target term is "apple" and the target language is English, the target term is integrated into the translation function of the page code file. After the translation function is executed, it will be transformed into "apple".

[0098] In some embodiments, the source language and the target language belong to different language categories.

[0099] This application embodiment can determine the location information of target terms in the page code file based on the abstract syntax tree, achieving efficient and accurate determination of the location information of target terms in the page code file, thereby preparing for the subsequent integration of terms into the translation function of the page code file based on the location information of the terms.

[0100] In step 103, based on the location information of the target term, the target term is incorporated into the translation function of the page code file so that the target term is included in the translation function.

[0101] Here, the location information of the target term includes the line number and column number of the target term in the page code file.

[0102] In some embodiments, the target term can be incorporated into the translation function of the page code file based on the line number of the target term in the page code file, so that the target term is included in the translation function.

[0103] In step 104, a translation function is executed to translate the application's source language page into the target language page.

[0104] In some embodiments, an application's code file may correspond to one or more application pages. An application page that does not support multilingual conversion is modified by incorporating the target term into the translation function of the page's code file. When the page's code file is executed, the application can display the corresponding page. When the user clicks the language conversion control in the application page, the translation function is called to translate the source language of the application page into the target language.

[0105] Here, the target language converted by the language conversion control can be selected by the user, or the developer can set the target language according to the needs of the application. This embodiment of the application does not impose any restrictions.

[0106] As an example, see Figure 5A and Figure 5B , Figure 5A This is a schematic diagram of the Chinese page of the application provided in the embodiments of this application. Figure 5B This is a schematic diagram of the English page of the application provided in this application embodiment. When the page code file is executed, the application displays as follows: Figure 5A The page's source language is Chinese. A translation control 501 exists on the page to translate the page's language to English. When the user clicks the translation control 501, the translation function is invoked, converting the page's source language (Chinese) to the target language (English), and displaying the result as shown below. Figure 5B The English page. Similarly, in Figure 5B When a user clicks on the translation control 502 on the page, which is used to translate the page language to Chinese, the page, originally in English, will be converted to Chinese. Figure 5A The Chinese version of the page.

[0107] In this embodiment, the page language translation device can generate an abstract syntax tree (AST) corresponding to the page code file of an application. Based on the AST, it determines the location information of the target term in the page code file. Based on the location information of the target term, it integrates the target term into the translation function of the page code file, so that the target term is included in the translation function. This automates the integration of the target term into the translation function of the page code file, eliminating the need for manual intervention, thereby significantly improving work efficiency, ensuring the accuracy and consistency of code processing, and reducing labor costs.

[0108] In some embodiments, see Figure 3B , Figure 3B This is an optional flowchart illustrating the page language translation method provided in this application embodiment. Figure 3A Step 101 shown can be implemented through steps 1011 to 1013. The process of generating the abstract syntax tree corresponding to the page code file will be explained in conjunction with each step.

[0109] In step 1011, multiple characters in the application's page code file are divided into multiple syntax units.

[0110] Here, the process of dividing multiple characters in an application's page code file into multiple syntactic units is usually called lexical analysis. A lexical analyzer or lexical scanner breaks down the source code text into a series of tokens, which are syntactic units with specific meanings.

[0111] As an example, the lexical analyzer first reads the source code character by character from the page code file, then categorizes the read characters into different classes, and finally, based on the sequence of read characters, identifies and constructs meaningful tokens, that is, divides them into multiple syntactic units. For example, for the target code "int x = 10;", the lexical analyzer will divide it into ˋintˋ: keyword, ˋxˋ: identifier, ˋ=ˋ: operator, ˋ10ˋ: integer constant, ˋ;ˋ: separator.

[0112] This application embodiment divides multiple characters in the application's page code file into multiple syntactic units, thereby preparing for the subsequent construction of a syntactic structure based on the syntactic units.

[0113] In step 1012, multiple syntactic structures of the page code file are constructed based on the syntax rules and multiple lexical units of the page code file.

[0114] After dividing multiple characters in the page code file into multiple syntactic units, multiple syntactic structures can be constructed based on the multiple syntactic units and corresponding syntactic rules in the page code file.

[0115] In some embodiments, a grammar can be defined, typically using Backus-Noor Normal Form (BNF) or a variant thereof to describe the grammatical rules of the language, combining the obtained grammatical units into larger grammatical structures, such as expressions, statements, functions, classes, etc., according to the set rules.

[0116] This application embodiment converts textual information in the source code into a logical structure that a computer can understand and process by constructing multiple syntactic structures in the code file, thereby providing a foundation for subsequent compilation, analysis, conversion, and optimization operations.

[0117] In step 1013, an abstract syntax tree corresponding to the page code file is generated using the syntax structure as nodes.

[0118] In some embodiments, an abstract syntax tree is constructed based on the different syntax structures corresponding to different nodes contained in the page code file.

[0119] As an example, for the abstract syntax tree of result = 5, the root node in the tree is Assignment, which represents the assignment operation. The nodes in the tree include the Id("result") node and the Number(5) node, where the Id("result") node represents the variable name result, and the Number(5) node represents the value 5.

[0120] In this embodiment, the page language translation device can divide multiple characters in the application's page code file into multiple grammatical units. Based on the grammar rules and multiple lexical units of the page code file, it constructs multiple grammatical structures of the page code file. Using these grammatical structures as nodes, it generates an abstract syntax tree corresponding to the page code file. This allows it to obtain the abstract syntax tree corresponding to the page code file, facilitating subsequent page language translation.

[0121] In some embodiments, see Figure 3C , Figure 3C This is an optional flowchart illustrating the page language translation method provided in this application embodiment. Figure 3A Step 102 shown can be implemented through steps 1021 to 1023, which will be explained in conjunction with each step.

[0122] In step 1021, the node of the target type in the abstract syntax tree is determined.

[0123] Here, the target type node is a node related to the target term. For example, the target type node may include one or more of the following nodes: JSXAttribute node, TemplateElement node, JSXText node, AssignmentExpression node, ObjectProperty node, AssignmentPattern node, JSXExpressionContainer node, ReturnStatement node, ArrayExpression node, NewExpression node, CallExpression node, BinaryExpression node, SwitchCase node, ConditionalExpression node, LogicalExpression node, and VariableDeclarator node.

[0124] This application embodiment determines the target type node in the abstract syntax tree, providing a precise contextual environment for subsequent text content extraction and target term location, thus ensuring the accuracy of the operation.

[0125] In step 1022, the text content of the target type node is extracted.

[0126] In some embodiments, extracting text content from nodes of a target type can be achieved by traversing the nodes of the target type in the abstract syntax tree, and extracting text content from the nodes according to their type and structure by calling a text extraction function.

[0127] Here, the text extraction function extracts the text content from the target type node, which is then used to extract the target term from the text content. This can be done by registering an AST Visitor callback, detecting the target type node, processing the callback of the detected target type node, and extracting the text part of the target type node based on the node's attributes and type.

[0128] As an example, when the target type node is a JSXAttribute node, it contains the node type, attribute name, and attribute value. The attribute value can be StringLiteral, JSXExpressionContainer, BooleanLiteral, NullLiteral, NumericLiteral, or JSXElement, etc. To extract text content from a JSXAttribute node, you need to access the node's attribute value and process it accordingly based on the type of the attribute value. When the attribute value is a string literal, you can directly obtain the value of StringLiteral to extract the text content.

[0129] In some embodiments, when the content of the target type node contains line breaks, it is necessary to split the content of the target type node by line and extract the text content of the target type node line by line.

[0130] As an example, when the target type node is a JSXText node, a new node information object is created based on the node information object, and the line numbers are incremented line by line. The value of the JSXText node is accessed line by line to extract the text content.

[0131] In step 1023, the target term is extracted from the text content, and the location information of the target term in the page code file is determined.

[0132] In some embodiments, the target term is extracted from the text content in the following manner: for the text content extracted from each node, the source language text content is extracted from the text content as candidate terms to obtain at least one candidate term, and candidate terms not included in the translation function are selected from the at least one candidate term as the target term.

[0133] In practical applications, regular expressions can be used to extract source language text from text content. For example, when the source language of the text content is Chinese, the text content extracted from each node is compared with the regular expression " / [\u4e00-\u9fa5] / ". When a Chinese word is detected in the text content, that word is taken as a candidate word and filtered based on whether it is included in a translation function (such as the t function). If a candidate word is not included in a translation function, it is taken as the target word.

[0134] In some embodiments, the location information of the target term in the page code file is determined by the following method: obtaining the term information quadruple corresponding to the target term, the term information quadruple including the term content of the target term, the type of the target term, the node to which the target term belongs and the type of the corresponding node, and determining the location information of the target term in the page code file based on the term information quadruple corresponding to the target term.

[0135] As an example, S can be used to represent the quadruple of word information corresponding to the target word. The corresponding tuple information can be (value, node, type, babelType), where value is the word content of the target word, node is the node to which the target word belongs, type is the type of the target word, babelType is the type of the corresponding node, and Si represents the quadruple of word information of the i-th word.

[0136] In some embodiments, the location information includes source code location information, which indicates the line number of the target term in the page code file. The application maintains a term location information database for recording the location information of terms. Accordingly, based on the term information quadruple corresponding to the target term, the location information of the target term in the page code file can be determined in the following way:

[0137] Check whether the location information of the target term is recorded in the term location information database;

[0138] If the location information of the target term is not recorded in the term location information database, a term location information tuple for the target term is generated based on the term information quadruple corresponding to the target term, and the term location information tuple is added to the term location information database.

[0139] Here, the term location information tuple includes the identifier of the target term and the source code location information of the target term.

[0140] As an example, when the location information of a target term is not available in the term location information database, the identifier and source code location information of the target term are obtained based on the four-tuple of term information corresponding to the target term. This results in a two-tuple of target term location information, which is then added to the term location information database. For instance, C can represent the two-tuple of target term location information, where the corresponding tuple information can be (id, source). Here, id is the identifier of the target term, which in practice can be the content of the target term itself; source is the source code location information of the target term; and Ci represents the i-th term information two-tuple. Furthermore, D can represent the term location information database, and D is composed of n C's.

[0141] As another example, when the location information of the target term is not available in the term location information database, the identifier of the target term, the replacement type of the target term, and the source code location information of the target term are obtained based on the term information quadruple corresponding to the target term. The replacement type of the target term and the source code location information of the target term are encapsulated into a source code location information tuple. Based on the identifier of the target term and the source code location information tuple, the location information tuple of the target term is generated and added to the term location information database.

[0142] For example, C can be used to represent a tuple of target term location information. The corresponding tuple information can be (id, source), where id is the identifier of the target term (in practical applications, this identifier can be the content of the target term itself), source is an array of multiple L arrays, where L represents the source code location information tuple, and L can be (type, location), where type is the replacement type of the target term, location is the source code location information of the target term, and Ci represents the tuple of information for the i-th term. Furthermore, D can be used to represent a term location information database, and D is composed of n C arrays.

[0143] In some embodiments, if the term location information database records the location information of the target term, the location information of the target term in the term location information database is updated based on the source code location information of the target term.

[0144] As an example, when the location information database contains the location information of a target term, the database finds the existing term index information based on the term content of the target term in the term information quadruple, and adds the target term's location information to the database based on the term index information. For instance, when there are multiple target terms, they will be distributed in different locations. If other location information of the target term already exists in the database before the current target term's location information is added, the database finds the index information n of the target term already existing in D based on Ci.id, and appends the Ci.source information to the end of D[n].source.

[0145] This application embodiment records the location information of the entries into a location information database, making related operations more efficient and accurate.

[0146] In some embodiments, see Figure 3D , Figure 3D This is an optional flowchart illustrating the page language translation method provided in this application embodiment. Figure 3A Step 103 shown can be implemented through steps 1031 to 1032. The process of integrating the target term into the translation function of the page code file will be explained in conjunction with each step.

[0147] In step 1031, multiple target terms are sorted in descending order of content length to obtain a target term sequence.

[0148] Here, because there are cases where long terms contain short terms, if the short terms are first incorporated into the translation function of the page code file, then the part of the long terms containing the short terms may also be incorporated into the translation function, causing an error in the process of incorporating the target terms into the translation function of the page code file. Therefore, the target terms are sorted from longest to shortest according to the length of the term content to obtain a target term sequence, and then each target term can be incorporated into the translation function of the page code file based on this target term sequence.

[0149] As an example, when the target terms include "apple", "an apple" and "I have an apple", the target terms are sorted from longest to shortest according to their content length, resulting in the sequence of target terms: "I have an apple", "an apple", "apple".

[0150] In this embodiment, target terms are sorted from longest to shortest according to their content length. This avoids the problem that processing short terms first may result in some of the long terms being removed, thereby improving the accuracy of page language translation.

[0151] In step 1032, based on the location information of the target terms, each target term is sequentially integrated into the translation function of the page code file according to the order of the target terms in the target term sequence, so that the target terms are included in the translation function.

[0152] Here, the location information includes the line number of the target term in the page's code file.

[0153] In some embodiments, for the target terms in the target term sequence that need to be incorporated into the translation function of the page code file: based on the line number of the target term in the page code file, the code content corresponding to the line number is found in the page code file, and the target term in the code content is incorporated into the translation function of the page code file, so that the target term in the code content is included in the translation function.

[0154] As an example, based on the file containing the term, the file content is read and split into an array line by line according to the newline character. Based on the line number of the target term in the page code file, the original code content of the line number where the target term is located is obtained. The target term is found in the original code content, and based on the type of the target term, the target term in the original code content is integrated into the translation function of the page code file so that the target term is included in the translation function.

[0155] For example, let `keyword` represent the content of the term being processed. `keyword` can be obtained through `D[i].id`. Based on `keyword`, the search term (`searchStr`) can be in the following formats: double quotes: `searchStr = "${keyword}"`, single quotes: `searchStr = '${keyword}'`, or no quotes: `searchStr = keyword`. Since the format of `location` is ` / path / to / file#line number#column number`, by splitting the string, we can obtain the file name and the line number where the term is located. Based on the line number corresponding to the term, we can obtain... The code snippet retrieves the line number containing the term (lineStr). When the term type is jsx, the replacement string (replaceStr) is ˋ{t('${keyword}')}ˋ. When the term type is template, the replacement string (replaceStr) is ˋ${t('${keyword}')}ˋ. When the term type is text, the replacement string (replaceStr) is ˋt('${keyword}')ˋ. Thus, by obtaining lineStr, replaceStr, and searchStr, the target term can be included in the translation function.

[0156] In some embodiments of this application, before generating the abstract syntax tree corresponding to the page code file based on the application's page code file, that is, before... Figure 3A Before step 101, the method may also include steps 104 to 105, which will be explained in conjunction with each step.

[0157] In step 104, a list of paths corresponding to the application's code files is obtained.

[0158] In some embodiments, the user can input a list of paths to the code files (source code files) to be processed as needed, thereby enabling the page language translation device to obtain a list of paths recording the storage locations of the code files. The application may have multiple code files, and correspondingly, the path list may include the paths corresponding to multiple code files.

[0159] In step 105, a wildcard expansion method is used to scan the path list to determine the application's page code file.

[0160] Here, wildcard filename extensions are used to match and select files that have a specific pattern. Some common wildcards include * (asterisk), ? (question mark), [...] (square brackets), and {...} (curly braces). An asterisk can match any number of characters, a question mark can match any single character, square brackets can match any single character within them, and curly braces can match any combination of characters within them.

[0161] As an example, *.txt will match all files with the .txt extension, file?.txt will match file1.txt, file2.txt, etc., but will not match file12.txt, file

[123] .txt will match file1.txt, file2.txt, and file3.txt, and file{1,2,3}.txt will match file1.txt, file2.txt, and file3.txt.

[0162] As another example, `[" / path / to / project / src / ** / *.{js,jsx,ts,tsx}"]` means scanning any nested level of files in the `src` directory that have the extensions `js`, `jsx`, `ts`, or `tsx`.

[0163] In some embodiments of this application, after incorporating the target term into the translation function of the page code file based on the target term's location information, that is, in Figure 3A After step 103, the method may also include steps 106 to 107, which will be explained in conjunction with each step.

[0164] In step 106, the page code file containing the target term is subjected to citation statement detection to obtain the detection results.

[0165] Here, the target reference statement is used to import the translation function in the page code file.

[0166] In some embodiments, regular expressions can be used to detect citation statements in page code files containing target terms, and the detection results can be obtained.

[0167] Here, the import statement is used to import translation functions, so that the translation functions can be called directly in the code file without rewriting them.

[0168] This application embodiment detects whether a page code file containing target terms contains quotations, and obtains the detection results. The detection results can then be used to determine whether the code file contains quotations, thereby judging whether the code file can successfully perform page language translation.

[0169] In step 107, if the detection result indicates that the page code file does not contain a target reference statement, the target reference statement is added to the page code file.

[0170] As an example, see Figure 4 , Figure 4 This is a schematic diagram of a code file containing reference statements provided in an embodiment of this application. Figure 4 A target reference statement 401 was added to the page code file.

[0171] The embodiments of this application can detect whether there are reference statements in the code file, thereby ensuring that the necessary modules or resources are loaded correctly.

[0172] The following will describe an exemplary application of the embodiments of this application in a real-world application scenario.

[0173] This application is a solution for integrating target terms into the translation function of a page code file. Specifically, it can process terms in the application's code file that are not included by the t function. In other words, it integrates terms not included by the t function into the translation function of the page code file so that they are included by the t function. The main processing involves two steps: term location information extraction and term processing. The following will describe these two steps separately.

[0174] refer to Figure 6A , Figure 6A This is a schematic diagram of the term location information extraction process in the page language translation method provided in this application, which specifically includes the following steps:

[0175] In step 601, the extraction of term location information begins.

[0176] In step 602, a list of files to be scanned is determined.

[0177] In some embodiments, the range of files to be scanned can be determined based on a user-configured list of scan paths in wildcard extended form.

[0178] For example, `[" / path / to / project / src / ** / *.{js, jsx, ts, tsx}"]` means scanning files with the extensions .js, .jsx, .ts, and .tsx at any nested level under the `src` directory. Using `glob` (npm), you can determine a specific list of files by configuring wildcard expansion methods. Here, the file list contains one or more source code files of the application.

[0179] In step 603, the list is traversed to determine if there are any unprocessed files.

[0180] Specifically, this involves iterating through the list of files to be scanned and determining if any source code files in the list have not been processed by the terminology. Here, terminology processing refers to the page language translation mentioned above. By determining if there are more source code files that have not been processed by the terminology, the range of files that need to be processed can be determined, ensuring that the program does not attempt to process files when none exist, thereby avoiding errors or exceptions.

[0181] In step 604, if so, perform AST parsing.

[0182] In step 605, the nodes are traversed to determine if there are any untraversed nodes.

[0183] By checking for unvisited nodes, we can help control the traversal process, ensuring that each node is visited appropriately, avoiding unnecessary traversals, and thus improving code performance.

[0184] In step 606, if so, parse the text content of the node.

[0185] In some embodiments, a single file is parsed using the `transformFileSync` function provided by `@babel / core`, and an AST Visitor callback is registered. This primarily detects nodes of the following types: `JSXAttribute`, `TemplateElement`, `JSXText`, `AssignmentExpression`, `ObjectProperty`, `AssignmentPattern`, `JSXExpressionContainer`, `ReturnStatement`, `ArrayExpression`, `NewExpression`, `CallExpression`, `BinaryExpression`, `SwitchCase`, `ConditionalExpression`, `LogicalExpression`, and `VariableDeclarator`. The callbacks for the detected node types are processed, and the text portion of the corresponding node type is extracted. Only the value portion of different node types needs to be processed and composed into a Si.

[0186] Here, S is the term location information quadruple mentioned above. The corresponding tuple information can be (value, node, type, babelType). Here, value is the term content of the target term, node is the node to which the target term belongs, type is the type of the target term, babelType is the type of the corresponding node, and Si represents the i-th term information quadruple.

[0187] In step 607, text content detection is performed.

[0188] Text content detection involves using regular expressions to detect text content based on the information in the four-tuple of terms.

[0189] In step 608, it is determined whether it matches the regular expression.

[0190] By determining whether a term matches a regular expression, we can identify whether a target term exists in the text content, thereby finding the location information of the target term.

[0191] As an example, when the source language of the entry is Chinese, that is, when the language to be translated is Chinese, it can be matched with the regular expression / [\u4e00-\u9fa5] / to check whether there are Chinese characters in the text content.

[0192] In step 609, if so, the term location information is recorded to a file.

[0193] When a term matches a regular expression, it is handled according to the following two scenarios:

[0194] (1) This entry does not exist in the entry location information database.

[0195] Then, a corresponding Ci is created based on the Si information, and Ci is added to the end of D to represent the latest term.

[0196] Here, C refers to the term location information tuple mentioned above. The corresponding tuple information can be (id, source), where id is the identifier of the target term, which in practical applications can be the content of the target term itself. source is an array composed of multiple L, where L is the source code location information tuple. The tuple information of L can be (type, location), where type is the replacement type of the target term, and location is the source code location information of the target term. Ci represents the i-th term information tuple. D refers to the location information database mentioned above, indicating that the term location information database is an array structure composed of n Cs.

[0197] (2) The term already exists in the term location information database.

[0198] Based on the information in Ci.id, the index information n of the existing term in D is found, and the Ci.source information is appended to the end of D[n].source to add new position information for the same term. Here, Ci.id is the term identifier mentioned above.

[0199] In step 610, the extraction of term location information is completed.

[0200] The above methods enable the extraction of target term location information. Therefore, page language translation can be performed based on the target term's location information. (See [link to relevant documentation]). Figure 6B , Figure 6B This is a schematic diagram of the term processing flow in the page language translation method provided in this application embodiment, which specifically includes the following steps:

[0201] In step 611, term processing begins.

[0202] After extracting the location information of the target term, the page language translation device can begin to process the term based on its location information.

[0203] In step 612, the location information of the term to be processed is determined.

[0204] Here, the term location information to be processed is the term location information obtained from steps 601 to 610.

[0205] In step 613, the entries are sorted and traversed.

[0206] The terms are sorted, i.e., arranged in descending order of length. Assume the term location information extraction step yields n unique terms, resulting in a list D of length n. The list D of length n is sorted in descending order of term length. By iterating through list D, D[i] represents the term currently being processed.

[0207] In step 614, it is determined whether there are any unprocessed terms.

[0208] By checking if there are any unprocessed terms in the term list D, it is determined whether there are any terms that have not yet been processed by the function. This ensures that each term to be processed is processed by the function, i.e., included in the translation function. Here, function processing refers to the translation function mentioned above, which integrates the target term into the page code file.

[0209] In step 615, if so, iterate through the list of different positions of the word entry.

[0210] When there are more terms, for example, when there are multiple target terms, the target terms will be distributed in different positions. D[i].source represents the list of position information in the i-th term. Traversing this list, D[i].source[j] represents the j-th position that is currently being processed.

[0211] In step 616, it is determined whether any entries have been left unprocessed.

[0212] By determining whether there are any other unprocessed positions in the current term, we can ensure that each term is processed by the function.

[0213] In step 617, the file content is read and split into line arrays.

[0214] In some embodiments, the known location format is: / path / to / file#line number#column number. By splitting the string, the name of the page code file, the line where the target term is located, and the column where the target term is located can be obtained. The content of the file can be read according to the name of the page code file, and the file content of the page code file can be split into an array line by line according to the newline character.

[0215] In step 618, the original code content lineStr of the line number where the target term is located is obtained.

[0216] After obtaining the line number corresponding to the target term, the original text content in the code file, i.e., lineStr, can be found in the array containing the content of each line of the page code file based on the line number.

[0217] In step 619, the form of the search term and the replacement string replaceStr are determined.

[0218] In some embodiments, D[i].source[j] is an L tuple from which (type, location) information can be obtained. Let keyword represent the current term content D[i].id. Based on keyword, the following forms of term search (searchStr) can be tried:

[0219] (1) Enclosed in double quotes: searchStr = "${keyword}"

[0220] (2) Enclosed in single quotes: searchStr=ˋ'${keyword}'ˋ

[0221] (3) No package: searchStr=keyword

[0222] The `type` parameter, representing the type of term being replaced, has three possible values: `jsx`, `text`, and `template`. The corresponding replacement string (`replaceStr`) for these three values ​​is as follows:

[0223] (1) When the value of type is jsx, replaceStr is ˋ{t('${keyword}')}ˋ

[0224] (2) When the value of type is template, replaceStr is ˋ${t('${keyword}')}ˋ

[0225] (3) When the value of type is text, replaceStr is ˋt('${keyword}')ˋ

[0226] Here, t() is the t function, which is the translation function mentioned above.

[0227] In step 620, the corresponding line entry is included using a translation function.

[0228] When translating a line of terms, considering the possibility of multiple terms in a line, especially when long terms have been replaced, term collisions may occur. Therefore, it is necessary to use regular expressions to split lineStr: / (?<![a-zA-Z])t\(.+?\) / . This will remove terms already included by function t from the current line before further processing. Here, function t is the translation function.

[0229] In step 621, the comparison function processes the line content before and after processing.

[0230] By comparing the line content before and after the function processing, it can be determined whether the term has been successfully included by the translation function.

[0231] In step 622, it is determined whether the entry has been processed successfully.

[0232] The success of the term processing is determined by comparing the content of lineStr before and after the function processing. If they are equal, the processing has failed; otherwise, it has succeeded.

[0233] In step 623, if so, record the file path where the entry was successfully processed.

[0234] Once the target term is successfully included by the function, the current file name needs to be added to the term processing success list P for further processing. Here, P represents the term processing success list, which is an array structure composed of absolute file path strings.

[0235] In step 624, the reference statement is detected and added.

[0236] After obtaining the list P of code file paths that have been successfully processed for the target term, the files in the list are processed one by one, with two scenarios:

[0237] Scenario 1: Import reference statements already exist in the file, no processing is required.

[0238] Case 2: If there is no import statement in the file, add the import statement to the first line of the file.

[0239] Here, the Import statement imports multilingual translation functions, allowing the translation functions to be called directly in the code file without rewriting them.

[0240] In step 625, the term processing ends.

[0241] The following description continues to illustrate the exemplary structure of the page language translation device 555 provided in the embodiments of the present invention as a software module. In some embodiments, such as... Figure 2 As shown, the software modules of the page language translation device 555 may include: an abstract syntax tree generation module 5551, a location information determination module 5552, a function processing module 5553, and a page translation module 5554.

[0242] Abstract syntax tree generation module 5551 generates an abstract syntax tree corresponding to the page code file based on the application's page code file;

[0243] The location information determination module 5552 is used to determine the location information of the target term in the page code file based on the abstract syntax tree; wherein, the target term is a term in the page code file that is not included by the translation function, and the translation function is used to translate the language of the term in the page code file from the source language to the target language;

[0244] The function processing module 5553 is used to integrate the target term into the translation function of the page code file based on the position information of the target term, so that the target term is included by the translation function;

[0245] The page translation module 5554 is used to execute the translation function to translate the source language page of the application into the target language page.

[0246] In some embodiments, the abstract syntax tree generation module 5551 is further configured to divide multiple characters in the page code file of the application into multiple lexical units; construct multiple syntax structures of the page code file according to the syntax rules of the page code file and the multiple lexical units; and generate an abstract syntax tree corresponding to the page code file using the syntax structures as nodes.

[0247] In some embodiments, the location information determination module 5552 is further configured to determine the node of the target type in the abstract syntax tree; extract the text content in the node of the target type; extract the target term from the text content; and determine the location information of the target term in the page code file.

[0248] In some embodiments, the location information determination module 5552 is further configured to traverse the nodes of the target type in the abstract syntax tree and perform the following operation on the traversed nodes: extract text content from the nodes according to the type and structure of the nodes by calling the text extraction function.

[0249] In some embodiments, the location information determination module 5552 is further configured to use regular expressions to extract the source language text content from the text content extracted from each of the nodes as candidate terms, to obtain at least one candidate term; and to filter from the at least one candidate term to obtain candidate terms not included in the translation function as the target term.

[0250] In some embodiments, the location information determination module 5552 is further configured to obtain a term information quadruple corresponding to the target term, the term information quadruple including the term content of the target term, the type of the target term, the node to which the target term belongs, and the type of the corresponding node; and determine the location information of the target term in the page code file based on the term information quadruple corresponding to the target term.

[0251] In some embodiments, the location information determination module 5552 is further configured to: if the location information of the target term is not recorded in the term location information database, generate a term location information tuple for the target term based on the term information quadruple corresponding to the target term, and add the term location information tuple to the term location information database; wherein the term location information tuple includes the identifier of the target term and the source code location information of the target term; if the location information of the target term is recorded in the term location information database, update the location information of the target term in the term location information database based on the source code location information of the target term.

[0252] In some embodiments, the number of target terms is multiple. Based on the position information of the target terms, the function processing module 5553 is further configured to sort the multiple target terms in descending order of content length to obtain a target term sequence; based on the position information of the target terms, and in accordance with the order of the target terms in the target term sequence, each target term is sequentially incorporated into the translation function of the page code file so that the target terms are included by the translation function.

[0253] In some embodiments, the function processing module 5553 is further configured to, for the target terms in the target term sequence that currently need to be incorporated into the translation function of the page code file: based on the line number of the target term in the page code file, search for the code content corresponding to the line number in the page code file; and incorporate the target term in the code content into the translation function of the page code file, so that the target term in the code content is included by the translation function.

[0254] In some embodiments, the page language translation device 555 further includes: a code file determination module, configured to obtain a list of paths corresponding to the code files of the application; and scan the list of paths using wildcard expansion to determine the page code files of the application.

[0255] In some embodiments, the page language translation device 555 further includes: a quotation statement adding module, used to perform quotation statement detection on the page code file containing the target term, and obtain a detection result; if the detection result indicates that the page code file does not contain the target quotation statement, the target quotation statement is used to introduce the translation function into the page code file, and the target quotation statement is added to the page code file.

[0256] In some embodiments, the abstract syntax tree generation module 5551 is further configured to divide multiple characters in the page code file of the application into multiple lexical units; construct multiple syntax structures of the page code file according to the syntax rules of the page code file and the multiple lexical units; and generate an abstract syntax tree corresponding to the page code file using the syntax structures as nodes.

[0257] This application provides a computer program product comprising a computer program or computer-executable instructions stored in a computer-readable storage medium. A processor of a page language translation device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the page language translation device to perform the page language translation method described above in this application.

[0258] This application provides a computer-readable storage medium storing computer-executable instructions or a computer program. When the computer-executable instructions or the computer program are executed by a processor, the processor will execute the page language translation method provided in this application. For example, ... Figure 3A , Figure 3B ,and Figure 3C The methods shown are as follows.

[0259] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.

[0260] In some embodiments, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.

[0261] As an example, computer-executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).

[0262] As an example, computer-executable instructions may be deployed to execute on a single page language translation device, or on multiple page language translation devices located in one location, or on multiple page language translation devices distributed across multiple locations and interconnected via a communication network.

[0263] In summary, the embodiments of this application significantly improve the efficiency and accuracy of multilingual support. They not only reduce the workload of manually searching and identifying terms, but also optimize the translation process by automating the processing and sorting of multiple target terms. Furthermore, by establishing a term location information database, code maintenance and updates are facilitated. In large-scale codebase applications, this meets the needs of the global market and effectively reduces the cost of multilingual transformation for large projects.

[0264] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.

Claims

1. A method for translating page language, characterized in that, The method includes: Based on the application's page code file, an abstract syntax tree corresponding to the page code file is generated; Based on the abstract syntax tree, the location information of the target term in the page code file is determined; The target term is a term in the page code file that is not included in the translation function. The translation function is used to translate the language of the term in the page code file from the source language to the target language. Based on the location information of the target term, the target term is integrated into the translation function of the page code file so that the target term is included in the translation function; The translation function is executed to translate the source language page of the application into the target language page.

2. The method according to claim 1, characterized in that, Determining the location information of the target term in the page code file based on the abstract syntax tree includes: Determine the node of the target type in the abstract syntax tree; Extract the text content from nodes of the target type; The target term is extracted from the text content, and the position information of the target term in the page code file is determined.

3. The method according to claim 2, characterized in that, The extraction of text content from nodes of the target type includes: Traverse the nodes of the target type in the abstract syntax tree, and perform the following operations on the traversed nodes: By calling the text extraction function, the text content is extracted from the node according to the node's type and structure.

4. The method according to claim 2, characterized in that, The step of extracting the target term from the text content includes: For the text content extracted from each of the nodes, regular expressions are used to extract the text content of the source language from the text content as candidate terms, resulting in at least one candidate term; Candidate terms not included in the translation function are selected from the at least one candidate term and used as the target term.

5. The method according to any one of claims 2 to 4, characterized in that, Determining the location information of the target term in the page code file includes: Obtain the term information quadruple corresponding to the target term, wherein the term information quadruple includes the term content of the target term, the type of the target term, the node to which the target term belongs, and the type of the corresponding node; Based on the four-tuple of term information corresponding to the target term, the position information of the target term in the page code file is determined.

6. The method according to claim 5, characterized in that, The location information includes source code location information, which is used to indicate the line number of the target term in the page code file; the application has a term location information database for recording the location information of terms; The step of determining the position information of the target term in the page code file based on the term information quadruple corresponding to the target term includes: If the location information of the target term is not recorded in the term location information database, a term location information tuple for the target term is generated based on the term information quadruple corresponding to the target term, and the term location information tuple is added to the term location information database. The term location information tuple includes the identifier of the target term and the source code location information of the target term; If the term location information database records the location information of the target term, the location information of the target term in the term location information database is updated based on the source code location information of the target term.

7. The method according to claim 1, characterized in that, The number of target terms is multiple, and the step of integrating the target terms into the translation function of the page code file based on the location information of the target terms includes: The target terms are sorted in descending order of content length to obtain a target term sequence. Based on the location information of the target terms, each target term is sequentially integrated into the translation function of the page code file according to the order of the target terms in the target term sequence, so that the target terms are included in the translation function.

8. The method according to claim 7, characterized in that, The location information includes the line number of the target term in the page code file; The step of integrating each target term into the translation function of the page code file sequentially according to the order of the target terms in the target term sequence, based on the location information of the target terms, includes: For the target terms in the target term sequence that currently need to be incorporated into the translation function of the page code file: Based on the line number of the target term in the page code file, find the code content corresponding to the line number in the page code file; The target term in the code content is incorporated into the translation function of the page code file, so that the target term in the code content is included in the translation function.

9. The method according to claim 1, characterized in that, After incorporating the target term into the translation function of the page code file based on the target term's location information, the method further includes: The code files containing the target terms are subjected to citation statement detection, and the detection results are obtained. If the detection result indicates that the page code file does not contain a target reference statement, the target reference statement is used to introduce the translation function into the page code file, and the target reference statement is added to the page code file.

10. The method according to claim 1, characterized in that, Before generating the abstract syntax tree corresponding to the application-based page code file, the method further includes: Obtain the list of paths corresponding to the code files of the application; The path list is scanned using wildcard expansion to determine the application's page code file.

11. The method according to claim 1, characterized in that, The application-based page code file generates an abstract syntax tree corresponding to the page code file, including: The multiple characters in the page code file of the application are divided into multiple lexical units; Based on the syntax rules of the page code file and the multiple lexical units, multiple syntax structures of the page code file are constructed. Using the grammatical structure as nodes, an abstract syntax tree corresponding to the page code file is generated.

12. A page language translation device, characterized in that, The device includes: The abstract syntax tree generation module is used to generate an abstract syntax tree corresponding to the page code file based on the application's page code file. The location information determination module is used to determine the location information of the target term in the page code file based on the abstract syntax tree; wherein, the target term is a term in the page code file that is not included by the translation function, and the translation function is used to translate the language of the term in the page code file from the source language to the target language; The function processing module is used to integrate the target term into the translation function of the page code file based on the location information of the target term, so that the target term is included in the translation function; A page translation module is used to execute the translation function to translate the source language page of the application into a target language page.

13. A page language translation device, characterized in that, The page language translation device includes: Memory is used to store executable instructions or computer programs. A processor, when executing computer-executable instructions or computer programs stored in the memory, implements the method according to any one of claims 1 to 11.

14. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the method described in any one of claims 1 to 11.

15. A computer program product comprising computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the method according to any one of claims 1 to 11.