Online webpage translation method and related device

By calling proxy servers and large language models to split and translate web page content, the problem of cumbersome online translation of web pages in the existing technology is solved, and dynamic web page translation is realized on any browser, improving the accuracy and convenience of translation.

CN120106093APending Publication Date: 2025-06-06HIGH-QUALITY XINTONG (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510255391.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-05
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

In the current technology, when online translation of web pages, specific browsers and browser plug-ins are required. The process is cumbersome and only supports static web page translation. It is impossible to dynamically load web page data, resulting in inconvenient and inaccurate translation.

Method used

By calling the proxy server to obtain web page content from the unified resource locator, split the hypertext markup language text into multiple fragments, and use the large language model to translate segment by segment according to the translation prompt words, and finally replace the original text content according to the corresponding relationship to realize dynamic web page translation.

Benefits of technology

It realizes online web page translation on any browser, eliminating the steps of installing browsers and plug-ins, supports dynamic web page translation, and the translation results are accurate and smooth, expanding the scope of application and improving user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120106093A_ABST
    Figure CN120106093A_ABST
Patent Text Reader

Abstract

The invention discloses an online webpage translation method and a related device, relates to the field of information processing, and can obtain a corresponding uniform resource locator in response to a webpage translation operation after a user inputs a corresponding webpage website. And obtaining the webpage content from the uniform resource locator by calling the proxy server. Splitting the hypertext markup language text corresponding to the webpage content into a plurality of hypertext markup language text segments; and calling a large language model according to the translation prompt words to translate the text content in each hypertext markup language text fragment to obtain a plurality of translated fragments. And finally, according to the corresponding relationship between each translation fragment and each hypertext markup language text fragment, obtaining a translated hypertext markup language text, and further completing the translation of the webpage. In the whole process, the webpage can be translated online without depending on any specific browser, and the tedious process of installing browsers, plug-ins and the like is omitted.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information processing technology, and in particular to an online webpage translation method and related devices. Background Art

[0002] At present, when users need to translate some web pages online, they need to use a browser that supports the translation function installed in the terminal to achieve online translation of the web pages. And when using these browsers for translation, auxiliary tools such as browser plug-ins are often required to achieve web page translation. Not only is the installation process cumbersome, but the need to use a specific browser also limits the scope of application of online translation, which brings inconvenience to users' convenient use. Summary of the invention

[0003] In view of the above problems, the present application provides an online webpage translation method and related devices to achieve the purpose of improving the scope of application and the convenience of online webpage translation. The specific scheme is as follows:

[0004] The first aspect of the present application provides an online webpage translation method, comprising:

[0005] In response to the webpage translation operation, obtaining a uniform resource locator;

[0006] Invoke a proxy server to obtain webpage content from the uniform resource locator;

[0007] Splitting the hypertext markup language text corresponding to the webpage content into a plurality of hypertext markup language text segments;

[0008] Calling the large language model according to the translation prompt word to translate only the text content in each hypertext markup language text segment to obtain multiple translation segments;

[0009] According to the correspondence between each translation segment and each hypertext markup language text segment, the text content in each hypertext markup language text segment is replaced with the translation text in the corresponding translation segment to obtain the translated hypertext markup language text.

[0010] In a possible implementation, the online webpage translation method further includes:

[0011] The first identifier of each text content string is associated with the corresponding translation segment and stored, and the second identifier of each translation content string is associated with the corresponding hypertext markup language text segment and stored, each of the text content strings is a string included in the text content of a corresponding hypertext markup language text segment, and each of the translation content strings is a string included in the translation text of a corresponding translation segment.

[0012] In a possible implementation, the process of determining each first identifier includes:

[0013] Calling a first Hash function to calculate the text content character string corresponding to the first identifier to obtain a first Hash value, and using the first Hash value as the first identifier;

[0014] The process of determining each second identifier includes:

[0015] A second Hash function is called to calculate the translation content character string corresponding to the second identifier to obtain a second Hash value, and the second Hash value is used as the second identifier.

[0016] In a possible implementation, splitting the hypertext markup language text corresponding to the webpage content into multiple hypertext markup language text segments includes:

[0017] Traversing the document object model tree corresponding to the hypertext markup language text to determine whether there is a target element, the target element being an element of the document object model tree having a text subnode of the first level;

[0018] When determining that the target element exists, if the target element has a target segmentation subnode, then including a text subnode at the same level as the target segmentation subnode into the new element, and the level at which the target segmentation subnode is located is the same as the first level;

[0019] The text subnodes in the new element are marked as split elements, and the hypertext markup language text is split according to the original element structure in the document object model tree and the split elements.

[0020] In a possible implementation, replacing the text content in each of the hypertext markup language text segments with the translated text in the corresponding translation segment to obtain the translated hypertext markup language text includes:

[0021] If the number of text nodes included in the translation segment is the same as the number of text nodes included in the hypertext markup language text segment, then according to the correspondence between the text nodes, the content of each text node in the hypertext markup language text segment is replaced with the corresponding translation text.

[0022] In a possible implementation, replacing the text content in each of the hypertext markup language text segments with the translated text in the corresponding translation segment to obtain the translated hypertext markup language text further includes:

[0023] If the number of text nodes included in the translation segment is different from the number of text nodes included in the hypertext markup language text segment, the hypertext markup language text segment is replaced by the translation segment.

[0024] In a possible implementation, the translation prompt word includes:

[0025] The text nodes in the hypertext markup language text segment are translated as a whole, and the constraints of the original structure of the hypertext markup language text segment are maintained.

[0026] A second aspect of the present application provides an online webpage translation device, comprising:

[0027] A webpage translation response module, used for obtaining a uniform resource locator in response to a webpage translation operation;

[0028] A web page resource acquisition module, used for invoking a proxy server to acquire web page content from the uniform resource locator;

[0029] A web page content splitting module, used for splitting the hypertext markup language text corresponding to the web page content into multiple hypertext markup language text segments;

[0030] A webpage fragment translation module is used to call a large language model according to a translation prompt word to translate only the text content in each hypertext markup language text fragment to obtain multiple translation fragments; and

[0031] The translation segment combination module is used to replace the text content in each of the hypertext markup language text segments with the translation text in the corresponding translation segment according to the correspondence between each of the translation segments and each of the hypertext markup language text segments, so as to obtain the translated hypertext markup language text.

[0032] A third aspect of the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the online web page translation method of the first aspect or any implementation of the first aspect.

[0033] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0034] The memory is used to store computer programs;

