Automatic multi-language construction method, system and device and storage medium
By automatically building tree structure files and translation result libraries, the problem of cumbersomeness and high error rate of manual translation in web project development is solved, efficient and accurate multi-language support is achieved, international development process is simplified, and products are improved. quality.
Patent Information
- Application Number
- CN202411014663.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-12-20
AI Technical Summary
Existing internationalization solutions require manual extraction and translation of copywriting in web project development, resulting in cumbersome and error-prone, affecting development efficiency and code maintainability.
By obtaining the project source file, building a tree-like structure file, automatically identifying and extracting text content, assigning location tags, generating language packages, and using the translation result library to automatically generate multi-language packages, dynamically replace text content, and realize language switching.
It significantly improves the efficiency and accuracy of multilingual support, reduces the workload and maintenance costs of developers, simplifies project management and deployment, and improves the development efficiency and overall quality of international products.
Smart Images

Figure CN119166251A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Web development technology, and in particular to a method, system, device and storage medium for automatic multi-language construction. Background Art
[0002] Internationalization is a key technology in Web project development. It involves designing and implementing software products that can adapt to different languages and cultural environments, including using Unicode character sets to support global languages, optimizing global content distribution using content delivery networks (CDNs), and managing content in different languages through multilingual content management systems. Internationalization is a common and important requirement. Through internationalization, pages can display different content according to different countries and regions, or switch according to user language preferences.
[0003] In the prior art, there are two main internationalization solutions: one is to adopt a multi-code base solution, by developing independent code bases for different languages, and requesting the corresponding code by switching different domain names, so as to achieve multi-language switching. The other is a plug-in solution, using the popular internationalized i18n plug-in on the market to configure and switch multiple languages. Developers only need to maintain a set of code and configure content in different languages through language package objects.
[0004] However, in these internationalization solutions, human intervention is usually required to manually extract and translate text, which is not only cumbersome but also very error-prone. In addition, in order to support internationalization, the project source code needs to be modified accordingly, which affects the readability and maintainability of the code, making subsequent development and maintenance more difficult. It can be seen that the existing internationalization solutions have the defects of complex development and maintenance, which affects the development efficiency and overall quality of the product. Summary of the invention
[0005] The present application provides a method, system, device and storage medium for automatic multi-language construction, which are used to improve the generation efficiency of language packages and reduce the maintenance cost of multi-language development.
[0006] The first aspect of the present application provides a method for automatic multi-language construction, comprising:
[0007] Obtaining a project source file, and building a tree structure file based on the project source file;
[0008] Traversing the tree-structured file, identifying and extracting text content in the tree-structured file;
[0009] assigning a corresponding position tag to each of the text contents, and generating a first language package based on the text contents and the position tags;
[0010] Extracting the target text to be translated from the first language package, and obtaining translation results in a plurality of preset languages from a translation result database according to the target text;
[0011] generating a second language package of the preset multiple languages according to the translation result and the location tag;
[0012] When receiving a request to switch the language used in the current text content to a target language, determining a target language package corresponding to the target language in the second language package;
[0013] The target language package and the target location tag corresponding to the current text content are used to perform text replacement on the current text content.
[0014] Optionally, extracting the target text to be translated in the first language package, and obtaining translation results in a plurality of preset languages in a translation result library according to the target text, includes:
[0015] Extracting the target text to be translated from the first language package, and searching in a translation result database whether there is a translation result of the target text in a preset language;
[0016] If yes, obtaining the translation result from the translation result library;
[0017] If not, the translation API is called to translate the target text into the preset language, and the translation result is saved in the translation result library.
[0018] Optionally, traversing the tree structure file to identify and extract text content in the tree structure file includes:
[0019] Traversing each node in the tree structure file, and checking whether each node contains a string literal in a preset order;
[0020] If so, the string literal is determined as text content and the text content is extracted.
[0021] Optionally, using the target language package and the target location tag corresponding to the current text content to perform text replacement on the current text content includes:
[0022] Determine the current text content displayed on the page, and determine the target location tag corresponding to the current text content;
[0023] A corresponding target translation result is determined in the target language package according to the target location tag, and the current text content is replaced with the target translation result.
[0024] Optionally, the method further includes:
[0025] Displaying the translation result library through the platform and receiving a user's request to modify the translation result library;
[0026] Updating the translation result library according to the modification request;
[0027] The second language package is regenerated according to the updated translation result library.
[0028] Optionally, the first language package and the second language package are in JSON format, and the text content is encoded in UTF-8.
[0029] A second aspect of the present application provides a system for automatic multi-language construction, comprising:
[0030] A construction unit, used for obtaining a project source file and constructing a tree structure file based on the project source file;
[0031] An extraction unit, used to traverse the tree structure file, identify and extract text content in the tree structure file;
[0032] A first generating unit, configured to assign a corresponding position tag to each of the text contents, and generate a first language package based on the text contents and the position tags;
[0033] an acquisition unit, configured to extract a target text to be translated from the first language package, and acquire translation results in a plurality of preset languages from a translation result database according to the target text;
[0034] A second generating unit, configured to generate a second language package of the preset multiple languages according to the translation result and the position tag;
[0035] a determining unit, configured to determine a target language package corresponding to the target language in the second language package when receiving a request to switch the language used in the current text content to the target language;
[0036] The replacement unit is used to perform text replacement on the current text content using the target language package and the target position tag corresponding to the current text content.
[0037] Optionally, the acquiring unit is specifically used for:
[0038] Extracting the target text to be translated from the first language package, and searching in a translation result database whether there is a translation result of the target text in a preset language;
[0039] If yes, obtaining the translation result from the translation result library;
[0040] If not, the translation API is called to translate the target text into the preset language, and the translation result is saved in the translation result library.
[0041] Optionally, the extraction unit is specifically used for:
[0042] Traversing each node in the tree structure file, and checking whether each node contains a string literal in a preset order;
[0043] If so, the string literal is determined as text content and the text content is extracted.
[0044] Optionally, the replacement unit is specifically used for:
[0045] Determine the current text content displayed on the page, and determine the target location tag corresponding to the current text content;
[0046] A corresponding target translation result is determined in the target language package according to the target location tag, and the current text content is replaced with the target translation result.
[0047] Optionally, the system further includes: a modification unit, wherein the modification unit is specifically configured to:
[0048] Displaying the translation result library through the platform and receiving a user's request to modify the translation result library;
[0049] Updating the translation result library according to the modification request;
[0050] The second language package is regenerated according to the updated translation result library.
[0051] Optionally, the first language package and the second language package are in JSON format, and the text content is encoded in UTF-8.
[0052] A third aspect of the present application provides a device for automatic multi-language construction, the device comprising:
[0053] Processor, memory, input-output unit, and bus;
[0054] The processor is connected to the memory, the input and output unit, and the bus;
[0055] The memory stores a program, and the processor calls the program to execute the first aspect and any optional method of automatic multi-language construction in the first aspect.
[0056] A fourth aspect of the present application provides a computer-readable storage medium, on which a program is stored. When the program is executed on a computer, the program executes the method of automatic multi-language construction according to the first aspect and any optional item in the first aspect.
[0057] It can be seen from the above technical solutions that this application has the following advantages:
[0058] The automated process of this application significantly improves the efficiency and accuracy of multi-language support. First, a tree-structured file is generated based on the project source file, and then the tree-structured file is traversed to automatically identify and extract the text content that needs to be translated. A corresponding position tag is assigned to each text content, and a first language package is constructed based on the text content and the position tag. This process not only avoids the tedious work of manually extracting text, but also greatly reduces the possibility of errors. Subsequently, the system queries the translation result library based on the target text to be translated in the first language package, and automatically generates a second language package in multiple preset languages based on the query results, further reducing the workload of developers in multi-language development. When the user switches the target language, the system reads the corresponding target language package and dynamically replaces the text content on the display interface with the translated text based on the position tag.
[0059] By automatically extracting the text content in the source code and combining it with the location tag to generate the first language package, and then automatically generating the second language packages in multiple languages based on the first language package and the translation result library, the efficiency of language package generation is improved and the maintenance cost of multi-language development is reduced. In addition, this application allows language switching to be achieved by dynamically loading the corresponding target language package only when the project is running without changing the source code, without maintaining code libraries in multiple languages, thereby simplifying project management and deployment and improving the development efficiency and overall quality of international products. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solution in the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0061] Figure 1 A flowchart of an embodiment of the method for automatic multi-language construction provided in this application;
[0062] Figure 2 A schematic diagram of an embodiment of a flow chart of calling a translation API in the method for automatic multi-language construction provided by the present application;
[0063] Figure 3A schematic diagram of an embodiment of a flow chart of extracting text content in the method for automatic multi-language construction provided in the present application;
[0064] Figure 4 A flowchart of an embodiment of text replacement in the method for automatic multi-language construction provided by the present application;
[0065] Figure 5 A schematic diagram of an embodiment of the flow chart showing the translation result library in the method for automatic multi-language construction provided in the present application;
[0066] Figure 6 A schematic diagram of the structure of an embodiment of the automatic multi-language construction system provided by the present application;
[0067] Figure 7 A schematic diagram of the structure of an embodiment of the apparatus for automatic multi-language construction provided in the present application. DETAILED DESCRIPTION
[0068] The present application provides a method, system, device and storage medium for automatic multi-language construction, which are used to improve the generation efficiency of language packages and reduce the maintenance cost of multi-language development.
[0069] It should be noted that the method for automatic multi-language construction provided in this application can be applied to a terminal or a server. For example, the terminal can be a smart phone or a computer, a tablet computer, a smart TV, a smart watch, a portable computer terminal, or a fixed terminal such as a desktop computer. For the convenience of explanation, this application uses the terminal as the execution subject for example.
[0070] See also Figure 1 , Figure 1 An embodiment of the method for automatic multi-language construction provided by the present application includes:
[0071] S101, obtaining a project source file, and constructing a tree structure file based on the project source file;
[0072] The terminal first obtains the project source file from the root directory of the project, which includes the source code. The terminal uses the abstract syntax tree AST to parse the source code, reads the source code content and parses the source code into an AST tree structure composed of nodes to obtain a tree structure file for subsequent traversal and processing. In the tree structure file, each node represents an element in the code, such as a variable declaration, a function call, a loop statement, etc. The parsed tree structure file organizes the code into a hierarchical form, allowing the terminal to more easily identify and operate various parts of the source code.
[0073] It should be noted that the project source files also include a pre-created configuration file, which specifies the text language used in the current project development, that is, the default language (such as Chinese), and the preset multiple languages that the project can display (such as English, French, German, etc.). In addition, the project source files may include source code in different programming languages such as HTML, CSS, JavaScript, Python, etc. Therefore, when building a tree-structured file, the terminal will automatically select the appropriate parsing library to parse the source code file according to the programming language. For example, Esprima or Acorn can be automatically called for JavaScript, and the AST module can be automatically called for Python.
[0074] S102, traversing the tree structure file, identifying and extracting text content in the tree structure file;
[0075] In the tree structure file, there are some nodes containing text content, and these text contents need to be translated during the internationalization process. Specifically, the terminal traverses the tree structure file, accesses each node in the tree structure file, identifies and extracts the text content contained in each node, and these text contents may include labels of user interface elements, button texts, prompt information, etc.
[0076] The terminal can use depth-first traversal of each node, starting from the top-level structure of the code, going deeper into each child node layer by layer, and judging whether there is text content that needs to be translated based on the node type. For example, in HTML, the text content may be directly contained in the tag node, and in JavaScript, the text content may appear as a variable value or string literal, or as a text element related to the user interface in other programming languages. For each node identified as containing text content, the terminal will extract the text content therein. The order of extracting the text content can be the order in which the nodes appear in the source code, which helps to maintain the consistency of the code structure, or it can be other user-defined orders, such as extraction according to the order of specific functional modules of the application, which is not limited here.
[0077] S103, assigning a corresponding position tag to each text content, and generating a first language package based on the text content and the position tag;
[0078] The terminal assigns a unique corresponding position tag to each extracted text content, and the position tag is used to identify the position of the text content in the source code. Since each node in the tree structure file contains its position information, such as line number and column number, the position information can be directly associated with the specific position of the node in the source code. By assigning a position tag associated with the position information to the text content, the specific position of the text content in the source code can be located according to the position tag.
[0079] The terminal uses these location tags to clearly associate each text content with its location in the source code, establishes a mapping relationship between each text content and its corresponding unique location tag, generates a first language package based on the mapping relationship, and saves the first language package to a specified location. As the basis for multi-language support, the first language package provides the necessary basic resources and structure for subsequent translation. Specifically, the first language package can use the location tag as the key and the text content as the value to store the key-value pair structure, which makes the structure and content of the first language package clear, and helps the accuracy and consistency of the subsequent translation process.
[0080] S104, extracting the target text to be translated from the first language package, and obtaining translation results in a plurality of preset languages from a translation result database according to the target text;
[0081] During the translation phase, the terminal reads and loads the generated first language package from the specified location. The first language package contains all the text content to be translated in the project and the corresponding location tags. By traversing the first language package, the terminal can identify and extract each target text to be translated. Based on these target texts to be translated, the terminal queries the translation result library to obtain the corresponding translation results in multiple preset languages. The translation result library is a multilingual database that stores translation texts for different languages. The preset multiple languages are specified by the user in the configuration file.
[0082] When querying the translation result library, the terminal will retrieve the corresponding translation text according to the content of the target text. If there are translation texts corresponding to the preset language in the translation result library, the terminal will associate these translation texts with the target text and generate corresponding translation results for the preset language.
[0083] S105, generating second language packages in a plurality of preset languages according to the translation results and the position tags;
[0084] After the terminal extracts the translation result of the preset language of the target text, it establishes a mapping relationship between the position tag corresponding to the target text and the translation result. Through the position tag, each translation result can be associated with a specific position in the source code. After all the target texts are translated, the terminal generates a second language package for each preset language based on the translation results and position tags, and saves it to the specified location. The structure of the second language package is the same as the first language package.
[0085] S106, when a request to switch the language used in the current text content to the target language is received, determining a target language package corresponding to the target language in the second language package;
[0086] The terminal receives a user's request to switch the target language through the setting options of the user interface or automatically detects the user's region and language preferences. The request is specifically a request to switch the language used in the current text content to the target language. The current text content specifically refers to the text content displayed on the current page. Specifically, a language switching option can be provided in the user interface, such as a drop-down menu or button, and the request to switch the target language is determined according to the user's selection. The terminal parses the request and identifies the target language that the user wants to switch to. According to the target language, the terminal reads the multiple second language packages created in step S105 from the specified location, and determines the target language package corresponding to the target language. If the target language package requested by the user exists, step S107 is directly executed. If it does not exist, the system can fall back to the default language or provide other available language options.
[0087] In order to improve the response speed and user experience, the terminal can cache the commonly used second language packages at runtime so that they can be quickly loaded when a request to switch to the target language is received.
[0088] S107: Use the target language package and the target location tag corresponding to the current text content to perform text replacement on the current text content.
[0089] In actual operation, the terminal uses the translation results in the target language package and the target location label corresponding to the current text content to replace the text, and dynamically inserts the translated text into the user interface, so that the user interface can display the translated text based on the target language of the current text content without reloading, thereby realizing the user's language switching needs.
[0090] Since the location tags of text content in different language packs are fixed, the location tag list of text content in the current page can be cached during user browsing, and the text content recorded in the cache is loaded and replaced first when switching languages, further improving the loading time of the translated text. At the same time, this method also supports fast iteration and multi-language support. In actual application, it only needs to modify the preset multiple languages specified in the configuration file, and the second language pack of the corresponding language can be automatically generated through steps S104 to S105, thereby improving the internationalization capability of the application.
[0091] In some specific embodiments, the JSON format can be used as the data format of the first language package and the second language package, and the text content can be encoded in combination with UTF-8 encoding, thereby realizing a structured, readable and cross-platform compatible multi-language support solution, thereby improving the maintainability and extensibility of multi-language development.
[0092] In this embodiment, the automated process significantly improves the efficiency and accuracy of multi-language support. First, a tree structure file is generated based on the project source file, and then the tree structure file is traversed to automatically identify and extract the text content that needs to be translated. A corresponding position tag is assigned to each text content, and a first language package is constructed based on the text content and the position tag. This process not only avoids the tedious work of manually extracting text, but also greatly reduces the possibility of errors. Subsequently, the system queries the translation result library based on the target text to be translated in the first language package, and automatically generates a second language package in multiple preset languages based on the query results, further reducing the workload of developers in multi-language development. When the user switches the target language, the system reads the corresponding target language package and dynamically replaces the text content on the display interface with the translated text based on the position tag.
[0093] By automatically extracting the text content in the source code and combining it with the location tags to generate the first language package, and then automatically generating the second language packages in multiple languages based on the first language package and the translation result library, the efficiency of language package generation is improved and the maintenance cost of developers is reduced. In addition, this application allows the language switching to be achieved by dynamically loading the corresponding target language package only when the project is running without changing the source code, without maintaining code bases in multiple languages, thereby simplifying the management and deployment of the project and improving the development efficiency and overall quality of the product.
[0094] In step S104, if there is no translation result of the target text in the translation result library, the translation API can be called to translate the target text in real time. Figure 2 , Figure 2 An optional embodiment of calling a translation API in the method for automatic multi-language construction provided by the present application includes:
[0095] S201, extracting a target text to be translated from a first language package, and searching a translation result database for a translation result of the target text in a preset language;
[0096] The system first analyzes the first language package, identifies and extracts all target texts to be translated, which are the content in the default language (such as Chinese) and need to be translated into multiple preset languages. For each target text to be translated and each preset language, the system searches the translation result library to determine whether there is already a translation result in the preset language corresponding to the target text.
[0097] The translation result library is a system for storing and managing translation content, specifically in the form of a database. The translation result library can store translation results in multiple languages, which can be quickly retrieved and used. If the translation results of the preset language of the target text already exist in the translation result library, the terminal executes step S202 to directly extract these translation results from the translation result library. If there are no existing translation results in the translation result library, the terminal executes step S203 to call the translation API to obtain the translation until the translation results of the target text in all preset languages are obtained.
[0098] S202: If yes, obtain the translation result from the translation result database;
[0099] S203: If not, call the translation API to translate the target text into a preset language, and save the translation result into a translation result database.
[0100] When the terminal fails to find the preset language translation of the target text in the translation result library, it can call the translation API for real-time translation. The terminal will specifically send a translation request to the translation API through an HTTP request or other protocol. The translation request includes information such as the target text to be translated and the preset language. The terminal then receives the translation result returned by the translation API and saves the translation result to the translation result library.
[0101] Furthermore, in order to ensure data security and reduce dependence on external services, the translation API can be privately deployed, and the terminal can dynamically select different translation APIs according to different preset languages, maximizing the advantages of each translation API and providing the best translation services for users of different languages.
[0102] In this embodiment, the terminal first extracts the target text to be translated from the first language package, and queries the translation result library to see whether there are translation results in the corresponding preset language. If corresponding translation results already exist, the system will directly extract these translation results to avoid duplication of work. If the translation results are missing, the system calls the translation API for real-time translation, and then saves the translation results returned by the translation API back to the translation result library, ensuring the continuous update and availability of translation resources.
[0103] In step S102, the text content can be extracted by determining the node attributes of the tree structure file. Figure 3 , Figure 3 An optional embodiment of extracting text content from a tree structure file in this application includes:
[0104] S301, traverse each node in the tree structure file, and check whether each node contains a string literal in a preset order;
[0105] S302: If yes, determine the string literal as text content and extract the text content.
[0106] In this embodiment, the terminal starts from the root node of the tree structure file and recursively accesses each child node to achieve traversal of the entire tree structure file. During the traversal process, the terminal checks the type of each node, specifically checks the attributes or labels of the node to determine whether the node contains a string literal. A string literal is a fixed string used to represent text content in the source code, expressed as a string surrounded by double quotes or single quotes. During the traversal process, the terminal specifically performs node inspection in a preset order, which can be the logical structure of the source code, the execution order of the source code, or an optimized custom order based on the frequency and importance of the text. If a node is detected as a string literal, the terminal determines its content as the text content to be translated and extracts it. If it is not detected, the next node will continue to be traversed. When extracting the text content, the terminal also records its position information in the source code, and the extracted text content will be used for subsequent translation work.
[0107] In step S107, the current text content can be dynamically replaced based on the location tag. Figure 4 , Figure 4 An optional embodiment of text replacement using a target language package and a position tag for this application includes:
[0108] S401, determining the current text content displayed on the page, and determining the target location tag corresponding to the current text content;
[0109] When receiving a user's request to switch the target language, the terminal first identifies all the page text content displayed on the current page, that is, the current text content. These text contents are usually associated with page elements, such as button text, navigation labels, prompt information, etc. The terminal can determine the location tag corresponding to each text content according to the mapping relationship in the first language package, that is, determine the target location tag.
[0110] S402: Determine a corresponding target translation result in the target language package according to the target position tag, and use the target translation result to replace the current text content.
[0111] The terminal uses the target location tag as an index to query the corresponding target translation results in the target language package, and dynamically replaces the current text content with these target translation results and the target location tag. This replacement operation is dynamic, which means that users can see the current text content updated to the target translation results of the selected language without refreshing the page.
[0112] In this embodiment, the target language pack and the target location tag can be used to dynamically replace the text content, ensuring that the user does not need to wait for the page to be reloaded when switching languages, and can obtain a seamless and smooth experience.
[0113] In some optional embodiments, the translation result library can be displayed and optimized. Figure 5 , Figure 5 This is an optional embodiment of the present application related to the translation result library, which includes:
[0114] S501, displaying the translation result database through the platform, and receiving the user's modification request for the translation result database;
[0115] In this embodiment, in order to reduce the communication cost of developers and translators and improve the professionalism of translation work, a user-friendly translation result display platform can be developed, through which all translation items in the translation result library are intuitively displayed, and an interface is provided for translators to submit modification requests. The modification request includes editing of existing translation results, adding of new translation results or marking of erroneous translation results. The platform also supports search, screening and sorting functions, which is convenient for translators to quickly locate and view the translation content that needs to be modified.
[0116] S502, updating the translation result database according to the modification request;
[0117] Developers or users with corresponding permissions review the translators' modification requests on the platform and update the translation result library based on project requirements and quality standards, ensuring the accuracy and consistency of the translated content.
[0118] S503: Regenerate the second language package according to the updated translation result database.
[0119] Once the translation result library is updated, the regeneration of the second language package is automatically or manually triggered, and the modified translation results are updated in the second language package, thereby ensuring that the translation results displayed to the user when switching languages are the latest and verified.
[0120] In this embodiment, a centralized translation management platform is provided, so that developers and translators can collaborate more efficiently, reducing the time and cost of back-and-forth communication and coordination, and enabling effective management and continuous improvement of translation results, thereby improving the quality and speed of internationalization of multilingual applications.
[0121] The following is a detailed description of the automatic multi-language construction system provided by this application. Figure 6 , Figure 6 Another embodiment of the system for automatic multi-language construction provided by the present application includes:
[0122] A construction unit 601 is used to obtain a project source file and construct a tree structure file based on the project source file;
[0123] An extraction unit 602 is used to traverse the tree structure file, identify and extract text content in the tree structure file;
[0124] A first generating unit 603, configured to assign a corresponding position tag to each text content, and generate a first language package based on the text content and the position tag;
[0125] The acquisition unit 604 is used to extract the target text to be translated in the first language package, and obtain translation results in a plurality of preset languages in the translation result database according to the target text;
[0126] The second generating unit 605 is used to generate second language packages of a plurality of preset languages according to the translation results and the position tags;
[0127] A determination unit 606, configured to determine a target language package corresponding to the target language in the second language package when receiving a request to switch the language used in the current text content to the target language;
[0128] The replacement unit 607 is used to perform text replacement on the current text content using the target language package and the target position tag corresponding to the current text content.
[0129] Optionally, the acquiring unit 604 is specifically configured to:
[0130] Extracting the target text to be translated from the first language package, and searching in the translation result database whether there is a translation result of the target text in a preset language;
[0131] If yes, then obtain the translation result from the translation result database;
[0132] If not, the translation API is called to translate the target text into a preset language, and the translation result is saved in a translation result library.
[0133] Optionally, the extraction unit 602 is specifically configured to:
[0134] Traverse each node in the tree structure file and check whether each node contains a string literal in a preset order;
[0135] If so, the string literal is determined to be text content and the text content is extracted.
[0136] Optionally, the replacing unit 607 is specifically configured to:
[0137] Determine the current text content displayed on the page, and determine the target location tag corresponding to the current text content;
[0138] The corresponding target translation result is determined in the target language package according to the target location tag, and the current text content is replaced with the target translation result.
[0139] Optionally, the system further includes: a modification unit 608, wherein the modification unit 608 is specifically configured to:
[0140] Display the translation result database through the platform and receive user requests to modify the translation result database;
[0141] Update the translation result database according to the modification request;
[0142] Regenerate the second language package based on the updated translation result library.
[0143] Optionally, the first language package and the second language package are in JSON format, and the text content is encoded in UTF-8.
[0144] In this embodiment, the functions of each unit are the same as those described above. Figures 1 to 5 The steps in the method embodiment shown correspond to each other and will not be repeated here.
[0145] This application also provides a device for automatic multi-language construction, see Figure 7 , Figure 7 An embodiment of the device for automatic multi-language construction provided by the present application includes:
[0146] Processor 701, memory 702, input and output unit 703, bus 704;
[0147] The processor 701 is connected to the memory 702, the input and output unit 703 and the bus 704;
[0148] The memory 702 stores a program, and the processor 701 calls the program to execute any of the above automatic multi-language construction methods.
[0149] The present application also relates to a computer-readable storage medium, on which a program is stored. When the program is run on a computer, the computer executes any of the above-mentioned methods for automatic multi-language construction.
[0150] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0151] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0152] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0153] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0154] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. A method for automatic multi-language construction, characterized in that: The method comprises: Obtaining a project source file, and building a tree structure file based on the project source file; Traversing the tree-structured file, identifying and extracting text content in the tree-structured file; Assigning a corresponding position tag to each of the text contents, and generating a first language package based on the text contents and the position tags; Extracting the target text to be translated from the first language package, and obtaining translation results in a plurality of preset languages from a translation result database according to the target text; generating a second language package of the preset multiple languages according to the translation result and the location tag; When receiving a request to switch the language used in the current text content to a target language, determining a target language package corresponding to the target language in the second language package; The target language package and the target location tag corresponding to the current text content are used to perform text replacement on the current text content.
2. The method according to claim 1, characterized in that The extracting the target text to be translated in the first language package, and obtaining translation results in a plurality of preset languages in a translation result database according to the target text, includes: Extracting the target text to be translated from the first language package, and searching in a translation result database whether there is a translation result of the target text in a preset language; If yes, obtaining the translation result from the translation result library; If not, the translation API is called to translate the target text into the preset language, and the translation result is saved in the translation result library.
3. The method according to claim 1, characterized in that The traversing the tree structure file to identify and extract text content in the tree structure file includes: Traversing each node in the tree structure file, and checking whether each node contains a string literal in a preset order; If so, the string literal is determined as text content and the text content is extracted.
4. The method according to claim 1, characterized in that: The using the target language package and the target position tag corresponding to the current text content to perform text replacement on the current text content includes: Determine the current text content displayed on the page, and determine the target location tag corresponding to the current text content; A corresponding target translation result is determined in the target language package according to the target location tag, and the current text content is replaced with the target translation result.
5. The method according to claim 1, characterized in that The method further comprises: Displaying the translation result library through the platform and receiving a user's request to modify the translation result library; Updating the translation result library according to the modification request; The second language package is regenerated according to the updated translation result library.
6. The method according to any one of claims 1 to 5, characterized in that The first language package and the second language package are in JSON format, and the text content is encoded in UTF-8.
7. A system for automatic multi-language construction, characterized in that: The system comprises: A construction unit, used for obtaining a project source file and constructing a tree structure file based on the project source file; An extraction unit, used to traverse the tree structure file, identify and extract text content in the tree structure file; A first generating unit, configured to assign a corresponding position tag to each of the text contents, and generate a first language package based on the text contents and the position tags; an acquisition unit, configured to extract a target text to be translated from the first language package, and acquire translation results in a plurality of preset languages from a translation result database according to the target text; A second generating unit, configured to generate a second language package of the preset multiple languages according to the translation result and the position tag; a determining unit, configured to determine a target language package corresponding to the target language in the second language package when receiving a request to switch the language used in the current text content to the target language; The replacement unit is used to perform text replacement on the current text content using the target language package and the target position tag corresponding to the current text content.
8. The system according to claim 7, characterized in that The acquisition unit is specifically used for: Extracting the target text to be translated from the first language package, and searching in a translation result database whether there is a translation result of the target text in a preset language; If yes, obtaining the translation result from the translation result library; If not, the translation API is called to translate the target text into the preset language, and the translation result is saved in the translation result library.
9. An automatic multi-language construction device, characterized in that: The device comprises: Processor, memory, input-output unit, and bus; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the method according to any one of claims 1 to 6.
10. A computer-readable storage medium having a program stored thereon, wherein the program, when executed on a computer, performs the method according to any one of claims 1 to 6.
Citation Information
Cited By
Cross-platform self-adaptive internationalization language dynamic switching method based on database
CN119886164A
Interface display language switching method and device, storage medium and electronic equipment
CN121143932A
Multi-language front-end resource automatic construction method and system based on construction stage
CN121638279A
International page generation method and device, equipment, medium and program product
CN121834083A
