Document translation methods, devices, storage media, and electronic devices

By directly identifying and translating the original strings in the LaTeX document and then backfilling them into the original document, the problem of low efficiency in LaTeX document translation is solved, achieving efficient and accurate document translation.

CN116306700BActive Publication Date: 2026-05-26WANGYIYOUDAO INFORMATION TECH BEIJING CO LTD
View PDF 1 Cites 0 Cited by

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-05-26

AI Technical Summary

Technical Problem

Existing document translation technologies cannot directly process LaTeX format documents, resulting in low translation efficiency and a high risk of losing document structure information and making translation errors.

Method used

The original strings to be translated are directly identified from the original LaTeX document, translated, and then backfilled into the original document, avoiding the rendering of PDF files. Special identifiers and translation strategies are used to process the structure and elements of the LaTeX document.

Benefits of technology

It improved translation efficiency, reduced the loss of document structure information and translation errors, and ensured translation quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116306700B_ABST
    Figure CN116306700B_ABST
Patent Text Reader

Abstract

This invention discloses a document translation method, apparatus, storage medium, and electronic device. The method includes: determining the original string to be translated from the original LaTeX format document; translating the original string to obtain a target string; and filling the original document with the translated target string to obtain the translated target document. This invention solves the translation problem of LaTeX format documents, maintaining good document formatting while avoiding mistranslation of non-translatable elements such as formulas and citations, achieving a smoother translation effect.
Need to check novelty before this filing date? Find Prior Art

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] Existing document translation technologies do not support the translation of LaTeX format documents. Therefore, the usual practice for translating such documents is to use existing PDF document translation technologies to translate the rendered PDF files.

[0003] However, rendering a LaTeX document into a PDF file first, and then translating the PDF file, will inevitably lead to low translation efficiency. Summary of the Invention

[0004] This invention provides a document translation method, apparatus, storage medium, and electronic device to at least solve the technical problem of low translation efficiency.

[0005] According to one aspect of the present invention, a document translation method is provided, comprising: determining the original string to be translated from the original LaTeX format document to be translated; translating the original string to obtain a target string; and filling the translated target string back into the original document to obtain a translated target document.

[0006] As an optional example, the above translation of the original string to obtain the target string includes: converting each segment of the original string into a string representation to generate 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 based on the first string, the second string, and the third string.

[0007] As an optional example, the above conversion of the original string into a first string based on whether the string representation in the original string is plain text includes: if the string representation is plain text, retaining the string representation; if the string representation is not plain text, adding the special identifier to the string representation.

[0008] As an optional example, determining the target string 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 special identifier in the first string within the second string; and inserting the special identifier into the third string according to the relationship and the position to obtain the target string.

[0009] As an optional example, translating the second string to obtain the translated third string includes translating the second string according to the translation method required by the structural block containing the second string to obtain the third string.

[0010] As an optional example, the process of backfilling the translated target string into the original document to obtain the translated target document includes: converting the target string into a target string array and a target element type identifier according to the special identifier in the target string; mapping each substring in the target string array to each substring in the original string array according to the correspondence between the original element type identifier and the target element type identifier; adding a corresponding field and assigning a field value to each object in the original string array; and backfilling the translated target string into the original document according to the corresponding field and field value of each object to obtain the target document.

[0011] As an optional example, the above-described correspondence between the original element type identifier and the target element type identifier, mapping each substring in the target string array to each object in the original string array, and adding an object field and assigning a field value to each object in the original string array, includes: using a first pointer to point to the first object in the original string array and using a 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, and performing the following operation: in the element class corresponding to the current object and the current substring... When both the current object and the element type of the current substring are plain text, a translation field is added to the current object, the value of the current substring is assigned to the translation field, the first pointer is set to the next object, and the second pointer is set to the next substring. When the element types of both the current object and the current substring are not plain text, and the sequence numbers of the special identifiers of the current object and the current substring are inconsistent, a replacement field is added to the current object, the value of the sequence number of the special identifier of the current substring is assigned to the replacement field, the first pointer is set to the next object, and the second pointer is set to the next substring. When the element types of both the current object and the current substring are not plain text, a replacement field is added to the current object, the value of the sequence number of the special identifier of the current substring is assigned to the replacement field, the first pointer is set to the next object, and the second pointer is set to the next substring. If both types are non-plain text, and the sequence number of the special identifier of the current object and the current substring is the same, then the first pointer is moved to the next object, and the second pointer is moved to the next substring. If the current object is plain text and the element type corresponding to the current substring is non-plain text, then a translation field is added to the current object, the value of the translation field is set to null, and the first pointer is moved to the next object. If the element type corresponding to the current object is non-plain text and the element type corresponding to the current substring is plain text, then 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... The second pointer points to the next substring; when 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 points to the end of the target substring; when 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, the value of the translation field is set to null, and the first pointer points to the end of the original substring.