[0035] The processor is used to execute the computer program so that the electronic device can implement the online webpage translation method of the above-mentioned first aspect or any implementation manner of the first aspect.

[0036] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the online web page translation method of the above-mentioned first aspect or any implementation of the first aspect.

[0037] By means of the above technical scheme, the online webpage translation method provided by the present application can obtain the corresponding uniform resource locator in response to the webpage translation operation after the user inputs the corresponding webpage URL. The webpage content is obtained from the uniform resource locator by calling a proxy server. The hypertext markup language text corresponding to the webpage content is split into multiple hypertext markup language text fragments. According to the translation prompt word, the large language model is called to translate only the text content in each hypertext markup language text fragment to obtain multiple translation fragments. Finally, according to the corresponding relationship between each translation fragment and each hypertext markup language text fragment, the text content in each hypertext markup language text fragment is replaced with the translation text in the corresponding translation fragment to obtain the translated hypertext markup language text, thereby completing the translation of the webpage. The whole process can translate the webpage online without relying on any specific browser, eliminating the cumbersome process of installing browsers, plug-ins, etc., and has a wider scope of application and translation accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0039] Figure 1 An architectural diagram of an online webpage translation system provided for this application;

[0040] Figure 2 An architecture diagram of a terminal provided for this application;

[0041] Figure 3 An architectural diagram of a server provided for this application;

[0042] Figure 4 A flowchart of an online webpage translation method provided for this application;

[0043] Figure 5 A flowchart of another online webpage translation method provided for this application;

[0044] Figure 6 A structural diagram of an online webpage translation device provided for this application;

[0045] Figure 7A structural diagram of an electronic device provided in this application. DETAILED DESCRIPTION

[0046] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0047] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0048] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0049] See also Figure 1 , Figure 1 1 shows a schematic diagram of the architecture of an online webpage translation system. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers ( Figure 1 In the example, a server is included, and the server 200 can provide the online webpage translation method provided in the embodiment of the present application for one or more terminals.

[0050] Among them, a web browser can be installed on the terminal 100, which can provide a translation interface. The terminal 100 can receive the web address entered by the user on the translation interface and send the above parameters to the server 200. The server 200 can obtain the processing result based on the received parameters and return the processing result to the terminal 100.

[0051] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters by itself without the cooperation of the server, and the embodiments of the present application are not limited to this.

[0052] Next describe Figure 1 The product form of the mid-terminal 100;

[0053] The terminal 100 in the embodiment of the present application can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiment of the present application does not impose any limitation on this.

[0054] Figure 2 An optional hardware structure diagram of the terminal 100 is shown.

[0055] refer to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), an earphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190 and other components. Those skilled in the art will appreciate that Figure 2 These are merely examples of terminals or multi-function devices and do not constitute limitations on the terminals or multi-function devices, which may include more or fewer components than those shown in the figures, or combinations of certain components, or different components.

[0056] The input unit 130 can be used to receive input digital or character information, and generate key signal input related to the user settings and function control of the portable multifunctional device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect the user's touch operations on or near it (such as the user's operation on or near the touch screen using any suitable object such as fingers, joints, stylus, etc.), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the user's touch action on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute the command sent by the processor 170; the touch signal at least includes the touch point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, the touch screen can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic wave. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.

