Internationalization method, system and equipment for automation front-end project

By using react i18next internationalization library and big model translation scripts in front-end projects, the internationalization of Chinese copywriting is solved, and the problems of low internationalization processing efficiency and high error risk in the existing technology are achieved, and more efficient and accurate Language file generation simplifies the development process.

CN119204042APending Publication Date: 2024-12-27CHINA ELECTRONICS CLOUD DIGITAL INTELLIGENCE TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411508015.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The existing front-end project internationalization method is inefficient, has high error risk and high cognitive cost. Especially when large projects or multilingual support, developers need to invest a lot of time and resources to manage international keys and translate texts, and existing tools Failed to effectively solve the problem of generating costs of Chinese internationalized documents.

Method used

Use the package function of react i18next internationalization library to wrap Chinese copy, add script commands to the project configuration file, configure code management trigger function, automatically trigger international processing before submitting the code, and use large-scale translation scripts to generate multiple Language internationalization documents to ensure consistency and accuracy of key-value pairs.

Benefits of technology

It significantly reduces the time and complexity of developers in international processing, improves development efficiency, reduces the risk of errors, and makes the generation of Chinese international files more efficient, accurate and smooth.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119204042A_ABST
    Figure CN119204042A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of front-end project internationalization, and provides an automatic front-end project internationalization method, system and equipment, and the method comprises the steps: employing a wrapping function provided by a reaction i18next internationalization library to wrap a Chinese document in a code development process; adding a script command for the Chinese copywriting in the project configuration file of the project, and configuring a quotable script command name for the added script command; and configuring a code management trigger function, and triggering the internationalization processing of the Chinese copywriting according to the configured script command and the configured code management trigger function before the code is submitted. According to the automatic front-end project internationalization method, system and equipment, the development efficiency can be remarkably improved; the development difficulty and thinking burden are reduced, and the development process is smoother.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of front-end project internationalization, and in particular to an automated front-end project internationalization method, system and device. Background Art

[0002] In the practice of internationalization of front-end projects, existing methods require developers to manually define keys for internationalization and write corresponding translation texts for each locale. For example, when using a standard internationalization library, developers first need to determine a common key and then add corresponding translations for each language.

[0003] In practical applications, existing methods have the following defects: 1. Low efficiency. When large projects are involved or multiple languages ​​need to be supported, developers need to invest a lot of time and resources to manage and maintain these internationalized keys and their corresponding translated texts, which leads to a significant increase in workload; 2. High risk of errors. During manual operation, there is a risk of mismatch between keys and translated texts, and there is a risk of omissions and errors in the translation process; 3. High cognitive cost. Developers need to repeatedly consider how to choose keys to ensure that they are both logical and easy to manage subsequently, which seriously increases the complexity and cognitive burden of development.

[0004] In the development field of my country, the development process of front-end copywriting requires developers to translate Chinese content into English as a key. This extra step further increases the translation cost and reduces development efficiency. Although there are some tools that can convert Chinese internationalization files based on English keys into files in other languages ​​by programmatically processing JSON files, these tools do not fundamentally solve the main cost problem, that is, how to efficiently generate Chinese internationalization files.

[0005] Therefore, how to improve and optimize the internationalization automatic workflow so that Chinese internationalization documents can be generated smoothly, efficiently and accurately and solve the cost problem in the existing process has become a technical problem that needs to be solved urgently. Summary of the invention

[0006] In view of this, in order to overcome the deficiencies of the prior art, the present invention aims to provide an automated front-end project internationalization method, system and device.

[0007] According to a first aspect of the present invention, there is provided an automated front-end project internationalization method, comprising: Use the wrapping function provided by the react i18next internationalization library to wrap the Chinese text in the code development process; Add script commands for Chinese text in the project configuration file, and configure referenceable script command names for the added script commands; Configure the code management trigger function to trigger the internationalization of Chinese text according to the configured script command and the configured code management trigger function before submitting the code.

[0008] Preferably, in the automated front-end internationalization method of the present invention, the wrapping function provided by the react i18next internationalization library is used to wrap the Chinese text in the code development process, including: using the react i18next internationalization library for code development, and wrapping the Chinese text in the code development process through the wrapping function provided by the i18next npm package.