[0012] As an optional example, the above method, based on the corresponding fields and field values ​​of each object, backfills the translated target string into the original document, resulting in the target document comprising: if the objects in the original string array contain translation fields, modifying the text of the first plain text node under the command node or the first node in the plain text node set in the original document pointed to by the object to the value of the translation field, and adjusting the values ​​of the remaining plain text nodes to empty; if the objects in the original string array contain the previous translation fields, taking the first node under the command node or the first node in the plain text node set in the original document pointed to by the object as the current node, and in the child node set of the parent node of the current node, at the index of the current node... Insert a new plain text node at the specified position and set its value to the value of the aforementioned pre-translation field. If the object in the aforementioned 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's index in the child node set of the current node's parent node and set its value to the value of the aforementioned post-translation field. If the object in the aforementioned 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 a replacement operation on the position of the node to be replaced.

[0013] As an optional example, after backfilling the translated target string into the original document to obtain the translated target document, the method further includes: adding language support commands to the target document according to the language of the translation.

[0014] According to another aspect of the present invention, a document translation apparatus is provided, comprising: a determining module, configured to determine an original string to be translated from an original LaTeX format document to be translated; a translation module, configured to translate the original string to obtain a target string; and a backfilling module, configured to backfill the translated target string into the original document to obtain a translated target document.

[0015] As an optional example, the above-mentioned determining module includes: a first filtering unit, used to filter candidate original files from all files in the above-mentioned original document according to the file extension; a generating unit, used to generate a file tree of the above-mentioned candidate original files; a first determining unit, used to take the file containing a predetermined character in the above-mentioned candidate original files as the entry file; a second filtering unit, used to filter a first file from the above-mentioned candidate original files based on the file reference relationship contained in the command type node in the file, starting from the above-mentioned entry file, wherein the type of the above-mentioned node is determined according to the above-mentioned file tree; and a second determining unit, used to determine the paragraph in the above-mentioned first file as the above-mentioned original string.

[0016] As an optional example, the above generation unit includes: a first determining subunit, used to create a root node for the candidate original file and use the root node as the current node; a traversal subunit, used to traverse the string variables of the candidate original file; for each traversal of a command start character, generating a command child node for the current node and using the command child node as the new current node; for each traversal of a command end character, using the parent node of the current node as the new current node; and for each traversal of a plain string, generating a text child node for the current node.

[0017] As an optional example, the second determining unit includes: a generating subunit, configured to generate an intermediate representation with a hierarchical structure from the first file according to the file tree of the first file, wherein the hierarchical structure includes paragraph layers; and a second determining subunit, configured to determine the string corresponding to the paragraph layer as the original string.

[0018] As an optional example, the above-described generation subunit is further configured to: use the file tree of the first file as the file layer of the intermediate expression; use each document structure-related command node in the file tree of the first file as the structural block layer of the intermediate expression; use each document element-related command node in the file tree of the first file as the paragraph layer of the intermediate expression; use each leaf node in the file tree of the first file as the fragment layer of the intermediate expression; and construct different translation strategies for different structural block layers.

[0019] As an optional example, the translation module includes: a conversion unit, configured to convert each segment of the original string into a string representation, generating 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 based on the first string, the second string, and the third string.

[0020] As an optional example, the above conversion unit includes: a first processing subunit, used to retain the above string representation when the above string representation is plain text; and to add the above special identifier to the above string representation when the above string representation is not plain text.

[0021] As an optional example, the above conversion unit includes: a second processing subunit, used to perform word segmentation on the second string and the third string; establish a correlation between the word segments; determine the position of the special identifier in the first string in the second string; and insert the special identifier into the third string according to the correlation and the position to obtain the target string.