[0057] The input device 132 may receive input web page address data and the like.

[0058] The display unit 140 can be used to display information input by the user or information provided to the user, various menus of the terminal 100, interactive interfaces, file display and / or playback of any multimedia file. In the embodiment of the present application, the display unit 140 can be used to display the translation interface, processing results, etc.

[0059] The memory 120 can be used to store instructions and data. The memory 120 can mainly include an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files, texts, etc.; the instruction storage area can store software units such as operating systems, applications, instructions required for at least one function, or their subsets and extensions. It can also include a non-volatile random access memory; provide the processor 170 with hardware, software and data resources including management of computing and processing equipment, and support control software and applications. It is also used for the storage of multimedia files, and the storage of running programs and applications.

[0060] The processor 170 is the control center of the terminal 100. It uses various interfaces and lines to connect various parts of the entire terminal 100. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal 100 and processes data, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips. The processor 170 may also be used to generate corresponding operation control signals, send them to corresponding components of the computing and processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein performs corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.

[0061] Among them, the memory 120 can be used to store software codes related to the online web page translation method, the processor 170 can execute the steps of the online web page translation method, and can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to achieve corresponding functions.

[0062] The radio frequency unit 110 (optional) can be used for receiving and sending information or receiving and sending signals during a call, for example, after receiving the downlink information of the base station, it is sent to the processor 170 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (Global System of Mobile communication, GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE), email, Short Messaging Service (SMS), etc.

[0063] In this embodiment of the present application, the RF unit 110 can send the webpage address data to the server 200 and receive the translation processing result sent by the server 200.

[0064] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network port.

[0065] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption.

[0066] The terminal 100 further includes an external interface 180 , which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal 100 to communicate with other devices, or to connect a charger to charge the terminal 100 .

[0067] Although not shown, the terminal 100 may also include a flashlight, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which are not described in detail here. Some or all of the methods described below may be applied in the following embodiments. Figure 2 In the terminal 100 shown.

[0068] Next describe Figure 1 The product form of the server 200;

[0069] Figure 3 A structural diagram of a server 200 is provided, such as Figure 3 As shown, the server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other via the bus 201.

[0070] The bus 201 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0071] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0072] The memory 204 may include a volatile memory, such as a random access memory (RAM). The memory 204 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0073] The memory 204 may be used to store software codes related to the online webpage translation method, and the processor 202 may execute the steps of the online webpage translation method of the chip, and may also schedule other units to implement corresponding functions.

[0074] It should be understood that the above-mentioned terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above-mentioned terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as application specific integrated circuit (ASIC), field-programmable gate array (FPGA), general-purpose processor, digital signal processor (DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.

[0075] Currently, if you want to achieve online web translation, you need to install a specific browser, and the user needs to click a button outside of normal browsing to trigger the translation. When further implementing immersive translation, these browsers also require users to install browser plug-ins, and the whole process is very cumbersome. In addition, these browsers can only support static web translation and cannot dynamically load web data. When translating, they only mechanically replace text nodes, and the context is lost during translation, resulting in incoherent translated sentences.

[0076] In order to solve the above problems, the embodiment of the present application provides an online webpage translation method. The online webpage translation method of the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0077] Reference Figure 4 , Figure 4 The process diagram of an online webpage translation method provided in the embodiment of the present application is as follows: Figure 4 As shown, an online webpage translation method provided by an embodiment of the present application may include steps 401 to 405, and these steps are described in detail below.

[0078] 401. In response to the webpage translation operation, obtain a uniform resource locator.

[0079] Specifically, in order to facilitate users to translate online web pages anytime and anywhere, without being restricted by specific browsers, online web page translation can be provided to users in the form of web page links. Users only need to enter the online translation URL in the address input box in the browser, or directly click on the online translation URL, and the online translation interface can be displayed in the browser of the terminal. An input box for a URL is provided in the online translation interface, and users can enter the web page address to be translated, such as URL (i.e., uniform resource locator, which is the address of a standard resource on the Internet, used to indicate the location and access method of a resource on the Internet) in the input box, and then trigger the operation of online web page translation by clicking Enter or the like.

[0080] When the user's operation of triggering online webpage translation is identified, the corresponding uniform resource locator is obtained from the input box.

[0081] It is understandable that those skilled in the art may also adopt other methods to open and display the online translation interface on a browser, which will not be described in detail here.

[0082] 402. Call the proxy server to obtain the web page content from the uniform resource locator.