[0009] Preferably, in the automated front-end internationalization method of the present invention, the script commands added to the project's engineering configuration file include Chinese key-value pair file generation trigger script commands and large model translation script commands.

[0010] Preferably, in the automated front-end internationalization method of the present invention, the Chinese key-value pair file generation trigger script command in the script command is used to: extract internationalized Chinese text, generate multilingual internationalization files, and configure the keys and values ​​of the Chinese internationalization files in the multilingual internationalization files to be consistent.

[0011] Preferably, in the automated front-end internationalization method of the present invention, the large model translation script command in the script command is used to translate the generated Chinese internationalization file.

[0012] Preferably, in the automated front-end internationalization method of the present invention, configuring the code management trigger function includes: adding an automatic trigger command in the pre-execution callback function of the code management tool, and adding an execution callback function of the automatic trigger command to trigger the internationalization processing of the Chinese text.

[0013] Preferably, in the automated front-end internationalization method of the present invention, before submitting the code, triggering the internationalization processing of the Chinese text according to the configured script command and the configured code management trigger function includes: Create a translation script file in the project root directory, and introduce the large model javascript module into the created translation script file; Read the project configuration file of the project, execute the created translation script file through the large model translation script command in the script command, obtain the project name from the project configuration file of the project, and construct the file name and path of the internationalized file to be processed according to the obtained project name; Generate a trigger script command by using the Chinese key-value pair file in the trigger script command of the trigger function through code management, extract the content from the Chinese text wrapped in the wrapping function as Chinese internationalized JSON data, and read the corresponding Chinese internationalized JSON data into the translation script file according to the file name and path of the internationalized file to be processed; Create a client instance of the big model javascript module, configure the interface communication key between the big model and the client instance, read the Chinese internationalized JSON data corresponding to the file name and path of the internationalized file to be processed in the translation script file through the client instance of the big model javascript module, and pass the read Chinese internationalized JSON data as the content of the user role in the big model to the chat completion interface of the big model; The big model uses the big model translation script command in the script command to translate the Chinese internationalization file, and writes the translation result as non-Chinese internationalization content into the corresponding internationalization file through deserialization.

[0014] Preferably, in the automated front-end internationalization method of the present invention, the big model uses the big model translation script command in the script command to translate the Chinese internationalization file, and writes the translation result as non-Chinese internationalization content into the corresponding internationalization file through deserialization, including: detecting the translation result returned by the chat completion interface of the big model through the translation script file, and when the data format of the returned translation result is JSON, writing the translation result as non-Chinese internationalization content into the corresponding internationalization file through deserialization; when the data format of the returned translation result is not JSON, the big model uses the big model translation script command in the script command to re-translate the Chinese internationalization file, and detects the translation result re-returned by the chat completion interface of the big model through the translation script file, and when the number of re-translations exceeds the preset number, terminating the translation and reporting an error.

[0015] According to a second aspect of the present invention, there is provided an automated front-end project internationalization system, the system comprising an automated front-end project internationalization server, the automated front-end project internationalization server being used to: use a wrapping function provided by a react i18next internationalization library to wrap Chinese text in a code development process; add script commands for the Chinese text in an engineering configuration file of the project, and configure a referenceable script command name for the added script command; configure a code management trigger function, and trigger internationalization processing of the Chinese text according to the configured script command and the configured code management trigger function before submitting the code.

[0016] According to a third aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect of the present invention when executing the program.

[0017] The automated front-end project internationalization method, system and device of the present invention combine the development based on Chinese text with the process of react-i18next parsing internationalized key values. In the development of Chinese context, the t() function is used to wrap the Chinese text, so that react-i18next can generate the JSON key value of the internationalized file based on the Chinese text, and use Chinese as the key value of internationalized translation, forming the basis for the construction of translation scripts based on the big model and the integration with the development process; by adding the script command in package.json and ensuring that the command can automatically trigger the internationalization processing flow when the code is submitted, the integration of the development process is realized; based on the automated translation script of the big model, the big model is used to efficiently construct a JavaScript script that translates from the Chinese JSON file to the JSON file of other languages ​​through precise prompt words, including the correct use of each module in the script, the interaction process with the big model and the processing of the results returned by the big model, so as to achieve an accurate, efficient and sustainable and cyclic translation process.

