Document translation method and apparatus, storage medium, and electronic device
By automatically acquiring and translating documents when the page is displayed, the high complexity of translation operations in existing technologies is solved, and a simplified document translation process is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WANGYIYOUDAO INFORMATION TECH BEIJING CO LTD
- Filing Date
- 2023-03-15
- Publication Date
- 2026-07-21
AI Technical Summary
In existing technologies, the paper translation process is cumbersome and time-consuming. Users need to download the paper from a third-party academic platform and then upload it to the document translation product to obtain the translation results.
When the current page is displayed, the system automatically retrieves the document to be translated in a predefined format by obtaining the translation instruction under the target link, translates it, and then displays the translated document in a predefined mode on the target page.
It simplifies the translation process, reduces translation complexity, and enables automatic translation without requiring users to manually copy the entire document, thus improving translation efficiency.
Smart Images

Figure CN116306701B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of translation, and more specifically, to a document translation method, apparatus, storage medium, and electronic device. Background Technology
[0002] In existing technologies, when translating academic papers, users need to download the papers they found on a third-party academic platform and then upload them to a document translation product to obtain the translation results. The whole process is cumbersome and time-consuming. Summary of the Invention
[0003] This invention provides a document translation method, apparatus, storage medium, and electronic device to at least solve the technical problem of high translation operation complexity.
[0004] According to one aspect of the present invention, a document translation method is provided, comprising: during the display of a current page, upon receiving a translation instruction to translate a first document under a target link, obtaining a document to be translated in a predetermined format corresponding to the first document; translating the document to be translated to obtain a translated document; and displaying the translated document in a predetermined mode on the target page.
[0005] As an optional example, displaying the translated document in a predetermined mode on the target page includes: displaying the translated document on the target page in a layout rule of a first document with a first format different from the predetermined format.
[0006] As an optional example, displaying the translated document on the target page with a layout rule different from the predetermined first format of the first document includes: obtaining a first document with a first format different from the predetermined format according to the target link; displaying the first document and the translated document side-by-side on the target page; and displaying both the first document and the translated document with the layout rule of the first document's first format.
[0007] As an optional example, the step of displaying the first document and the translated document side-by-side on the target page, with both the first document and the translated document displayed according to the first format layout rules of the first document, further includes: highlighting the corresponding content in the translated document when the first content in the first document is selected; and highlighting the corresponding content in the first document when the second content in the translated document is selected.
[0008] As an optional example, the document to be translated is a LaTeX format document, and translating the document to be translated to obtain a translated document includes: determining the original string to be translated from the document to be translated; translating the original string to obtain a target string; and filling the translated target string back into the document to be translated to obtain a translated document.
[0009] As an optional example, translating the original string to obtain the target string includes: converting each segment of the original string in the document to be translated into a string representation, generating an array of original strings and an original element type identifier; converting the original string into a first string according to whether the string representation in the original string is plain text, wherein the first string includes a special identifier; filtering out the special identifier in the first string to obtain a second string; translating the second string to obtain a translated third string; and determining the target string of the translated document based on the first string, the second string, and the third string.
[0010] As an optional example, converting the original string into a first string based on whether the string representation in the original string is plain text includes: retaining the string representation if the string representation is plain text; and adding the special identifier to the string representation if the string representation is not plain text.
[0011] As an optional example, determining the target string of the translated document based on the first string, the second string, and the third string includes: performing word segmentation on the second string and the third string; establishing a relationship between the word segments; determining the position of the text fragment in the second string within the first string; and replacing the string representation in the first string with the string representation in the third string according to the relationship and the position to obtain the target string.
[0012] As an optional example, translating the second string to obtain the translated third string includes: translating the second string according to the required translation method to obtain the third string.
[0013] According to another aspect of the present invention, a document translation apparatus is provided, comprising: a first acquisition module, configured to acquire a document to be translated in a predetermined format corresponding to the first document when a translation instruction for translating a first document under a target link is acquired during the display of the current page; a translation module, configured to translate the document to be translated to obtain a translated document; and a first display module, configured to display the translated document in a predetermined mode on the target page.
[0014] As an optional example, the above device further includes: a second display module, configured to display a translation control while the current page is the download page where the first document is located, and the first document in a first format different from the predetermined format can be downloaded through the current page; a first determining module, configured to determine that the translation instruction has been obtained when the translation control is triggered; and a second obtaining module, configured to obtain the predetermined format document corresponding to the first document displayed on the current page as the document to be translated.
[0015] As an optional example, the above display module includes: a jump unit, used to display the translation control when jumping from the first page to the current page, wherein the first page is a page that displays the document link of the first document, the first page displays multiple document links, the multiple document links include the document link of the first document, and when the document link of the first document is triggered, the user jumps from the first page to the current page.
[0016] As an optional example, the second acquisition module includes: a first acquisition unit, configured to send an acquisition request to a target server, wherein the acquisition request includes the document encoding of a first document in the current page's webpage link, the acquisition request being used to download the document to be translated in the predetermined format according to the document encoding, and the target server being a third-party server providing the document to be translated; receiving the document to be translated in the predetermined format returned by the target server; the first display module includes: a first display unit, configured to create a new tab; and using the newly created tab as the target page.
[0017] As an optional example, the current page is the front-end page of the translation system, and the device further includes: a second determining module, used to determine that the translation instruction has been obtained when the target link is filled into the translation input box of the current page during the display of the current page, or when the target link is filled into the translation input box of the current page and the translation button is triggered; the page corresponding to the target link is the download page of the first document, through which the first document in a first format different from the predetermined format can be downloaded; and a third obtaining module, used to obtain the document in the predetermined format corresponding to the first document as the document to be translated based on the target link.
[0018] As an optional example, the third acquisition module includes: a second acquisition unit, configured to send an acquisition request to a target server, wherein the acquisition request includes the document encoding of the first document linked to the target server, the acquisition request is used to download the document to be translated in a predetermined format according to the document encoding, and the target server is a third-party server that provides the document to be translated; and to receive the document to be translated in a predetermined format returned by the target server.
[0019] As an optional example, the first display module includes: a second display unit for jumping from the current page to the target page; and displaying the translated document in a predetermined mode on the target page.
[0020] As an optional example, the first display module includes a third display unit for displaying the translated document on the target page according to the layout rules of a first document in a first format that is different from the predetermined format.
[0021] As an optional example, the third display unit includes: a display subunit, configured to obtain a first document in a first format different from the predetermined format according to the target link; to display the first document and the translated document in comparison on the target page; and to display both the first document and the translated document according to the layout rules of the first document in the first format.
[0022] As an optional example, the document to be translated is a LaTeX format document, and the display subunit is further configured to: highlight the corresponding content in the translated document when the first content in the first document is selected; and highlight the corresponding content in the document to be translated when the second content in the translated document is selected.
[0023] As an optional example, the translation module includes: a translation unit, configured to convert each fragment of the original string in the document to be translated into a string representation, generate an array of original strings, and an original element type identifier; convert the original string into a first string according to whether the string representation in the original string is plain text, wherein the first string includes a special identifier; filter out the special identifier in the first string to obtain a second string; translate the second string to obtain a translated third string; and determine the target string of the translated document based on the first string, the second string, and the third string.
[0024] As an optional example, the translation unit is also used to: retain the string representation when the string representation is plain text; and add the special identifier to the string representation when the string representation is not plain text.
[0025] As an optional example, the translation unit is also used to: perform word segmentation on the second string and the third string; establish a relationship between the word segments; determine the position of the text fragment in the second string within the first string; and, according to the relationship and position, replace the string representation in the first string with the string representation in the third string to obtain the target string.
[0026] As an optional example, the translation unit described above is also used to: translate the second string according to the required translation method to obtain the third string.
[0027] According to another aspect of the present invention, a storage medium is also provided, wherein a computer program is stored in the storage medium, and the computer program is executed by a processor to perform the above-described document translation method.
[0028] According to another aspect of the present invention, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to execute the document translation method described above through the computer program.
[0029] In this embodiment of the invention, a method is adopted in which, during the display of the current page, upon receiving a translation instruction to translate a first document under a target link, a document to be translated in a predetermined format corresponding to the first document is obtained; the document to be translated is translated to obtain a translated document; and the document to be translated and the translated document are displayed in a predetermined mode on the target page. Since in the above method, when translating the first document, only the translation instruction needs to be triggered, and the system can automatically translate the first document in the predetermined format without copying the entire first document, the purpose of reducing the complexity of translation operations is achieved, thereby solving the technical problem of high translation operation complexity. Attached Figure Description
[0030] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0031] Figure 1 This is a flowchart of an optional document translation method according to an embodiment of the present invention;
[0032] Figure 2 This is a current page diagram of an optional document translation method according to an embodiment of the present invention;
[0033] Figure 3 This is a target page diagram of an optional document translation method according to an embodiment of the present invention;
[0034] Figure 4 This is a schematic diagram illustrating the highlighted content of an optional document translation method according to an embodiment of the present invention;
[0035] Figure 5 This is a document tree example diagram of an optional document translation method according to an embodiment of the present invention;
[0036] Figure 6 This is a document tree example diagram of another optional document translation method according to an embodiment of the present invention;
[0037] Figure 7 This is an example diagram of a document tree to be replaced according to an optional document translation method according to an embodiment of the present invention;
[0038] Figure 8 This is an example diagram of document tree splitting for an optional document translation method according to an embodiment of the present invention;
[0039] Figure 9 This is an example diagram of document tree replacement for an optional document translation method according to an embodiment of the present invention;
[0040] Figure 10This is a schematic diagram of the structure of an optional document translation device according to an embodiment of the present invention;
[0041] Figure 11 This is a schematic diagram of an optional electronic device according to an embodiment of the present invention. Detailed Implementation
[0042] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0043] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0044] According to a first aspect of the present invention, a document translation method is provided, optionally, as follows: Figure 1 As shown, the above method includes:
[0045] S102, during the process of displaying the current page, if a translation instruction is obtained to translate the first document under the target link, the document to be translated in a predetermined format corresponding to the first document is obtained;
[0046] S104, Translate the document to be translated to obtain the translated document;
[0047] S106, Display the translated document in a pre-defined mode on the target page.
[0048] Optionally, the above document translation method can be used during the document translation process. When the current page is displayed, if a translation instruction to translate the first document under the target link is triggered, a document to be translated in a predefined format corresponding to the first document can be obtained. The first document can have multiple formats, and the document to be translated is a first document in one of these formats. After translating the document to be translated to obtain the translated document, the translated document can be displayed on the target page.
[0049] The current page mentioned above can be the page used to display or download the first document, or it can be the front-end page of the translation system. The target page mentioned above can be a front-end page of the translation system that is different from the current page. For example, one can jump from the current page to the target page, or create a new tab and display the target page in the new tab.
[0050] The aforementioned pre-defined format can be one of the formats of the first document. The purpose of obtaining the first document in the pre-defined format is to improve the efficiency of the translation process, rather than to complicate the translation process by first converting the first document in the pre-defined format to a different format before translating it.
[0051] In the above method, when translating the first document, only the translation command needs to be triggered, and the system can automatically translate the first document in the predetermined format without copying the entire first document. This achieves the goal of reducing the complexity of the translation operation and thus solves the technical problem of high translation operation complexity.
[0052] As an optional example, the current page is the download page where the first document is located. The first document in a first format different from the predetermined format can be downloaded through the current page. During the display of the current page, the above method also includes: displaying a translation control; determining that a translation instruction has been obtained when the translation control is triggered; and obtaining the predetermined format document corresponding to the first document displayed on the current page as the document to be translated.
[0053] In this embodiment, there are several ways to obtain translation instructions. As a first method, it can be triggered by a translation control.
[0054] As an optional example, the translation control includes: displaying the translation control when navigating from a first page to the current page, wherein the first page is a page that displays a document link to a first document, the first page displays multiple document links, including a document link to the first document, and navigating from the first page to the current page when a document link to the first document is triggered.
[0055] Optionally, in this embodiment, the translation control can be displayed in real time or triggered under certain conditions. For example, the triggering condition can be a jump from the first page to the current page. The first page can be any page; as an example, the first page is the page that displays document links. Each document link on the first page can be used to jump to a document display or download page.
[0056] As an optional example, obtaining a pre-formatted document corresponding to the first document displayed on the current page as the document to be translated includes: sending an acquisition request to a target server, wherein the acquisition request includes the document encoding of the first document in the webpage link of the current page, the acquisition request is used to download the pre-formatted document to be translated according to the document encoding, and the target server is a third-party server providing the document to be translated; receiving the pre-formatted document to be translated returned by the target server; and translating the document in a pre-defined mode on the target page includes: creating a new tab; and using the newly created tab as the target page.
[0057] Optionally, in this embodiment, after receiving the translation instruction, a document to be translated needs to be obtained. The document to be translated is in a predetermined format. The predetermined format can be LaTeX format. In this embodiment, a first document in LaTeX format is obtained as the document to be translated, and then translation is performed.
[0058] When retrieving a first document in LaTeX format, a retrieval request can be sent to the target server, which then provides the LaTeX document. The retrieval request can include the document encoding, allowing the target server to download the first LaTeX document as the document to be translated.
[0059] Once you have both the document to be translated and the translated document, you can display the translated document using a pre-defined mode. This pre-defined mode opens a new tab in your browser, redirecting you from the current page to the target page displayed in that new tab. The target page displays both the original and translated documents.
[0060] As an optional example, the current page is the front-end page of the translation system. During the display of the current page, the above method further includes: determining that a translation instruction has been obtained when the target link is filled into the translation input box of the current page, or when the target link is filled into the translation input box of the current page and the translation button is triggered; the page corresponding to the target link is the download page of the first document, through which a first document in a first format different from the predetermined format can be downloaded; and obtaining the document in the predetermined format corresponding to the first document as the document to be translated based on the target link.
[0061] As another way to obtain translation instructions, the download page of a first document in a different format than the predetermined format can be used as the target link. The current page is the front-end page of the translation system. The target link is entered into the input box on the front-end page to obtain the translation instructions.
[0062] For example, such as Figure 2 As shown, Figure 2 For the front-end page of the translation system, the target link can be entered or copied into the input box under the first or second language, thereby translating the first document into a translated document in another language.
[0063] As an optional example, obtaining a document in a predetermined format corresponding to the first document as the document to be translated, based on the target link, includes: sending an acquisition request to the target server, wherein the acquisition request includes the document encoding of the first document of the target link, the acquisition request being used to download the document to be translated in a predetermined format according to the document encoding, and the target server being a third-party server providing the document to be translated; and receiving the document to be translated in a predetermined format returned by the target server.
[0064] Optionally, in this embodiment, after receiving the translation instruction, a document to be translated needs to be obtained. The document to be translated is in a predetermined format. The predetermined format can be LaTeX format. In this embodiment, a first document in LaTeX format is obtained as the document to be translated, and then translation is performed.
[0065] When retrieving a first document in LaTeX format, a retrieval request can be sent to the target server, which then provides the LaTeX first document. The retrieval request can include a document code identifying the specific first document, allowing the target server to download the LaTeX first document as the document to be translated.
[0066] As an optional example, displaying the translated document in a pre-defined mode on the target page includes: navigating from the current page to the target page; and displaying the translated document in a pre-defined mode on the target page.
[0067] In this embodiment, when the translated document is displayed, the user can jump from the current page to the target page. This jump does not trigger a new tab; instead, it jumps within the current tab.
[0068] As an optional example, displaying the translated document in a predetermined mode on the target page includes: displaying the translated document on the target page according to the layout rules of a first document in a first format that is different from the predetermined format.
[0069] Optionally, in this embodiment, the first format can be a portable document format (PDF), the document to be translated is in LaTeX format, and the translated document is displayed in PDF format.
[0070] When displayed, both have the same layout but different languages. For example, as Figure 3 As shown, the translated document has the same layout as the original PDF document.
[0071] In other words, in this embodiment, the LaTeX document is first translated to obtain a translated document. Then, when displaying the translated document, the text content of the translated document can be displayed directly, or the translated document can be displayed in the PDF format of the first document (the source language document).
[0072] In this embodiment, for a document in LaTeX format that has already been translated, if the same user or different users request to translate the document, the initial translation result can be retrieved directly without the system repeating the translation. If the initial translation result is too far removed from the current time or the data is lost, the system can translate it again.
[0073] As an optional example, displaying the translated document on the target page according to the layout rules of the first document in a first format different from the predetermined format includes: obtaining the first document in a first format different from the predetermined format according to the target link; displaying the first document and the translated document side-by-side on the target page; and displaying both the first document and the translated document according to the layout rules of the first document in the first format.
[0074] In this embodiment, when displaying the translated document, the first document (source language document) in PDF format can be displayed, and when displaying the translated document, the translated document is displayed according to the layout of the first document in PDF format, and the display layouts of the two are the same.
[0075] As an optional example, the first document and the translated document are displayed side-by-side on the target page; both the first document and the translated document are displayed according to the first format layout rules of the first document, and also include: when the first content in the first document is selected, the corresponding content in the translated document is highlighted; when the second content in the translated document is selected, the corresponding content in the first document is highlighted.
[0076] In this embodiment, when the first document and the translated document are displayed side-by-side, the first document displays the source language text, and the translated document displays the translated text. The two documents have the same display layout and are used for comparison. If content in one document is selected, the corresponding content at the corresponding position is highlighted in the other document.
[0077] For example, such as Figure 4 As shown, Figure 4 In the first document or the translated document, if any segment is selected or marked, it will be selected or marked in the other document simultaneously and highlighted.
[0078] As an optional example, translating a document to be translated to obtain a translated document includes: the document to be translated is a LaTeX format document; each fragment of the original string in the document to be translated is converted into a string representation, generating an array of original strings and an original element type identifier; the original strings are converted into a first string according to whether the string representations in the original strings are plain text, wherein the first string includes a special identifier; the special identifiers in the first string are filtered out to obtain a second string; the second string is translated to obtain a translated third string; the target string of the translated document is determined based on the first string, the second string, and the third string.
[0079] In this embodiment, the original string can be divided into paragraphs, which contain one or more segments. Each segment can be converted into a string representation, and then its conversion into the first string is determined by whether it is plain text. This can be understood as follows: the first string is the string obtained by adding special identifiers to the plain text segments of the original string; the second string is the string obtained by filtering out the special identifiers; and the third string is the string obtained by translating the second string. Therefore, the first string is the formatted, untranslated string; the second string is the unformatted string to be translated; and the third string is the unformatted translated string. These three are used to determine the formatted, translated target string.
[0080] As an optional example, converting the original string to a first string based on whether the string representation in the original string is plain text includes: preserving the string representation if the string representation is plain text; and adding a special identifier to the string representation if the string representation is not plain text.
[0081] Optionally, the above conversion of the original string to the first string can be achieved by preserving the string representation if the original string's string representation is plain text, and adding special identifiers to the string representation if the string representation is not plain text. Therefore, the first string is the original string in which plain text has been modified with special identifiers.
[0082] As an optional example, determining the target string of the translated document based on the first string, the second string, and the third string includes: performing word segmentation on the second string and the third string; establishing relationships between the word segments; determining the position of the text fragment in the second string within the first string; and replacing the string representation in the first string with the string representation in the third string according to the relationships and positions to obtain the target string.
[0083] As an optional example, translating the second string to obtain the translated third string includes: translating the second string according to the required translation method to obtain the third string.
[0084] In this embodiment, different strings can be configured with different translation methods. Therefore, when translating the second string, the second string is translated according to the translation method required for the second string to obtain the third string.
[0085] In this embodiment, the document to be translated can be a LaTeX document, also known as the original document, and the translated document can be called the target document. LaTeX is a TeX-based typesetting system that uses a combination of text and commands to control styles and layout. For a LaTeX document, the original string to be translated is first determined, then translated to obtain the target string, and finally the target string is added back to the original document to obtain the translated target document. The original document mentioned above can be a LaTeX source project package. A LaTeX project package can include multiple files.
[0086] The following method can be used to determine the original string: Filter candidate original files from all files in the original document according to their file extensions; generate a file tree of candidate original files; use the file containing the predetermined characters in the candidate original files as the entry file; starting from the entry file, filter the first file from the candidate original files according to the file reference relationship contained in the command type node in the file, where the type of the node is determined according to the file tree; determine the paragraph in the first file as the original string.
[0087] The above-described method of filtering candidate original files from all files in the original document by file extension can be used to select files with one or more specific file extensions from all files in the original document. For example, filtering files with the ".tex" extension can select candidate original files from all files in the original document.
[0088] For candidate original files, an entry file can be selected. The selection rule can be to check whether the candidate original file contains a predetermined character. There can be at least two rules. The first is to traverse each candidate original file, and when a specific character is encountered for the first time, select the candidate original file containing that specific character as the entry file. The second is to traverse each candidate original file, and when the specific character is encountered, select one candidate original file containing that specific character as the entry file according to a certain rule.
[0089] Before or after the entry file is determined, a file tree of candidate original files can be generated. The file tree can be understood as a node tree with a root node and leaf nodes. After the file tree is generated, different nodes within the file tree can have different types.
[0090] The entry file can be used as a starting point, and then the file reference relationships contained in the command type nodes can be queried according to the node tree. The file reference relationship indicates which files the entry file references, and whether the files referenced by the entry file in turn reference other files. It should be noted that the file reference relationship must be queried within the command type nodes. Based on the above reference relationships, multiple first files can be identified from the candidate original files.
[0091] After identifying the first file, the paragraphs in the first file can be identified as the original strings, i.e., the content that needs to be translated.
[0092] The file tree for generating candidate original files mentioned above can be achieved as follows: create a root node for the candidate original files and use the root node as the current node; traverse the string variables of the candidate original files; for each command start character encountered during traversal, generate a command child node for the current node and use the command child node as the new current node; for each command end character encountered during traversal, use the parent node of the current node as the new current node; for each plain string encountered during traversal, generate a text child node for the current node.
[0093] For example, such as Figure 5 and Figure 6 As shown, Figure 5 The file tree generated for the following TeX file string variables: "command1 start character plain string1 command1 end character command2 start character plain string2 command2 end character".
[0094] Figure 6 The file tree generated for the following TeX file string variables: command1 start character plain string1 command2 start character plain string2 command2 end character command1 end character.
[0095] Optionally, determining the paragraphs in the first file as raw strings can be done by: generating an intermediate representation with a hierarchical structure from the first file's file tree, wherein the hierarchical structure includes paragraph layers; and determining the strings corresponding to the paragraphs as raw strings.
[0096] In this embodiment, the hierarchical structure can be a nested structure, such as "{ [()]}", which can be considered a three-level hierarchical structure of curly braces, square brackets, and parentheses. The intermediate expression mentioned above can be a JSON structure. That is, the file tree of the first file (the candidate original file includes one or more first files) is used to generate a multi-level intermediate expression in JSON format according to different levels. Among them, the hierarchical structure includes a "paragraph" hierarchical structure. The strings in the paragraph structure are determined as the original strings to be translated.
[0097] Optionally, in this embodiment, generating an intermediate representation with a hierarchical structure from the first file can be achieved by: using the file tree of the first file as the file layer of the intermediate representation; using the command node related to each document structure in the file tree of the first file as the structural block layer of the intermediate representation; using the command node related to each document element in the file tree of the first file as the paragraph layer of the intermediate representation; using each leaf node in the file tree of the first file as the fragment layer of the intermediate representation; and constructing different translation strategies for different structural block layers.
[0098] Optionally, the document structure and document elements described above may include specific tags. These tags can identify which nodes are document structure elements and which are document elements. Through a hierarchical structure, the first file is divided into different levels, each representing different content, further facilitating the identification of the original string. Different translation strategies can be configured for different structural block levels to achieve better translation results.
[0099] By following the steps described above, the content to be translated can be determined from a document in a specific format.
[0100] For example, taking LaTeX format documents as an example, for a LaTeX source project package, each file in the LaTeX source project package is traversed according to a breadth-first strategy. For files with the suffix ".tex", their contents are read into a string variable, and these TeX file string variables are stored in an array to form a TeX file set. Then, the TeX file set is traversed, and it is determined whether each TeX file string variable contains the substring "\documentclass". "\documentclass" is the predefined string mentioned above. If it contains it, its index in the array is set as the index of the entry TeX file, and the traversal ends early.
[0101] Next, construct the LaTeX document tree. Create an empty queue of TeX collections to be constructed. First, add the TeX file corresponding to the entry TeX file index to this collection. Then, retrieve the TeX files from this collection one by one for processing until the collection is empty, at which point the processing ends.
[0102] The processing steps for each TeX file are as follows: parse the TeX file string variable into a TeX tree, then traverse the command nodes on the TeX tree, collect all the parameters of the "\input" command, which correspond to other TeX files that need to be imported, and add these files to the queue of the TeX collection to be built in sequence.
[0103] The steps for parsing the strings corresponding to a TeX file into a TeX tree are as follows: First, create a root node for the TeX tree, and set the current node pointer to this root node. Then, traverse the string variables in the TeX file. When encountering the start character of a command in LaTeX syntax, create a new command node and add it to the subtree set of the node pointed to by the current node pointer. Use the original pointer to point to the node pointed to by the current node pointer, and then set the current node pointer to the newly created command node. When encountering the end character of a command corresponding to the current node in LaTeX syntax, reset the current node pointer to the original pointer. When encountering a plain string, create a new plain text node and add it to the subtree set of the node pointed to by the current node pointer.
[0104] An array is used to store all the TeX trees obtained during the processing, which is the LaTeX document tree corresponding to the LaTeX document. The LaTeX document tree contains multiple TeX trees, and each TeX tree corresponds to a first document.
[0105] Finally, a hierarchical intermediate representation is generated. The entire document uses a JSON structure as the hierarchical intermediate representation and is divided into four levels: "File," "Block," "Paragraph," and "Fragment," based on the characteristics of the LaTeX document structure. "File" corresponds to each TeX file, ensuring a one-to-one correspondence between JSON objects and the TeX tree. "Block" corresponds to command nodes related to the document structure in the TeX tree (e.g., title, author, abstract, bibliography), ensuring different translation schemes can be used for different document structures. "Paragraph" corresponds to a collection of plain text nodes separated by command nodes related to document elements (e.g., figure, table, list) or commands with clear paragraph division meanings (e.g., \par, \\\). This level is the smallest unit of translation to maintain semantic fluency. "Fragment" corresponds to the leaf nodes in the TeX tree, including plain text nodes, text style command nodes (e.g., \textbf, \emph), and non-translated element command nodes (e.g., formulas, quotations). This level is the smallest unit in LaTeX syntax to maintain LaTeX syntax styles. Based on the four levels mentioned above, a JSON representation with four nested levels can be generated by traversing each node in the LaTeX document tree using a depth-first strategy. Each JSON object includes an array of JSON objects at the next level of its nesting, a type field (here, the corresponding command name is used as the node type), and an index pointing to a specific command node or a set of plain text nodes.
[0106] Finally, the string corresponding to the paragraph is used as the original string to determine the original string to be translated.
[0107] The steps for translating the original string to obtain the target string can be as follows: each segment of the original string can be converted into a string representation, generating an array of original strings and an identifier for the original element type; the original string can be converted into a first string according to whether the string representation in the original string is plain text, where the first string includes a special identifier; the special identifier in the first string can be filtered out to obtain a second string; the second string can be translated to obtain a translated third string; and the target string can be determined based on the first string, the second string, and the third string.
[0108] Since the original string is organized into paragraphs, it contains one or more segments. Each segment can be converted into a string representation, and then its conversion to the first string is determined by whether it is plain text. This can be understood as follows: the first string is the plain text portion of the original string with special identifiers added; the second string is the string after filtering out the special identifiers; and the third string is the translated version of the second string. Therefore, the first string is the formatted, untranslated string; the second string is the unformatted string to be translated; and the third string is the unformatted translated string. These three strings are used to determine the formatted, translated target string.
[0109] When determining the target string, the second and third strings can be segmented; relationships can be established between the segments; the position of the text fragment in the second string within the first string can be determined; and according to the relationships and positions, the string representation in the third string can be replaced with the string representation in the first string to obtain the target string.
[0110] Optionally, the above conversion of the original string to the first string can be achieved by preserving the string representation if the original string's string representation is plain text, and adding special identifiers to the string representation if the string representation is not plain text. Therefore, the first string is the original string in which plain text has been modified with special identifiers.
[0111] In this embodiment, since each structure block can be configured with different translation methods, paragraphs within different structure blocks can have different translation methods. The second string is translated according to the translation method required by the structure block containing the second string to obtain the third string.
[0112] For example, continuing with the LaTeX document format, in this embodiment, by traversing the hierarchical intermediate expressions, a translation strategy is executed on a "paragraph" basis for the original string to be translated. Different global translation strategies can be constructed for different "structural blocks." For instance, for the `author` structural block, a separate translation engine can be used to translate the names of the person and organization, or it can be left untranslated; for the `title` structural block, all titles in the document can be aggregated and translated together, utilizing more context to avoid mistranslation; for the `bibliography` structural block, the paper titles can be extracted separately for translation or left untranslated.
[0113] When translating a paragraph, the first step is to construct a formatted string to be translated (the first string). Each segment within the paragraph is iterated through and converted into a string representation, generating an array of original text strings corresponding to the paragraph. The conversion rule is as follows: determine if the text is plain text; if so, use the corresponding plain text content as the string representation; otherwise, use a predefined, numbered special token as the string representation. Next, each element in the string array corresponding to the paragraph is marked as formatted. This is done by iterating through the array and checking if the next element's string is a numbered special token; if not, mark the current element as formatted. Finally, the original text string array is concatenated in order. Unformatted strings are concatenated directly, while formatted strings are concatenated by adding formatted token pairs to both sides before concatenation, generating the formatted string to be translated. Then, the unformatted translation result string is obtained. The formatted string to be translated is filtered to remove the formatted token pairs, generating an unformatted string to be translated (the second string). This unformatted string is then input into a pre-trained translation engine to obtain the unformatted translated string (the third string). The pre-trained translation engine uses the same training data pairs to ensure that the special tokens with serial numbers are preserved in the translated text. Finally, the formatted translated string (the target string) is obtained. First, both the unformatted string to be translated and the unformatted translated string are segmented into words. Using the formatted string as a unit, the start and end positions of each formatted token pair within the unformatted word sequence are determined. A nested tree structure is constructed based on the nesting relationships between the formatted token pairs. Then, the Fast-Align algorithm is used to obtain the word alignment relationship between the unformatted word sequence to be translated and the unformatted translated word sequence. Finally, the nested tree structure is traversed using a depth-first strategy. The start and end positions of each node in the unformatted sequence of words to be translated are mapped to the unformatted sequence of translated words. These are then inserted into the unformatted translated string to obtain the formatted translation result (target string).
[0114] After translating the target string, it can be used to fill in the original document, replacing the original string, thus obtaining the translated target document. The filling process involves two steps. The first step is to map each substring in the target string array to each object in the original string array based on the correspondence between the original element type identifier and the target element type identifier, adding an object field and assigning a value to each object in the original string array. The second step is to fill in the translated target string back into the original document to obtain the target document.
[0115] The first step can be accomplished using pointers. Use the first pointer to point to the first object in the original string array and the second pointer to point to the first substring in the target string array. Taking the object pointed to by the first pointer as the current object and the substring pointed to by the second pointer as the current substring, perform the following operations: If the element type corresponding to both the current object and the current substring is plain text, add a translation field to the current object, assign the value of the current substring to the translation field, and move the first pointer to the next object and the second pointer to the next substring. If the element type corresponding to both the current object and the current substring is not plain text, and the index of the special identifier of the current object and the current substring is different, add a replacement field to the current object, assign the value of the index of the special identifier of the current substring to the replacement field, move the first pointer to the next object, and the second pointer to the next substring. If the element type corresponding to both the current object and the current substring is not plain text, and the index of the special identifier of the current object and the current substring is the same, move the first pointer to the next object. The process begins by setting the second pointer to the next substring. If the current object is plain text and the element type corresponding to the current substring is not plain text, a translation field is added to the current object, its value is set to null, and the first pointer is set to the next object. If the element type corresponding to the current object is not plain text and the element type corresponding to the current substring is plain text, a pre-translation field is added to the current object, the value of the current substring is assigned to the pre-translation field, and the second pointer is set to the next substring. If the first pointer points to the end of the original substring, a post-translation field is added to the current object, the concatenation result of all substrings between the current substring and the end of the target substring is assigned to the post-translation field, and the second pointer is set to the end of the target substring. If the second pointer points to the end of the target substring, a translation field is added to all objects between the current object and the end of the original substring, its value is set to null, and the first pointer is set to the end of the original substring.
[0116] The second step, if the object in the original string array contains a translation field, is to modify the text of the first plain text node under the command node or the first node in the plain text node set of the original document pointed to by the object to the value of the translation field, and set the values of the remaining plain text nodes to empty. If the object in the original string array contains a previous translation field, the first node under the command node or the first node in the plain text node set of the original document pointed to by the object is taken as the current node. A new plain text node is inserted at the index of the current node in the child node set of the parent node of the current node, and the value of the new plain text node is set to the previous translation field. The value of the translation field; if the object in the original string array contains a post-translation field, take the last node under the command node or the last node in the plain text node set of the original document pointed to by the object as the current node, insert a new plain text node at the index after the current node in the child node set of the current node's parent node, and set the value of the new plain text node to the value of the post-translation field; if the object in the original string array contains a replacement field, determine the node to be replaced from all nodes under the nearest common parent node of the node corresponding to the object and the node corresponding to the replacement field's index, and perform the replacement operation on the position of the node to be replaced.
[0117] Continuing with the LaTeX document as an example, we append backfill information to the intermediate expressions. By matching special tokens with serial numbers and format tokens, we split the formatted translation results into arrays of translated strings. We define source and translated string pointers, pointing to the source string array and the translated string array respectively, and process them sequentially until both pointers point to the end of their respective arrays. The processing rules are as follows: If both pointers point to plain text, add a "translation" field to the JSON object corresponding to the original pointer's position, with the value being the string corresponding to the translated pointer's position, and then move both pointers one position to the right. If both pointers point to non-plain text, for cases where the two special token numbers are inconsistent, add a "replace" field to the JSON object corresponding to the original pointer's position, with the value being the sequence number of the special token corresponding to the translated pointer's position, and then move both pointers one position to the right. For cases where the two special token numbers are consistent, only move both pointers one position to the right. If the original pointer points to plain text and the translated pointer points to non-plain text, add a "translation" field to the JSON object corresponding to the original pointer's position, with the value being an empty string, and then move the original pointer one position to the right. If the original pointer points to non-plain text and the translated pointer points to... For plain text, add a "translation-before" field to the JSON object corresponding to the position pointed to by the original pointer. The value of this field is the string at the position pointed to by the translation pointer. Then, move the translation pointer one position to the right. If the original pointer points to the end of the original string array, add a "translation-after" field to the JSON object corresponding to the last position of the original string array. The value of this field is the concatenation of all strings between the position pointed to by the translation pointer and the end of the translation string array. Then, move the translation pointer to the end of the translation string array. If the translation pointer points to the end of the translation string array, add a "translation" field to all corresponding JSON objects in the original string array between the position pointed to by the original pointer and the end of the original string array. The value of this field is an empty string. Then, move the original pointer to the end of the original string array.
[0118] The LaTeX document tree is adjusted based on the backfilled information. First, the intermediate JSON objects are traversed using a depth-first strategy. If the JSON object contains a "translation" field, the command node or plain text node set pointed to by the JSON object is retrieved. The text of the first plain text node under the corresponding command node or the first node in the plain text node set is modified to the value corresponding to the "translation" field, and the text of the remaining plain text nodes is modified to an empty string. If the JSON object contains a "translation-before" field, the first node under the specific command node pointed to by the JSON object or the first node in the plain text node set is taken as the current node. In the subtree set of the current node's parent node, a new node is inserted at the current node's index. A new plain text node is created, with its text being the value corresponding to the "translation-before" field. If the JSON object contains a "translation-after" field, the last node under the specific command node pointed to by the JSON object, or the last node in the plain text node set, is taken as the current node. In the subtree set of the current node's parent node, a new plain text node is inserted at index + 1 of the current node, with its text being the value corresponding to the "translation-after" field. If the JSON object contains a "replace" field, the node pair consisting of the node corresponding to the current JSON object and the node with the index corresponding to the "replace" field is added to the set to be reordered. Then, the set to be reordered is sorted, ordered from largest to smallest by the index of the first node in each node pair. Finally, the node pairs in the set to be reordered are traversed sequentially, and it is determined whether there is a fork in the path from the two nodes of the node pair to their nearest common ancestor node. If a fork exists (e.g., ...), the node pairs are reordered. Figure 7 As shown), then node splitting is performed (e.g. Figure 8 As shown), ensure that there are no branches on the path to the nearest common ancestor node, and then obtain the last node on the path (i.e., Figure 8 The nodes to be replaced (i.e., the nodes one level below the common ancestor node) are taken as the two nodes to be replaced, such as... Figure 9 The node replacement operation is shown.
[0119] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0120] According to another aspect of the embodiments of this application, a document translation apparatus is also provided, such as... Figure 10 As shown, it includes:
[0121] The first acquisition module 1002 is used to acquire the document to be translated in a predetermined format corresponding to the first document when a translation instruction to translate the first document under the target link is obtained during the process of displaying the current page.
[0122] Translation module 1004 is used to translate the document to be translated to obtain the translated document;
[0123] The first display module 1006 is used to display the translated document in a predetermined mode on the target page.
[0124] For other examples of this embodiment, please refer to the examples above, which will not be repeated here.
[0125] Figure 11 This is a structural block diagram of an optional electronic device according to an embodiment of this application, such as... Figure 11 As shown, it includes a processor 1102, a communication interface 1104, a memory 1106, and a communication bus 1108. The processor 1102, communication interface 1104, and memory 1106 communicate with each other via the communication bus 1108.
[0126] Memory 1106 is used to store computer programs;
[0127] When processor 1102 executes a computer program stored in memory 1106, it performs the following steps:
[0128] During the display of the current page, if a translation instruction is received to translate the first document under the target link, the document to be translated in a predefined format corresponding to the first document is obtained;
[0129] Translate the document to be translated to obtain the translated document;
[0130] The translated document is displayed in a pre-defined mode on the target page.
[0131] Optionally, in this embodiment, the communication bus can be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 11The symbol is represented by a single thick line, but this does not indicate that there is only one bus or one type of bus. The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0132] The memory may include RAM, or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0133] As an example, the memory 1106 described above may include, but is not limited to, the first acquisition module 1002, the translation module 1004, and the first display module 1006 of the document translation device described above. Furthermore, it may include, but is not limited to, other module units in the request processing device described above, which will not be elaborated upon in this example.
[0134] The processors mentioned above can be general-purpose processors, including but not limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; they can also be DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0135] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments, and will not be repeated here.
[0136] Those skilled in the art will understand that Figure 11 The structure shown is for illustrative purposes only. The device that implements the above document translation method can be a terminal device, such as a smartphone (e.g., Android phone, iOS phone), tablet computer, PDA, mobile Internet Devices (MID), PAD, etc. Figure 11 This does not limit the structure of the aforementioned electronic devices. For example, the electronic device may also include components that are more... Figure 11 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 11 The different configurations shown.
[0137] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, ROM, RAM, disk or optical disk, etc.
[0138] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, wherein the computer program is executed by a processor to perform the steps in the above-described document translation method.
[0139] Optionally, in this embodiment, those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0140] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0141] If the integrated units in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in the aforementioned computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0142] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0143] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between units or modules, and may be electrical or other forms.
[0144] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0145] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0146] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A document translation method, characterized in that, include: When the current page is the front-end page of the translation system, during the process of displaying the current page of the translation system, if a translation instruction to translate the first document under the target link is obtained, a document to be translated in a predetermined format corresponding to the first document is obtained. Specifically, if the target link is filled into the translation input box of the current page, or if the target link is filled into the translation input box of the current page and the translation button is triggered, it is determined that the translation instruction has been obtained. The translated document is obtained by translating the document to be translated. The translated document is displayed in a predetermined mode on the target page of the translation system. Wherein, the page corresponding to the target link is the download page of the first document, through which the first document in a first format different from the predetermined format can be downloaded; according to the target link, the document in the predetermined format corresponding to the first document is obtained as the document to be translated.
2. The method according to claim 1, characterized in that, When the current page is the download page where the first document is located, the first document in a first format different from the predetermined format can be downloaded through the current page. During the display of the current page, the method further includes: Display translation control; When the translation control is triggered, it is determined that the translation instruction has been obtained; The document in a predetermined format corresponding to the first document displayed on the current page is obtained as the document to be translated.
3. The method according to claim 2, characterized in that, The display translation control includes: When navigating from the first page to the current page, the translation control is displayed. The first page is a page that displays the document link of the first document. The first page displays multiple document links, including the document link of the first document. When the document link of the first document is triggered, navigating from the first page to the current page occurs.
4. The method according to claim 3, characterized in that, The step of obtaining the pre-formatted document corresponding to the first document displayed on the current page as the document to be translated includes: Send a request to the target server, wherein the request includes the document encoding of the first document in the webpage link of the current page, the request is used to download the document to be translated in the predetermined format according to the document encoding, and the target server is a third-party server that provides the document to be translated; Receive the document to be translated in a predetermined format returned by the target server; Before displaying the translated document in a predetermined mode on the target page of the translation system, the following steps are also included: Create a new tab; Use the newly created tab as the target page.
5. The method according to claim 1, characterized in that, Obtaining a document in a predetermined format corresponding to the first document as the document to be translated, based on the target link, includes: Send an acquisition request to the target server, wherein the acquisition request includes the document encoding of the first document of the target link, the acquisition request is used to download the document to be translated in the predetermined format according to the document encoding, and the target server is a third-party server that provides the document to be translated; Receive the document to be translated in a predetermined format returned by the target server.
6. The method according to claim 1, characterized in that, The process of displaying the translated document in a predetermined mode on the target page of the translation system includes: Jump from the current page to the target page; The translated document is displayed in a predetermined mode on the target page.
7. A document translation device, characterized in that, include: The first acquisition module is used to acquire a document in a predetermined format corresponding to the first document when the current page is the front-end page of the translation system and the current page of the translation system is displayed. In the process of acquiring the translation instruction to translate the first document under the target link, the module is used to acquire the document to be translated when the target link is filled into the translation input box of the current page, or when the target link is filled into the translation input box of the current page and the translation button is triggered. The translation module is used to translate the document to be translated to obtain the translated document. A first display module is used to display the translated document in a predetermined mode on the target page of the translation system; Wherein, the page corresponding to the target link is the download page of the first document, through which the first document in a first format different from the predetermined format can be downloaded; according to the target link, the document in the predetermined format corresponding to the first document is obtained as the document to be translated.
8. A computer-readable storage medium storing a computer program, characterized in that, The computer program is executed by the processor to perform the method described in any one of claims 1 to 6.
9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method described in any one of claims 1 to 6 through the computer program.