[0083] In a specific embodiment, considering the existing web page translation using a specific browser, an online web page proxy is not implemented, but the corresponding web page data is obtained from the web page data storage crawled by itself, or the web page request is processed through HTTP proxy. Such a method can work normally on static websites. However, many modern web pages need to load data dynamically, that is, after loading the initial web page skeleton, a data request is sent to the server, and the obtained data content is filled in the web page skeleton. For such websites, traditional reading search engine storage and HTTP proxy cannot correctly obtain the website content.

[0084] To this end, a proxy server is used here to solve this problem. All network requests of the original web page can be proxied correctly, and dynamic data loading triggered by user operations can also work normally. Further considering that the proxy server IP is sometimes identified as a robot, the request is intercepted. The original web page sometimes depends on the current website domain name (variables such as window.location) to work correctly, and it cannot work properly on the proxy domain name. You can use the IP pool to avoid being identified as a robot, and use Surfly to analyze and rewrite variables such as window.location in the original web page, so that most web pages can be proxied normally.

[0085] It should be noted that the above-mentioned proxy server can be a SOCKS proxy server, etc., and technicians with this skill can choose it according to their needs, and there is no limitation here.

[0086] 403. Split the hypertext markup language text corresponding to the webpage content into multiple hypertext markup language text segments.

[0087] Specifically, considering that HTML text (i.e., Hypertext Markup Language text) is composed of text contents marked by multiple tags, only the text contents marked by tags are translated during translation. In order to achieve fast and accurate translation, the entire Hypertext Markup Language text can be split into multiple Hypertext Markup Language text segments as needed.

[0088] This can be done by defining the minimum control element and splitting according to the minimum control element, for example:

[0089] A paragraph in an HTML document is a minimal element of collation:

[0090] This is a passage.

[0091] A p containing an a or span is also a paragraph, so p (rather than a or span) is a minimal comparison element:

[0092] One contains Link and span The paragraph is the minimal contrasting element.

[0093] It is understandable that those skilled in the art may define the above-mentioned minimum comparison elements as required, and split the hypertext markup language text according to the defined minimum comparison elements, which will not be described in detail here.

[0094] 404. Calling the large language model according to the translation prompt word to translate only the text content in each hypertext markup language text segment to obtain multiple translation segments.

[0095] Specifically, many paragraphs in a hypertext markup language text fragment are composed of multiple element nodes. For example:

[0096] Dog is a different animal from cat .

[0097] If each text node is translated separately, the sentence will not be smooth, as shown below:

[0098] dog It's a different animal cat .

[0099] In order to translate the text content smoothly and accurately while retaining the HTML structure completely, the content of the translation prompt word can be restricted accordingly. For example, the content of the translation prompt word can be:

[0100] “

[0101] Please follow these rules when translating the following HTML snippet:

[0102] 1. Strictly retain all HTML tags, attributes and original structures.

[0103] 2. Only translate the text content within the tag.

[0104] 3. Texts that already exist in the target language do not need to be translated.

[0105] 4. Codes, symbols and other non-translated content remain as they are (e.g. <code>, <pre>, <script>标签内的内容)。

[0106] 5、确保翻译过程中不修改、添加或删除任何HTML标签。

[0107] 6、请将文本节点从%s整体翻译为%s,并将对应的HTML元素按原始属性重新插入译文中。返回翻译后的HTML。(%s为占位符,分别对应源语言代码、目标语言代码和待翻译的HTML内容)。

[0108] HTML片段的内容。

[0109] ”

[0110] 通过提示词使大语言模型在保留原有元素结构的同时返回通顺的翻译后语句,例如:

[0111] 将Dog is a different animal from cat.连同提示词,通过大语言模型接口发送给大语言模型进行翻译,接口返回的内容是`狗是一个和猫不一样的动物.`。

[0112] 可以理解的是,本领域技术人员可根据需要对上述翻译提示词的内容进行选择和调整,在此不再赘述。

[0113] 405、根据每个翻译片段和每个超文本标记语言文本片段间的对应关系,将每个超文本标记语言文本片段内的文本内容替换为对应的翻译片段中的翻译文本,得到翻译后的超文本标记语言文本。

[0114] 具体的,为保证和原始网页内容上的一致性,在得到翻译片段的基础上,提取出翻译片段中的文本节点并和原超文本标记语言文本片段中的文本节点进行长度(即文本节点数量的比较)。其中若翻译片段中包含的文本节点的数量和超文本标记语言文本片段包含的文本节点数量相同,则根据文本节点间的对应关系,将超文本标记语言文本片段中每个文本节点中的内容替换为对应的翻译文本。

[0115] 若翻译片段中包含的文本节点的数量和超文本标记语言文本片段包含的文本节点数量不相同,则将超文本标记语言文本片段替换为翻译片段。

[0116] 例如,得到的翻译片段为:狗是一个和猫不一样的动物。

[0117] 其对应包含的文本节点为:["狗", "是一个和", "猫", "不一样的动物。"],共计4个文本节点。