[0022] As an optional example, the above conversion unit includes: a translation subunit, used to translate the above second string according to the translation method required by the structure block in which the above second string is located, to obtain the above third string.

[0023] As an optional example, the backfilling module includes: a backfilling unit, used to convert the target string into a target string array and a target element type identifier according to the special identifier in the target string; according to the correspondence between the original element type identifier and the target element type identifier, to map each substring in the target string array to each substring in the original string array, to add a corresponding field and assign a field value to each object in the original string array; and to backfill the translated target string into the original document according to the corresponding field and field value of each object, thereby obtaining the target document.

[0024] As an optional example, the backfill unit includes: a backfill subunit, used to point to the first object in the original string array using a first pointer and to point to the first substring in the target string array using a second pointer; 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, and performing the following operations: when the element types corresponding to the current object and the current substring are both plain text, add a translation field to the current object, assign the value of the current substring to the translation field, point the first pointer to the next object, and point the second pointer to the next substring; when the element types corresponding to the current object and the current substring are both non-plain text, and the sequence numbers of the special identifiers of the current object and the current substring are inconsistent, add a replacement field to the current object, assign the value of the sequence number of the special identifier of the current substring to the replacement field, point the first pointer to the next object, and point the second pointer to the next substring; when the element types corresponding to the current object and the current substring are both non-plain text, and the sequence numbers of the special identifiers of the current object and the current substring are consistent, add the first object to the translation field, assign the value of the first pointer to the translation field, point the second pointer to the next object, and point the second pointer to the next substring; when the element types corresponding to the current object and the current substring are both non-plain text, and the sequence numbers of the special identifiers of the current object and the current substring are consistent, add the first object to the translation field, assign the first pointer to the translation field, and point the second pointer to the translation field; when the element types corresponding to the current object and the current substring are both non-plain text, and the sequence numbers of the special identifiers of the current object and the current substring are consistent ... The first pointer points to the next object, and the second pointer points 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, the value of the translation field is set to null, and the first pointer points 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 points 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 points 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, the value of the translation field is set to null, and the first pointer points to the end of the original substring.

[0025] As an optional example, the above backfill subunit is also used to: if the object in the above original string array contains a translation field, modify the text of the first plain text node under the command node or the first node in the plain text node set in the above original document pointed to by the object to the value of the translation field, and adjust the values ​​of the remaining plain text nodes to empty; if the object in the above original string array contains a previous translation field, take the first node under the command node or the first node in the plain text node set in the above original document pointed to by the object as the current node, insert a new plain text node at the index of the current node in the child node set of the parent node of the current node, and set the new plain text node to empty. The value of the point is set to the value of the aforementioned pre-translation field; if the object in the aforementioned original string array contains a post-translation field, the last node under the command node or the last node in the plain text node set in the aforementioned original document pointed to by the aforementioned object is taken as the current node. In the child node set of the parent node of the aforementioned current node, a new plain text node is inserted at the index after the index of the current node, and the value of the new plain text node is set to the value of the aforementioned post-translation field; if the object in the aforementioned original string array contains a replacement field, the node to be replaced is determined from all nodes under the nearest common parent node of the node corresponding to the aforementioned object and the node corresponding to the serial number of the replacement field, and the replacement operation is performed on the position of the node to be replaced.

[0026] As an optional example, the above apparatus further includes: an adding module, used to add language support commands to the target document according to the language of the translation after backfilling the translated target string into the original document to obtain the translated target document.