[0018] During the development process, developers only need to focus on writing Chinese texts. They no longer need to spend a lot of time manually managing international keys and translated texts, which greatly reduces development time and significantly improves development efficiency. Developers no longer need to worry about choosing the right keys, which reduces the difficulty and mental burden of development and makes the development process smoother. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 This is a diagram showing an example of the architecture of an automated front-end project internationalization system according to an embodiment of the present invention; Figure 2 A flowchart of the steps of an automated front-end project internationalization method according to an embodiment of the present invention; Figure 3 A schematic diagram of the structure of the device provided by the present invention. DETAILED DESCRIPTION

[0021] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0022] It should be noted that the following embodiments and features in the embodiments may be combined with each other in the absence of conflict; and, based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making any creative work are within the scope of protection of the present disclosure.

[0023] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.

[0024] Figure 1 FIG. 1 is an example diagram of an architecture of an automated front-end project internationalization system according to an embodiment of the present invention. Figure 1 As shown, the system may include an automated front-end project internationalization server 101, a communication network 102 and / or one or more automated front-end project internationalization clients 103. Figure 1 The example in the figure is a plurality of internationalized clients 103 of the automated front-end projects.

[0025] The automated front-end project internationalization server 101 can be any appropriate server for storing information, data, programs and / or any other suitable type of content. In some embodiments, the automated front-end project internationalization server 101 can perform appropriate functions. For example, in some embodiments, the automated front-end project internationalization server 101 can be used to automatically internationalize the front-end project. As an optional example, in some embodiments, the automated front-end project internationalization server 101 can be used to: use the wrapping function provided by the react i18next internationalization library to wrap the Chinese copy in the code development process; add script commands to the Chinese copy in the project's engineering configuration file, and configure a referenceable script command name for the added script command; configure the code management trigger function, and trigger the internationalization processing of the Chinese copy according to the configured script command and the configured code management trigger function before submitting the code.

[0026] As another example, in some embodiments, the automated front-end project internationalization server 101 may send the automated front-end project internationalization method to the automated front-end project internationalization client 103 for user use based on a request of the automated front-end project internationalization client 103 .

[0027] As an optional example, in some embodiments, the automated front-end project internationalization client 103 is used to provide a visual interface for receiving a user's selection input operation for automatic internationalization of a front-end project, and for, in response to the selection input operation, obtaining an interface corresponding to the option selected by the selection input operation from the automated front-end project internationalization server 101 and displaying the interface, wherein at least information on automatic internationalization of the front-end project and operation options for the information on automatic internationalization of the front-end project are displayed in the interface.

[0028] In some embodiments, the communication network 102 can be any suitable combination of one or more wired and / or wireless networks. For example, the communication network 102 can include any one or more of the following: the Internet, an intranet, a wide area network (WAN), a local area network (LAN), a wireless network, a digital subscriber line (DSL) network, a frame relay network, an asynchronous transfer mode (ATM) network, a virtual private network (VPN), and / or any other suitable communication network. The automation front-end project internationalization client 103 can be connected to the communication network 102 through one or more communication links (e.g., communication link 104), and the communication network 102 can be linked to the automation front-end project internationalization server 101 via one or more communication links (e.g., communication link 105). The communication link can be any communication link suitable for transmitting data between the automation front-end project internationalization client 103 and the automation front-end project internationalization server 101, such as a network link, a dial-up link, a wireless link, a hard-wired link, any other suitable communication link, or any suitable combination of such links.

[0029] The automated front-end project internationalization client 103 may include any one or more clients that present an interface related to high-speed access to an ORC external table in an appropriate form for use and operation by a user. In some embodiments, the automated front-end project internationalization client 103 may include any suitable type of device. For example, in some embodiments, the automated front-end project internationalization client 103 may include a mobile device, a tablet computer, a laptop computer, a desktop computer, and / or any other suitable type of client device.