[0118] 翻译片段对应的原超文本标记语言文本片段为:

[0119] Dog is a different animal from cat.。

[0120] 其对应包含的文本节点为:["Dog", " is a different animal from ", "cat","."],共计4个文本节点。

[0121] 可以看出上述翻译片段和原超文本标记语言文本片段包含的文本节点的数量一致(均为4个),则可逐个替换原超文本标记语言文本片段每一个文本节点的数据为翻译后的内容即可。

[0122] 在文本节点数量不一致时,则可直接将超文本标记语言文本片段替换为翻译片段即可。

[0123] 其中为保证翻译结果的准确性,可首先尝试逐个替换文本节点数据而不是统统替换为翻译片段,以保持对原网页最小的修改。

[0124] 以上可以看出该在线网页翻译方法,通过在代理服务器代理的网页基础上做翻译,对浏览器或浏览器插件没有依赖,实现了一个网址在所有浏览器都能有一致的翻译效果。翻译网页网址在任何浏览器上都可以打开、翻译,能还原原网页的动态数据加载,扩展了在线网页翻译的适用范围,为用户的使用提供了便利。并且通过基于大语言模型的翻译后端接口实现了通顺连贯的段落翻译。

[0125] 在一些具体的实施例中,为实现原文-译文之间的反转切换,方便用户进行翻译内容和原内容的对照和切换,该在线网页翻译方法还包括以下处理过程:

[0126] 将每个文本内容字符串的第一标识和对应的翻译片段关联后存储,并将每个翻译内容字符串的第二标识和对应的超文本标记语言文本片段关联后存储,每个文本内容字符串为对应的一个超文本标记语言文本片段的文本内容包含的字符串,每个翻译内容字符串为对应的一个翻译片段的翻译文本包含的字符串。

[0127] 具体的,考虑到直接在DOM树(即文档对象模型树,是浏览器将 HTML 或 XML 文档解析后生成的树状结构对象模型,它表示网页的结构和内容,允许通过 JavaScript 动态操作页面元素)上把所有最小对照元素复制为两份、分别存储原文和译文会导致原网页的JavaScript有时不工作。例如,当一个具有ID的元素被复制成了两个,依赖于这个ID的JavaScript逻辑就不再能正常工作。

[0128] 采用将原文与译文的映射,分别存储进两个从文本内容的字符串的哈希值到HTML内容的映射。其中第一标识的确定过程包括:

[0129] 对第一标识对应的文本内容字符串调用第一哈希函数进行计算,得到第一哈希值,并将第一哈希值作为第一标识;

[0130] 第二标识的确定过程包括:

[0131] 对第二标识对应的翻译内容字符串调用第二哈希函数进行计算,得到第二哈希值,并将第二哈希值作为第二标识。

[0132] 具体在进行映射时,第一哈希函数和第二哈希函数可采用为相同的哈希函数,该哈希函数可将字符串的内容计算为相应的整数。

[0133] 例如,可采用两个映射表格分别进行两种映射关系额存储。

[0134] 其中,对于超文本标记语言文本片段:Dog is a different animalfrom cat.,在收到翻译结果狗是一个和猫不一样的动物.后,在第一映射表格中添加原文本内容的哈希值到翻译片段的映射。

[0135] 即提取原超文本标记语言文本片段中的文本内容字符串"Dog is a differentanimal from cat.”,通过常用的字符串哈希函数计算出其整数哈希值(如123456),然后向第一映射表格中添加Key-Value映射记录:123456 - "狗是一个和猫不一样的动物.”。

[0136] 同理,在第二映射表格中添加了翻译文本内容的哈希值到原超文本标记语言文本片段的映射:

[0137] 计算字符串"狗是一个和猫不一样的动物。”的哈希值(如888888),然后向第二映射表格中添加Key-Value映射记录: 888888 - "Dog is a different animalfrom cat."。

[0138] 通过使用文本内容为key,可以避免HTML中元素attribute(属性)的频繁改动导致key失效。并通用超文本标记语言文本片段的文本内容作为value使在替换超文本标记语言文本片段中文本节点的逻辑能始终正常工作。

[0139] 可以理解的是,本领域技术人员可根据需要选择满足上述哈希值要求的哈希函数进行字符串的计算,在此不再赘述。

[0140] 在另一些具体的实施例中,为使翻译结果更加符合用户预期、适合对照 / 翻转翻译快速准确的要求。上述各实施例中将网页内容对应的超文本标记语言文本拆分为多个超文本标记语言文本片段的过程,可具体包括以下处理过程:

[0141] 501、对超文本标记语言文本对应的文档对象模型树进行遍历,确定是否存在目标元素,目标元素为文档对象模型树具有第一层级的文本子节点的元素。