[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 to determine the original string to be translated from the original LaTeX format document to be translated; translate the original string to obtain the target string; and fill the translated target string back into the original document to obtain the translated target document. Since the original string to be translated can be determined from the original document of the predetermined format, and then the target string can be translated and the target string can be filled back into the original document, the LaTeX format document does not need to be rendered before translation, thereby improving the translation efficiency and solving the technical problem of low translation efficiency. 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 document tree example diagram of an optional document translation method according to an embodiment of the present invention;

[0033] Figure 3 This is a document tree example diagram of another optional document translation method according to an embodiment of the present invention;

[0034] Figure 4 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;

[0035] Figure 5 This is an example diagram of document tree splitting for an optional document translation method according to an embodiment of the present invention;

[0036] Figure 6 This is an example diagram of document tree replacement for an optional document translation method according to an embodiment of the present invention;

[0037] Figure 7 This is a schematic diagram of the structure of an optional document translation device according to an embodiment of the present invention;

[0038] Figure 8 This is a schematic diagram of an optional electronic device according to an embodiment of the present invention. Detailed Implementation

[0039] 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.

[0040] 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.

[0041] Existing technologies translate documents based on rendered PDF files, resulting in the loss of original document structure information, non-translated element information, and layout information. This leads to problems such as paragraphing errors, mistranslation of non-translated elements, and poor layout quality. Furthermore, it is difficult to recreate the LaTeX translation from the PDF format. To address these issues of low translation efficiency and further resolve the aforementioned problems, this embodiment provides a document translation method, optionally, as follows: Figure 1 As shown, the above method includes:

[0042] S102, Identify the original string to be translated from the original LaTeX format document to be translated;

[0043] S104, translate the original string to obtain the target string;

[0044] S106, the translated target string is backfilled into the original document to obtain the translated target document.

[0045] The original document mentioned above can be a LaTeX document. LaTeX is a typesetting system based on TeX that uses a combination of text and commands to control styles and layout. For a LaTeX document, the process involves first determining the original string to be translated, then translating it to obtain the target string, and finally filling the original document with the target string to obtain the translated target document. The predefined format mentioned above can be LaTeX, and the original document can be a LaTeX source project package. A LaTeX project package can include multiple files.

[0046] For the step S102 above to determine the original string, the following method can be used: filter candidate original files from all files in the original document according to the file extension; generate a file tree of candidate original files; take the file containing the predetermined character 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, wherein the type of the node is determined according to the file tree; determine the paragraph in the first file as the original string.

[0047] 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.

[0048] 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.

[0049] 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.

[0050] 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.

[0051] 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.

[0052] 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.

[0053] For example, such as Figure 2 and Figure 3 As shown, Figure 2 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".

[0054] Figure 3 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.

[0055] 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.

[0056] 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.

[0057] 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.

[0058] 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.

[0059] By following the steps described above, the content to be translated can be determined from a document in a specific format.

[0060] 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.

[0061] 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.

[0062] 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.

[0063] 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.

[0064] 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.

[0065] 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.

[0066] Finally, the string corresponding to the paragraph is used as the original string to determine the original string to be translated.

[0067] For step S104 above, translating the original string to obtain the target string, the following can be done: convert each segment of the original string into a string representation, generating 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 based on the first string, the second string, and the third string.

[0068] 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.

[0069] When determining the target string, the second string and the third string can be segmented; an association relationship can be established between the segments; the position of the special identifier in the first string in the second string can be determined, and the special identifier can be inserted into the third string according to the association relationship and the position to obtain the target string.

[0070] 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.

[0071] 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.

[0072] 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.

[0073] 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).

[0074] Regarding step S106 above, after translating the target string, the target string can be backfilled into the original document to replace the original string, thus obtaining the translated target document. The backfilling process consists of 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 backfill the translated target string into the original document to obtain the target document.

[0075] 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.

[0076] 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.

[0077] 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.