[0030] Although the automated front-end project internationalization server 101 is illustrated as one device, in some embodiments, any appropriate number of devices may be used to perform the functions performed by the automated front-end project internationalization server 101. For example, in some embodiments, multiple devices may be used to implement the functions performed by the automated front-end project internationalization server 101. Alternatively, cloud services may be used to implement the functions of the automated front-end project internationalization server 101.

[0031] Based on the above system, an embodiment of the present invention provides an automated front-end project internationalization method, which is described below through the following embodiments.

[0032] Figure 2 The automated front-end project internationalization method of this embodiment can be executed on the automated front-end project internationalization server, such as Figure 2 As shown, the automated front-end internationalization method includes the following steps: Step S201: Use the wrapping function provided by the react i18next internationalization library to wrap the Chinese text in the code development process.

[0033] As an optional example, in this embodiment, the react i18next internationalization library is used for code development, and the Chinese text in the code development process is wrapped by the wrapping function provided by the i18next npm package.

[0034] This embodiment uses the react-i18next internationalization library for front-end development. The react-i18next internationalization library is an internationalization solution based on the React framework and is an npm package based on i18next. In the daily development process of the Chinese context, this embodiment directly uses the t() function provided by i18next to wrap the developed Chinese copy without first converting it to an English key to replace the originally developed Chinese copy. Thus, the react-i18next internationalization library can parse and generate the key of the internationalization file based on the Chinese copy. For example, in the React component, a Chinese copy "Welcome" is written as t ("Welcome"), instead of first writing it as t ("Welcome") and then establishing a mapping from Welcome to "Welcome". For the Vue framework, an npm package derived from i18next, such as vue-i18n, is used to implement similar functions. The principle is also to wrap the copy through a specific function for internationalization. For example, in the process of developing the front end, the developer wrote the following code: <button> Hello< / button> , then directly wrap the Chinese text with t() and change the code to: <button> t("Hello")< / button> For example, when developing the front-end, developers wrote a mixture of Chinese characters and symbols: <button> Hello, how can I help you?< / button> According to the method of this embodiment, the developer can directly modify the code to <button> t("Hello, how can I help you?")< / button>. In this embodiment, Vue is a progressive JavaScript framework for building user interfaces. Compared with other front-end frameworks, Vue is known for its flexibility, lightness, and efficient two-way data binding mechanism, and is suitable for development from simple single-page applications (SPA) to complex enterprise-level systems. The react-i18next of this embodiment is built on the i18next library and is an internationalization (i18n) solution for react applications. It provides developers with powerful and flexible multi-language support, which can help applications dynamically switch languages, load localized resources, and manage complex translation logic. Through deep integration with react, react-i18next allows developers to easily apply internationalization functions in react components without manually managing cumbersome language data and switching logic. The react of this embodiment is an open source JavaScript library for building user interfaces. Its core purpose is to solve the problems of efficient rendering and state management in complex web applications, especially in scenarios where user interactions are frequent and interface states need to be dynamically updated. React is mainly used to build single page applications (SPA), and its core concept is a component-based development model, which allows the interface to be modularized, reused, and efficiently managed. i18next in this embodiment is a powerful internationalization (i18n) library for implementing multi-language support in different platforms and frameworks. i18next provides a flexible internationalization solution for applications, allowing developers to easily manage translations, regionalized content, and dynamic language switching in different languages. It is designed to be highly scalable and can be seamlessly integrated with a variety of front-end and back-end technologies (such as react, Vue, etc.), and is one of the internationalization tools currently widely used in the industry.

[0035] Step S202: Add a script command for the Chinese text in the project configuration file of the project, and configure a referenceable script command name for the added script command.

[0036] In this embodiment, the script commands added to the project configuration file include a Chinese key-value pair file generation trigger script command and a large model translation script command. The Chinese key-value pair file generation trigger script command in the script command is used to: extract internationalized Chinese copywriting, generate multilingual internationalized files, and configure the keys and values ​​of the Chinese internationalized files in the multilingual internationalized files to be consistent. The large model translation script command in the script command is used to: translate the generated Chinese internationalized files.