[0142] 502、在确定存在目标元素时,若目标元素具有目标分割子节点,则将和目标分割子节点处于同一层级的文本子节点包含进新的元素中,目标分割子节点所在层级和第一层级相同。

[0143] 503、将新的元素中的文本子节点标记为分割元素,并按照文档对象模型树中的原有元素结构和分割元素,对超文本标记语言文本进行拆分。

[0144] 具体的,DOM 树(Document Object Model Tree)是浏览器将 HTML 或 XML 文档解析后生成的树状结构对象模型,HTML 是静态文本,浏览器会将其解析为 DOM 树,每个HTML 标签、属性、文本都对应树中的一个节点(Node)。节点类型可包括:

[0145] 文档节点(Document):整个文档的根(如 document)。

[0146] 元素节点(Element):HTML 标签(如 、)。

[0147] 属性节点(Attribute):标签的属性(如 class="box")。

[0148] 文本节点(Text):标签内的文本内容(如 Hello)。

[0149] 其他:注释节点、文档类型节点等。

[0150] 其中树形结构的示例如下:

[0151] 超文本标记语言文本为:

[0152] <html>

[0153] <head>

[0154] <title>页面< / title>

[0155] < / head>

[0156] <body>

[0157] <h1>标题< / h1>

[0158] 段落

[0159] < / body>

[0160] < / html>

[0161] 相应的DOM树结构:

[0162] Document

[0163] └── html

[0164] ├── head

[0165] │ └── title

[0166] │ └── "页面"

[0167] └── body

[0168] ├── h1

[0169] │ └── "标题"

[0170] └── p

[0171] └── "段落"

[0172] 可以看出DOM树具有严格的层级结构。通过遍历整个DOM树,如果各文本内容均存在相应的元素,则可直接按照元素间的层级关系进行拆分即可。

[0173] 而对于一些并没有相应元素的文本内容,在需要另外的处理。其具体处理过程可包括:

[0174] 遍历整个DOM树,如果一个元素有直接的文本子节点(这里的直接的文本子节点是指直接隶属于该元素的文本子节点,中间没有间隔其他元素,也即该文本子节点为该元素的儿子节点而不是孙子节点),则判断该元素是否有直接的分割子节点(如"H1", "H2", "H3", "H4", "H5", "H6", "BR"),如果有,把和分割子节点相邻(即处于相同层级)的文本子节点包进新div中。

[0175] 然后判断该新的div中是否有直接的文本子节点,若有,则将该元素标记为最小对照元素。如果没有,则继续遍历这个元素的所有子节点即可。

[0176] 例如,超文本标记语言文本为:

[0177]

[0178] 这是一个不在p里的段落。

[0179]

[0180] 这个段落和上一个段落被BR分割。

[0181] <h1>这是一个标题< / h1>

[0182] 标题后有一个段落。

[0183]

[0184] 按照上述遍历过程进行识别,在元素div存在直接的文本子节点"这是一个不在p里的段落。”,

[0185] 进一步地,元素div存在直接的分割子节点<h1>、,则将"这是一个不在p里的段落。”、<h1>、、"标题后有一个段落”均包进新div中。然后再次进行判断,这段超文本标记语言文本应该产生4个最小对照元素:

[0186]

[0187]

[0188] 这是一个不在p里的段落。

[0189]

[0190]

[0191]

[0192] 这个段落和上一个段落被BR分割。

[0193]

[0194] <h1 dt-comp-unit>这是一个标题< / h1>

[0195]

[0196] 标题后有一个段落。

[0197]

[0198]

[0199] 其中为相应的段落标记。

[0200] 作为上述在线网页方法各个实施例的结合应用,参照图5所示,描述了最小对照元素被标记后如何被使用。一个在可视范围内的最小对照元素会被整体翻译,如果翻译请求失败会被重试,在翻译成功后可在"原文 / 译文 / 对照翻译”三种状态中切换。可在翻译界面中提供相应的按钮选择进行相应状态的切换。其中图5中div dt-comp-unit="123”表示原始文本内容,div dt-comp-unit="123” dt-status="trans”表示翻译文本内容,div dt-comp-unit="123” dt-status="orig”表示翻转译文,div dt-comp-unit="123” dt-status="comp”表示展示对照翻译内容。

[0201] 以上介绍了本申请实施例提供的一种在线网页翻译方法,以下将介绍执行上述的在线网页翻译方法的装置。

[0202] 请参阅图6,图6为本申请实施例提供的一种在线网页翻译装置的结构示意图。如图6所示,该在线网页翻译装置,包括:

[0203] 网页翻译响应模块601,用于响应于网页翻译操作,获取统一资源定位符。

[0204] 网页资源获取模块602,用于调用代理服务器从统一资源定位符获取网页内容。

[0205] 网页内容拆分模块603,用于将网页内容对应的超文本标记语言文本拆分为多个超文本标记语言文本片段。