[0078] 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 4 As shown), then node splitting is performed (e.g. Figure 5 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 5 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 6 The node replacement operation is shown.

[0079] 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.

[0080] According to another aspect of the embodiments of this application, a document translation apparatus is also provided, such as... Figure 7 As shown, it includes:

[0081] The determination module 702 is used to determine the original strings to be translated from the original LaTeX format document to be translated;

[0082] Translation module 704 is used to translate the original string to obtain the target string;

[0083] The backfill module 706 is used to backfill the translated target string into the original document to obtain the translated target document.

[0084] For other examples of this embodiment, please refer to the examples above, which will not be repeated here.

[0085] Figure 8 This is a schematic diagram of an optional electronic device according to an embodiment of this application, such as... Figure 8 As shown, it includes a processor 802, a communication interface 804, a memory 806, and a communication bus 808. The processor 802, communication interface 804, and memory 806 communicate with each other via the communication bus 808.

[0086] Memory 806 is used to store computer programs;

[0087] When processor 802 executes a computer program stored in memory 806, it performs the following steps:

[0088] Identify the original strings to be translated from the original document in the predefined format;

[0089] Translate the original string to obtain the target string;

[0090] The translated target string is then inserted back into the original document to obtain the translated target document.

[0091] 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 8 The 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.

[0092] 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.

[0093] As an example, the memory 806 described above may include, but is not limited to, the determining module 702, the translation module 704, and the backfilling module 706 of the document translation device described above. Furthermore, it may include, but is not limited to, other module units of the document translation device described above, which will not be elaborated upon in this example.

[0094] 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.

[0095] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments, and will not be repeated here.

[0096] Those skilled in the art will understand that Figure 8 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 8 This does not limit the structure of the aforementioned electronic devices. For example, the electronic device may also include components that are more... Figure 8 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 8 The different configurations shown.

[0097] 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.

[0098] 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.

[0099] 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.

[0100] 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.

[0101] 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 of the various embodiments of the present invention.

[0102] 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.

[0103] 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.

[0104] 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.

[0105] 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.

[0106] 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: Identify the original strings to be translated from the original LaTeX document; The original string is translated to obtain the target string; The translated target string is then backfilled into the original document to obtain the translated target document; The step of determining the original string to be translated from the original LaTeX document includes: filtering candidate original files from all files in the original document according to their file extensions; generating a file tree of the candidate original files; using the file containing the predetermined string in the candidate original files as the entry file; using the entry file as the starting point, filtering the first file from the candidate original files according to the file reference relationship contained in the command type node in the file, wherein the type of the node is determined according to the file tree; and determining the paragraph in the first file as the original string. The process of generating the file tree for the candidate original files includes: creating a root node for the candidate original files and using the root node as the current node; traversing the string variables of the candidate original files; generating a command child node for the current node and using the command child node as the new current node for each command start character encountered during traversal; using the parent node of the current node as the new current node for each command end character encountered during traversal; and generating a text child node for the current node for each plain string encountered during traversal. The step of determining the paragraphs in the first file as the original string includes: generating an intermediate representation of the first file with a hierarchical structure based on the file tree of the first file, wherein the hierarchical structure includes paragraph layers; and determining the string corresponding to the paragraph layer as the original string.

2. The method according to claim 1, characterized in that, The step of generating an intermediate representation with a hierarchical structure from the first file based on the file tree of the first file includes: The file tree of the first file is used as the file layer of the intermediate expression; Each document structure-related command node in the file tree of the first file is used as the structural block layer of the intermediate expression; The command node associated with each document element in the file tree of the first file is used as the paragraph layer of the intermediate expression; Each leaf node in the file tree of the first file is used as a fragment layer of the intermediate expression; Different translation strategies are constructed for different structural block layers.

3. The method according to claim 1, characterized in that, The process of translating the original string to obtain the target string includes: Each segment of the original string is converted into a string representation, generating an array of original strings and an original element type identifier; The original string is converted into a first string according to whether the string in the original string indicates that it is plain text, wherein the first string includes a special identifier; The second string is obtained by filtering out the special identifiers in the first string; Translate the second string to obtain the translated third string; The target string is determined based on the first string, the second string, and the third string.

4. The method according to claim 3, characterized in that, The step of converting the original string into a first string according to whether the string representation in the original string is plain text includes: If the string representation is plain text, the string representation is preserved; When the string representation is not plain text, the special identifier is added to the string representation.

5. The method according to claim 3, characterized in that, Determining the target string based on the first string, the second string, and the third string includes: Perform word segmentation on the second string and the third string; Establish associations between the word segments; Determine the position of the special identifier described in the first string in the second string; Based on the aforementioned association and position, the special identifier is inserted into the third string to obtain the target string.

6. The method according to claim 3, characterized in that, The translation of the second string to obtain the translated third string includes: The second string is translated according to the translation method required by the structural block containing the second string to obtain the third string.

7. The method according to claim 3, characterized in that, The step of backfilling the translated target string into the original document to obtain the translated target document includes: Based on the special identifier in the target string, the target string is converted into a target string array and a target element type identifier; Based on the correspondence between the original element type identifier and the target element type identifier, each substring in the target string array is mapped to each substring in the original string array, and a corresponding field is added and a field value is assigned to each object in the original string array; Based on the corresponding fields and field values ​​of each object, the translated target string is backfilled into the original document to obtain the target document.

8. The method according to claim 7, characterized in that, The step of mapping 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, and adding an object field and assigning a field value to each object in the original string array, includes: Use a first pointer to point to the first object in the original string array and a 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 operation: When the element type corresponding to the current object and the current substring is both plain text, add a translation field to the current object, assign the value of the current substring to the translation field, and point the first pointer to the next object and the second pointer to the next substring. When the element types corresponding to the current object and the current substring are both non-plain text, and the sequence numbers of the special identifiers of the current object and the current substring are inconsistent, a replacement field is added to the current object, the value of the sequence number of the special identifier of the current substring is assigned to the replacement field, the first pointer is pointed to the next object, and the second pointer is pointed to the next substring. When the element types corresponding to the current object and the current substring are both non-plain text, and the sequence number of the special identifier of the current object and the current substring is the same, the first pointer is pointed to the next object, and the second pointer is pointed to the next substring. If the current object is plain text and the element type corresponding to the current substring is not plain text, add a translation field to the current object, set the value of the translation field to null, and point the first pointer to the next object; When the element type corresponding to the current object is non-plain text and the element type corresponding to the current substring is plain text, add a pre-translation field to the current object, assign the value of the current substring to the pre-translation field, and point the second pointer to the next substring; When the first pointer points to the end position of the original string substring, a post-translation field is added to the current object, the concatenation result of all substrings between the current substring and the end position of the target string substring is assigned to the post-translation field, and the second pointer is pointed to the end position of the target string substring; When the second pointer points to the end position of the target string substring, add a translation field to all objects from the current object to the end position of the original string substring, set the value of the translation field to null, and point the first pointer to the end position of the original string substring.

9. The method according to claim 8, characterized in that, The step of backfilling the translated target string into the original document based on the corresponding fields and field values ​​of each object, resulting in the target document, includes: If the object in the original string array contains a translation field, modify the text of the first plain text node under the command node or the first node in the set of plain text nodes in the original document pointed to by the object to the value of the translation field, and adjust the values ​​of the remaining plain text nodes to empty; If the object in the original string array contains a pre-translation field, the first node under the command node or the first node in the plain text node set in the original document pointed to by the object is taken as the current node. In the child node set of the parent node of the current node, a new plain text node is inserted at the index where the current node is located, and the value of the new plain text node is set to the value of the pre-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 in the original document pointed to by the object as the current node, insert a new plain text node at the index after the index of the current node in the child node set of the parent node of the current 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, the node to be replaced is determined from all the nodes under the nearest common parent node of the node corresponding to the object and the node corresponding to the serial number of the replacement field, and the replacement operation is performed on the position of the node to be replaced.

10. The method according to claim 1, characterized in that, After filling the translated target string back into the original document to obtain the translated target document, the method further includes: Add language support commands to the target document based on the language of the translation.

11. A document translation device, characterized in that, include: The determination module is used to identify the original strings to be translated from the original LaTeX format document to be translated; The translation module is used to translate the original string to obtain the target string; The backfill module is used to backfill the translated target string into the original document to obtain the translated target document; The step of determining the original string to be translated from the original LaTeX document includes: filtering candidate original files from all files in the original document according to their file extensions; generating a file tree of the candidate original files; using the file containing the predetermined string in the candidate original files as the entry file; using the entry file as the starting point, filtering the first file from the candidate original files according to the file reference relationship contained in the command type node in the file, wherein the type of the node is determined according to the file tree; and determining the paragraph in the first file as the original string. The process of generating the file tree for the candidate original files includes: creating a root node for the candidate original files and using the root node as the current node; traversing the string variables of the candidate original files; generating a command child node for the current node and using the command child node as the new current node for each command start character encountered during traversal; using the parent node of the current node as the new current node for each command end character encountered during traversal; and generating a text child node for the current node for each plain string encountered during traversal. The step of determining the paragraphs in the first file as the original string includes: generating an intermediate representation of the first file with a hierarchical structure based on the file tree of the first file, wherein the hierarchical structure includes paragraph layers; and determining the string corresponding to the paragraph layer as the original string.

12. 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 10.

13. 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 10 through the computer program.