[0037] As an optional example, in this embodiment, a script command is added to the project's engineering configuration file, and it is ensured that the script command has a name that can be referenced by other modules (for example, named i18n-auto). The script command consists of two parts: First, use the i18next program to trigger the generation of Chinese key-value pair files (the command for a front-end project can be "i18next \"src / ** / *.{js,jsx,ts,tsx}\" [-oc] -c i18next-parser.config.js"). This part is used to extract the copywriting that needs to be internationalized, so as to automatically generate Chinese internationalization files. And for the generated internationalization files of multiple languages (such as languages A, B, C), ensure that the Chinese files (referred to as A) among them have the same key and value. That is to say, if the key in the Chinese internationalization JSON file is "Welcome", then the value also needs to be "Welcome". Then, ensure that after the previous operations are completed, execute the translation script based on the large model constructed in the subsequent steps (internationalization file processing). To achieve this goal, the translation script (for example, the translation script name is translate-ai.js) needs to be executed immediately after the automatic generation of Chinese internationalization files. Thus, a complete example of the script command is

i18next "src / ** / *.{js,jsx,ts,tsx}" [-oc] -c i18next-parser.config.js && node translate-ai.js

[0038] In this embodiment, JSON (JavaScript Object Notation) is a lightweight data interchange format, widely used for data transmission and storage, especially in web applications and services. The design goal of the JSON format is to be easy for humans to read and write, and at the same time easy for machines to parse and generate. It is based on a simple text form and is used to exchange data between different systems without relying on a specific programming language, which makes it highly versatile in cross-platform and cross-language data exchange.

[0039] Step S203: Configure a code management trigger function to trigger the internationalization process of Chinese copywriting according to the configured script command and the configured code management trigger function before submitting the code.

[0040] As an optional example, in this embodiment, an automatic trigger command is added to the pre-execution callback function of the code management tool, and the execution callback function of the added automatic trigger command is used to trigger the internationalization process of Chinese copywriting.

[0041] For example, in the code submission process, this embodiment realizes automatic triggering by configuring the pre-execution callback function (e.g., pre-commit hook) of the code management tool (e.g., Git). The pre-execution callback function is a function that is executed additionally before the expected command is executed to ensure that the expected supplementary logic is executed, thereby coordinating with other modules to achieve business goals. In the pre-execution callback function, add the "npm run i18n-auto" command, so that before each code submission, the internationalization process will be automatically executed, including operations such as extracting text and translating.

[0042] As an optional example, this embodiment triggers the internationalization of Chinese text according to the configured script command and the configured code management trigger function before submitting the code, and is executed in the following manner: First, create a translation script file in the project root directory, and import the big model javascript module into the created translation script file. For example, the suffix of the created translation script file is .js, and the file name of the translation script file is translate-ai.js. Introducing the big model javascript module into the created translation script file facilitates the interaction between the translation script file and the big model.

[0043] Secondly, read the project configuration file of the project, execute the translation script file created by the large model translation script command in the script command, obtain the project name from the project configuration file of the project, and construct the file name and path of the internationalized file to be processed based on the obtained project name. For example, read the project configuration file (such as package.JSON), obtain the project name (such as name), and construct the file name and path of the internationalized file to be processed based on this value (for example, the value of the field name representing the unique name of the project is console-plugin-sidebar, then the Chinese internationalized file name to be constructed is zh_console-plugin-sidebar.JSON, and the English internationalized file name to be constructed is en_console-plugin-sidebar.JSON).

[0044] Next, the Chinese key-value pair file in the trigger script command of the trigger function is generated through code management, the content is extracted from the Chinese copy wrapped in the wrapping function as Chinese internationalization JSON data, and the corresponding Chinese internationalization JSON data is read into the translation script file according to the file name and path of the internationalization file to be processed; Then, create a client instance of the big model javascript module, configure the interface communication key for the big model and the client instance, read the Chinese internationalization JSON data corresponding to the file name and path of the internationalized file to be processed in the translation script file through the client instance of the big model javascript module, and pass the read Chinese internationalization JSON data as the content of the user role in the big model to the chat completion interface of the big model.