[0206] 网页片段翻译模块604,用于根据翻译提示词调用大语言模型仅对每个超文本标记语言文本片段中的文本内容进行翻译,得到多个翻译片段。以及,

[0207] 翻译片段组合模块605,用于根据每个翻译片段和每个超文本标记语言文本片段间的对应关系,将每个超文本标记语言文本片段内的文本内容替换为对应的翻译片段中的翻译文本,得到翻译后的超文本标记语言文本。

[0208] 在一种可能的实现中,还包括:映射关系存储模块,用于

[0209] 将每个文本内容字符串的第一标识和对应的翻译片段关联后存储,并将每个翻译内容字符串的第二标识和对应的超文本标记语言文本片段关联后存储,每个文本内容字符串为对应的一个超文本标记语言文本片段的文本内容包含的字符串,每个翻译内容字符串为对应的一个翻译片段的翻译文本包含的字符串。

[0210] 在一种可能的实现中,映射关系存储模块中每个第一标识的确定过程包括:

[0211] 对第一标识对应的文本内容字符串调用第一哈希函数进行计算,得到第一哈希值,并将第一哈希值作为第一标识;

[0212] 每个第二标识的确定过程包括:

[0213] 对第二标识对应的翻译内容字符串调用第二哈希函数进行计算,得到第二哈希值,并将第二哈希值作为第二标识。

[0214] 在一种可能的实现中,网页内容拆分模块603将网页内容对应的超文本标记语言文本拆分为多个超文本标记语言文本片段的过程,包括:

[0215] 对超文本标记语言文本对应的文档对象模型树进行遍历,确定是否存在目标元素,目标元素为文档对象模型树具有第一层级的文本子节点的元素;

[0216] 在确定存在目标元素时,若目标元素具有目标分割子节点,则将和目标分割子节点处于同一层级的文本子节点包含进新的元素中,目标分割子节点所在层级和第一层级相同;

[0217] 将新的元素中的文本子节点标记为分割元素,并按照文档对象模型树中的原有元素结构和分割元素,对超文本标记语言文本进行拆分。

[0218] 在一种可能的实现中,翻译片段组合模块605将每个超文本标记语言文本片段内的文本内容替换为对应的翻译片段中的翻译文本,得到翻译后的超文本标记语言文本的过程,包括:

[0219] 若翻译片段中包含的文本节点的数量和超文本标记语言文本片段包含的文本节点数量相同,则根据文本节点间的对应关系,将超文本标记语言文本片段中每个文本节点中的内容替换为对应的翻译文本。

[0220] 在一种可能的实现中,翻译片段组合模块605将每个超文本标记语言文本片段内的文本内容替换为对应的翻译片段中的翻译文本,得到翻译后的超文本标记语言文本的过程,还包括:

[0221] 若翻译片段中包含的文本节点的数量和超文本标记语言文本片段包含的文本节点数量不相同,则将超文本标记语言文本片段替换为翻译片段。

[0222] 在一种可能的实现中,网页片段翻译模块604中的翻译提示词包括:

[0223] 对超文本标记语言文本片段中的文本节点进行整体翻译,以及保持超文本标记语言文本片段的原有结构的限制条件。

[0224] 本申请实施例中还提供一种电子设备。参考图7所示,其示出了适于用来实现本申请实施例中的电子设备的结构示意图。本申请实施例中的电子设备可以包括但不限于诸如移动电话、笔记本电脑、PDA(个人数字助理)、PAD(平板电脑)、台式计算机等等的固定终端。图7示出的电子设备仅仅是一个示例,不应对本申请实施例的功能和使用范围带来任何限制。

[0225] 如图7所示,该电子设备可以包括处理装置(例如中央处理器、图形处理器等)701,其可以根据存储在只读存储器(ROM)702中的程序或者从存储装置708加载到随机存取存储器(RAM)703中的程序而执行各种适当的动作和处理。在电子设备通电的状态下,RAM 703中还存储有电子设备操作所需的各种程序和数据。处理装置701、ROM 702以及RAM 703通过总线704彼此相连。输入 / 输出(I / O)接口705也连接至总线704。

[0226] 通常,以下装置可以连接至I / O接口705:包括例如触摸屏、触摸板、键盘、鼠标、摄像头、麦克风、加速度计、陀螺仪等的输入装置706;包括例如液晶显示器(LCD)、扬声器、振动器等的输出装置707;包括例如内存卡、硬盘等的存储装置708;以及通信装置709。通信装置709可以允许电子设备与其他设备进行无线或有线通信以交换数据。虽然图7示出了具有各种装置的电子设备,但是应理解的是,并不要求实施或具备所有示出的装置。可以替代地实施或具备更多或更少的装置。