[0045] For example, this embodiment sets the model to a large model that supports JSON data processing and accurate semantic analysis (such as "gpt-3.5-turbo"), and gives the following accurate prompts word for word: [Please play the role of the i18next translation program. I will input a JSON with key:value as the characteristics. Please translate the value part of the key:value in the input JSON into {language} with a meaning as close to the value as possible and as short as possible; if the value is already {language}, you do not need to translate it and output it as it is. If the value is already {language}, then you do not need to translate it and just return the input JSON directly. Output JSON in the same format without any Markdown tags. Only JSON needs to appear in your output. ], where {language} in the content enclosed in the above square brackets needs to be completely replaced with other international languages ​​to be translated, such as English, Russian, Japanese, and Korean in the actual implementation process. In this way, the big model can be controlled to know that it needs to act as the i18next translation program, and translate the value part into the language to be translated that is as close to the key as possible and as short as possible according to the input JSON data (key-value). (If the value is already in the language to be translated, it will be output as is)].

[0046] Finally, the big model uses the big model translation script command in the script command to translate the Chinese internationalization file, and writes the translation result as non-Chinese internationalization content into the corresponding internationalization file through deserialization.

[0047] It should be noted that, in the present embodiment, the translation result returned by the chat completion interface of the large model is detected through the translation script file. When the data format of the returned translation result is JSON, the translation result is written into the corresponding internationalization file as non-Chinese internationalization content through deserialization. When the data format of the returned translation result is not JSON, the large model uses the large model translation script command in the script command to re-translate the Chinese internationalization file, and detects the translation result re-returned by the chat completion interface of the large model through the translation script file. When the number of re-translations exceeds the preset number, the translation is terminated and an error is reported.

[0048] It should be noted that the automated front-end project internationalization method of this embodiment involves development based on the Chinese context and i18next parsing keys, integration into the development process, and internationalization file processing. In the complete development process, these three major steps are executed at least once, and after the first execution of the complete major step process, the subsequent incremental development only needs to repeat the first major step. When submitting the code, the contents involved in the second and third major steps are automatically executed.

[0049] In practical applications, the automated front-end project internationalization method and system of this embodiment combines the development based on Chinese text with the process of react-i18next parsing internationalized key values. In the development of the Chinese context, the t() function is used to wrap the Chinese text, so that react-i18next can generate the JSON key value of the internationalized file based on the Chinese text, and use Chinese as the key value of the internationalized translation, forming the basis for the construction of the translation script based on the big model and the integration with the development process; by adding the script command in package.json and ensuring that the command can automatically trigger the internationalization processing flow when the code is submitted, the integration of the development process is realized; based on the big model, the automated translation script uses the big model and uses precise prompt words to efficiently construct a JavaScript script that translates from the Chinese JSON file to the JSON file in other languages, including the correct use of each module in the script, the interaction process with the big model, and the processing of the results returned by the big model, so as to achieve an accurate, efficient, and sustainable and cyclic translation process.

[0050] According to the automated front-end project internationalization method and system of this embodiment, developers only need to focus on writing Chinese text during the development process, and no longer need to spend a lot of time manually managing internationalized keys and translated text, which greatly reduces development time and significantly improves development efficiency. There is no need to worry about choosing the right keys, which reduces the difficulty of development and the burden of thinking, making the development process smoother.

[0051] like Figure 3 As shown, the present invention further provides a device, including a processor 310, a communication interface 320, a memory 330 for storing a computer program executable by the processor, and a communication bus 340. The processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 implements the above-mentioned automated front-end project internationalization method by running the executable computer program.

[0052] Among them, the computer program in the memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for 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 various embodiments 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, etc. Various media that can store program codes.

[0053] The system embodiments described above are merely illustrative, wherein 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, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected based on actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.

[0054] Through the description of the above implementation modes, those skilled in the art can clearly understand that each implementation mode can be implemented by means of software plus a necessary general hardware platform, or of course by hardware. Based on such an understanding, the above technical solution can essentially or in other words be embodied in the form of a software product that contributes to the prior art. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.

[0055] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. An automated front-end project internationalization method, characterized in that: The method comprises: Use the wrapping function provided by the react i18next internationalization library to wrap the Chinese text in the code development process; Add script commands for Chinese text in the project configuration file, and configure referenceable script command names for the added script commands; Configure the code management trigger function to trigger the internationalization of Chinese text according to the configured script command and the configured code management trigger function before submitting the code.

2. The automated front-end internationalization method according to claim 1, characterized in that: The wrapping function provided by the react i18next internationalization library is used to wrap the Chinese copy in the code development process, including: using the react i18next internationalization library for code development, and wrapping the Chinese copy in the code development process through the wrapping function provided by the i18next npm package.

3. The automated front-end internationalization method according to claim 1, characterized in that: The script commands added to the project's engineering configuration file include Chinese key-value pair file generation trigger script commands and large model translation script commands.

4. The automated front-end internationalization method according to claim 3, characterized in that: The Chinese key-value pair file generation trigger script command in the script command is used to: extract the internationalized Chinese copy, generate multi-language internationalization files, and configure the keys and values ​​of the Chinese internationalization files in the multi-language internationalization files to be consistent.

5. The automated front-end internationalization method according to claim 3, characterized in that: The large model translation script command in the script command is used to translate the generated Chinese internationalization files.

6. The automated front-end internationalization method according to claim 1, characterized in that: Configuring the code management trigger function includes: adding an automatic trigger command in the pre-execution callback function of the code management tool, and adding an execution callback function of the automatic trigger command to trigger the internationalization processing of the Chinese copy.

7. The automated front-end internationalization method according to claim 1, characterized in that: Before submitting the code, the internationalization of Chinese text is triggered according to the configured script command and the configured code management trigger function, including: Create a translation script file in the project root directory, and introduce the large model javascript module into the created translation script file; Read the project configuration file of the project, execute the created translation script file through the large model translation script command in the script command, obtain the project name from the project configuration file of the project, and construct the file name and path of the internationalized file to be processed according to the obtained project name; Generate a trigger script command by using the Chinese key-value pair file in the trigger script command of the trigger function through code management, extract the content from the Chinese text wrapped in the wrapping function as Chinese internationalized JSON data, and read the corresponding Chinese internationalized JSON data into the translation script file according to the file name and path of the internationalized file to be processed; Create a client instance of the big model javascript module, configure the interface communication key between the big model and the client instance, read the Chinese internationalized JSON data corresponding to the file name and path of the internationalized file to be processed in the translation script file through the client instance of the big model javascript module, and pass the read Chinese internationalized JSON data as the content of the user role in the big model to the chat completion interface of the big model; The big model uses the big model translation script command in the script command to translate the Chinese internationalization file, and writes the translation result as non-Chinese internationalization content into the corresponding internationalization file through deserialization.

8. The automated front-end internationalization method according to claim 7, characterized in that: The big model uses the big model translation script command in the script command to translate the Chinese internationalization file, and writes the translation result as non-Chinese internationalization content into the corresponding internationalization file through deserialization, including: detecting the translation result returned by the chat completion interface of the big model through the translation script file, when the data format of the returned translation result is JSON, writing the translation result as non-Chinese internationalization content into the corresponding internationalization file through deserialization; when the data format of the returned translation result is not JSON, the big model uses the big model translation script command in the script command to re-translate the Chinese internationalization file, and detects the translation result returned by the chat completion interface of the big model through the translation script file, when the number of re-translations exceeds the preset number, terminates the translation and reports an error.

9. An automated front-end project internationalization system, characterized in that: The system includes an automated front-end project internationalization server, which is used to: use the wrapping function provided by the react i18next internationalization library to wrap the Chinese copy in the code development process; add a script command for the Chinese copy in the project's engineering configuration file, and configure a referenceable script command name for the added script command; Configure the code management trigger function to trigger the internationalization of Chinese text according to the configured script command and the configured code management trigger function before submitting the code.

10. A computer device, characterized in that: The computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method according to any one of claims 1 to 8 when executing the program.

Citation Information

Cited By

  • Rapid internationalization method, system and device based on Vue2 and storage medium

    CN120848852A