[0227] 本申请实施例中还提供一种计算机程序产品,包括计算机可读指令,当计算机可读指令在电子设备上运行时,使得电子设备实现本申请实施例提供的任一种在线网页翻译方法。

[0228] 本申请实施例中还提供一种计算机可读存储介质,该存储介质承载有一个或多个计算机程序,当一个或多个计算机程序被电子设备执行时,能够使电子设备实现本申请实施例提供的任一种在线网页翻译方法。

[0229] 另外需说明的是,以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本申请提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。

[0230] 通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。但是,对本申请而言更多情况下软件程序实现是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘、U盘、移动硬盘、ROM、RAM、磁碟或者光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,训练设备,或者网络设备等)执行本申请各个实施例所述的方法。

[0231] 在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。

[0232] 所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、训练设备或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、训练设备或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存储的任何可用介质或者是包含一个或多个可用介质集成的训练设备、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘(Solid State Disk,SSD))等。< / script> < / pre> < / code>

Claims

1. An online webpage translation method, characterized in that: include: In response to the webpage translation operation, obtaining a uniform resource locator; Invoke a proxy server to obtain webpage content from the uniform resource locator; Splitting the hypertext markup language text corresponding to the webpage content into a plurality of hypertext markup language text segments; Calling the large language model according to the translation prompt word to translate only the text content in each hypertext markup language text segment to obtain multiple translation segments; According to the correspondence between each translation segment and each hypertext markup language text segment, the text content in each hypertext markup language text segment is replaced with the translation text in the corresponding translation segment to obtain the translated hypertext markup language text.

2. The online webpage translation method according to claim 1, characterized in that: Also includes: The first identifier of each text content string is associated with the corresponding translation segment and stored, and the second identifier of each translation content string is associated with the corresponding hypertext markup language text segment and stored, each of the text content strings is a string included in the text content of a corresponding hypertext markup language text segment, and each of the translation content strings is a string included in the translation text of a corresponding translation segment.

3. The online webpage translation method according to claim 2, characterized in that: The process of determining each of the first identifiers includes: Calling a first Hash function to calculate the text content character string corresponding to the first identifier to obtain a first Hash value, and using the first Hash value as the first identifier; The process of determining each second identifier includes: A second Hash function is called to calculate the translation content character string corresponding to the second identifier to obtain a second Hash value, and the second Hash value is used as the second identifier.

4. The online webpage translation method according to any one of claims 1 to 3, characterized in that: Splitting the hypertext markup language text corresponding to the webpage content into multiple hypertext markup language text segments, including: Traversing the document object model tree corresponding to the hypertext markup language text to determine whether there is a target element, the target element being an element of the document object model tree having a text subnode of the first level; When determining that the target element exists, if the target element has a target segmentation subnode, then including a text subnode at the same level as the target segmentation subnode into the new element, and the level at which the target segmentation subnode is located is the same as the first level; The text subnodes in the new element are marked as split elements, and the hypertext markup language text is split according to the original element structure in the document object model tree and the split elements.

5. The online webpage translation method according to any one of claims 1 to 3, characterized in that: Replacing the text content in each of the hypertext markup language text segments with the translated text in the corresponding translation segment to obtain a translated hypertext markup language text, including: If the number of text nodes included in the translation segment is the same as the number of text nodes included in the hypertext markup language text segment, then according to the correspondence between the text nodes, the content of each text node in the hypertext markup language text segment is replaced with the corresponding translation text.

6. The online webpage translation method according to claim 5, characterized in that: Replacing the text content in each of the hypertext markup language text segments with the translated text in the corresponding translation segment to obtain the translated hypertext markup language text, further comprising: If the number of text nodes included in the translation segment is different from the number of text nodes included in the hypertext markup language text segment, the hypertext markup language text segment is replaced by the translation segment.

7. The online webpage translation method according to claim 1, characterized in that: The translation prompt words include: The text nodes in the hypertext markup language text segment are translated as a whole, and the constraints of the original structure of the hypertext markup language text segment are maintained.

8. An online webpage translation device, characterized in that: include: A webpage translation response module, used for obtaining a uniform resource locator in response to a webpage translation operation; A web page resource acquisition module, used for invoking a proxy server to acquire web page content from the uniform resource locator; A web page content splitting module, used for splitting the hypertext markup language text corresponding to the web page content into multiple hypertext markup language text segments; A webpage fragment translation module is used to call a large language model according to a translation prompt word to translate only the text content in each hypertext markup language text fragment to obtain multiple translation fragments; and The translation segment combination module is used to replace the text content in each of the hypertext markup language text segments with the translation text in the corresponding translation segment according to the correspondence between each of the translation segments and each of the hypertext markup language text segments, so as to obtain the translated hypertext markup language text.

9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the online webpage translation method as described in any one of claims 1 to 7.

10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the online webpage translation method as described in any one of claims 1 to 7.