Precise translation and asynchronous blocking processing method for API response body content

By constructing a semantic compensation window using a tree-based path encoder and a semantic compensation algorithm, and combining asynchronous translation and in-situ backfilling mechanisms, the translation coherence and nested structure compatibility issues of the API response body are resolved, reducing synchronous call latency and improving system stability.

CN122047263APending Publication Date: 2026-05-15CHINA ASEAN INFORMATION PORT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-25
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing API response translation technologies suffer from problems such as fragmented text context, rigid logic for extracting deeply nested structures, and high latency and poor fault tolerance in synchronous call chains.

Method used

The tree-structured path encoder identifies the fields to be translated, the semantic compensation extraction algorithm is used to construct a semantic compensation window, and the asynchronous translation task is implemented by combining a tag generator, serializer and message queue. The thread pool concurrent scheduling and structure reconstruction engine are used for in-situ backfilling, and the exponential backoff retryer and callback polling module are used for exception handling.

Benefits of technology

It improved the translation coherence of API response content, enhanced compatibility with nested data structures, reduced API request timeout rates, and improved the reliability of task delivery and system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122047263A_ABST
    Figure CN122047263A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of API (Application Program Interface) data processing and machine translation, and discloses a precise translation and asynchronous blocking processing method for API response body content, which comprises the following steps that: a tree path encoder identifies a field to be translated by utilizing a reflection mechanism; and generating task metadata containing a path vector of the to-be-translated field in the JSON nested structure according to a path coding formula. The identifier generator and the serializer generate a global request serial number and task snapshot data and distribute asynchronous tasks. A regular cleaner generates a cleaned text, and a semantic compensation extraction algorithm executes logic truncation and splices a semantic compensation window to generate a to-be-translated input sequence. And the thread pool concurrently schedules a third-party engine to obtain translation blocks, and the structure reconstruction engine executes in-situ backfilling to generate a translated response body after eliminating redundant translation contents. And the exponential backoff retry device processes the exception, and the callback polling module adopts a double-track delivery strategy to deliver the result. The problem of context deficiency is solved, and translation continuity is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of API data processing and machine translation technology, specifically a method for accurate translation and asynchronous chunking of API response content. Background Technology

[0002] With the rapid development of globalized internet businesses, API interfaces, as the core medium for data interaction, carry a large amount of text content that requires multilingual translation. In scenarios such as cross-border e-commerce, multilingual social networking, and internationalized software services, systems need to perform real-time translation of dynamically generated API responses to meet the reading needs of users in different countries and regions.

[0003] However, existing API content translation solutions have revealed significant limitations in practical engineering applications. When processing extremely long text fields, common techniques often rely solely on the character length limits of third-party translation engines for mechanical truncation. This approach severs the semantic connections between text chunks, causing translation engines to suffer from severe semantic deviations or grammatical errors when receiving discrete text fragments due to the lack of contextual information, thus affecting the coherence of API response content.

[0004] Meanwhile, modern API response bodies typically employ highly complex nested JSON structures with deep data hierarchies and numerous dynamic arrays. Existing field extraction and backfilling methods largely rely on hard-coded logic specific to the API structure, lacking the ability to generalize to heterogeneous data structures. When API versions are updated or the nesting level of the response body changes, the fixed extraction logic cannot automatically identify and accurately locate the fields to be translated, resulting in poor system compatibility when dealing with deeply nested structures and increased maintenance costs.

[0005] Furthermore, third-party translation services are typically provided on public cloud platforms, which are subject to network fluctuations, API frequency limits, and the processing load of the translation engine itself, resulting in highly uncertain call latency. Existing translation workflows are mostly integrated into the synchronous response chain of APIs, which can easily trigger API gateway timeouts and circuit breakers when facing high concurrency or slow external engine responses. Due to the lack of robust asynchronous buffering, task snapshot management, and fault-tolerant retry mechanisms for partial translation failures, an abnormal call to a single text chunk often leads to the failure of the entire API request delivery, failing to guarantee the overall stability of the interface service. Summary of the Invention

[0006] To address the shortcomings of existing technologies, this invention provides a method for accurate translation and asynchronous chunking of API response content, which solves the problems of fragmented text chunking context, rigid logic for extracting deeply nested structures, and high latency and poor fault tolerance in synchronous call chains in existing API response translation technologies.

[0007] This invention provides a method for accurate translation and asynchronous chunking of API response body content, comprising the following steps:

[0008] A tree-based path encoder utilizes reflection to scan the response entity class structure of the external input, identifying the fields to be translated by retrieving custom meta-annotations. The encoder recursively parses to determine the logical path depth and sibling index position of the fields to be translated within the nested JSON structure of the external input, and generates path vectors based on path encoding formulas to construct task metadata containing these path vectors. These path vectors are used to determine the positioning coordinates of subsequent translation results within the data structure, enabling in-situ backfilling of the translated content.

[0009] The identifier generator generates a global request sequence number for API requests from external inputs, serving as a task association index throughout the entire process. The serializer performs associative encapsulation and persistence processing on task metadata, the original request parameters from external inputs, the original response body template from external inputs, and the target language preferences from external inputs, generating task snapshot data. Asynchronous translation tasks containing task snapshot data are distributed via a message queue to achieve architectural decoupling between the interface service and the translation tasks.

[0010] The regular expression cleaner extracts the original content of fields from the task snapshot data, using regular expressions to match and remove escape characters and control characters to generate cleaned text. The semantic compensation extraction algorithm performs logical truncation on the cleaned text based on the length threshold of the third-party translation engine. When the text length exceeds the threshold, the semantic compensation extraction algorithm searches forward for the nearest text terminator as the truncation point to divide the text into blocks to be translated. The semantic compensation extraction algorithm extracts a character fragment of a predetermined length from the end of the previous block to be translated as a semantic compensation window, and concatenates the semantic compensation window to the beginning of the current block to be translated according to the semantic compensation formula, generating a sequence of input to be translated that includes contextual information, thus reducing semantic deviation in machine translation at text truncation points.

[0011] A thread pool concurrently schedules a third-party translation engine to translate the input sequence and obtain translation chunks. The structural reconstruction engine extracts the translation fragments corresponding to the semantic compensation windows within each translation chunk and aligns them with the end text of the preceding translation chunk. It identifies and trims redundant translation content caused by contextual splicing to generate clean translation content. The structural reconstruction engine parses the path vector in the task metadata, recursively addresses the target node in the original response body template, replaces the original text of the target node with clean translation content, and assembles the translated response body after all fields to be translated have been replaced.

[0012] When the exponential backoff retry mechanism detects an anomaly in the translation call, it reissues the input sequence to be translated using a strategy of progressively increasing time intervals, and executes backoff protection after reaching the maximum retry threshold. The callback polling module uses the global request serial number to match the stored translated response body, employing a dual-track delivery strategy of proactive push and reactive query to complete the delivery of the translated response body to the caller.

[0013] This invention provides a method for accurate translation and asynchronous chunking of API response body content. It offers the following advantages:

[0014] 1. This invention utilizes a semantic compensation extraction algorithm to construct a semantic compensation window between blocks to be translated. By introducing the context of the preceding text into the current block to be translated, it solves the problem of semantic deviation in the translation caused by the loss of context when machine translation processes logical truncation of long texts, and improves the translation coherence of API response content.

[0015] 2. This invention transforms the data structure into path vectors using a tree-based path encoder and leverages task metadata to guide the structure reconstruction engine in performing in-situ backfilling. This mechanism achieves the mapping and positioning of translated content with the original data structure, eliminating the need for hard-coding for different API response formats and enhancing the system's compatibility with nested data structures.

[0016] 3. This invention employs an identifier generator, serializer, and message queue to construct an asynchronous processing system, separating external translation calls from API synchronous response processes. By combining thread pool concurrent scheduling and an exponential backoff retry mechanism, the timeout rate of API requests is reduced, and a dual-track delivery strategy is used to improve the reliability of task delivery. Attached Figure Description

[0017] Figure 1 This is a flowchart of a method for accurate translation and asynchronous chunking of API response body content according to the present invention;

[0018] Figure 2 This is a flowchart of the response entity metadata modeling and path identification process of the present invention;

[0019] Figure 3 This is a flowchart of the intelligent block preprocessing based on semantic compensation window of the present invention. Detailed Implementation

[0020] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. 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 are within the scope of protection of the present invention.

[0021] Please see the appendix Figure 1 This invention provides a method for accurate translation and asynchronous chunking of API response body content, comprising the following steps:

[0022] In step S1, the tree path encoder uses reflection to scan the response entity class structure (external API definition) to accurately identify the marked fields to be translated (external development configuration). The tree path encoder then performs recursive parsing on the identified fields to be translated, determining their logical hierarchical path within the nested JSON structure (external data structure), and uses the path encoding formula to calculate and generate the corresponding path vector, thereby generating task metadata containing structural location index information.

[0023] The path encoding formula is as follows:

[0024] ;

[0025] In the formula: Indicates the field to be translated Path vector; Indicates the first Hierarchical key name or array index; Indicates the field to be translated Nesting depth.

[0026] In step S2, the identifier generator performs a generation action on the received API request (triggered by an external call) to generate a unique global request serial number. The serializer performs an association and encapsulation action on the task metadata, original request parameters (external call input), original response body template (external API definition), and target language preference (external call input) to construct persistent task snapshot data. The message queue receives and distributes the task snapshot data, activating the asynchronous translation task.

[0027] In step S3, the regular expression cleaner extracts the original content of fields from the task snapshot data carried by the asynchronous translation task activated in step S2, and performs regular expression filtering to generate normalized cleaned text. The semantic compensation extraction algorithm performs logical truncation on the cleaned text to divide it into blocks to be translated.

[0028] If no terminating punctuation mark is found within the length threshold after text cleaning, a hard truncation is forced according to the length threshold. Then, the semantic compensation window at the end of the preceding block is calculated based on the semantic compensation formula. Perform a concatenation operation with the current block to generate a semantically coherent input sequence to be translated.

[0029] The semantic compensation formula is as follows:

[0030] ;

[0031] In the formula: Indicates the first One input sequence to be translated; This represents a semantic truncation function; This indicates the previous block to be translated; Indicates the length of the semantic compensation window; This represents a string concatenation operator; This indicates the current block to be translated.

[0032] In step S4, the thread pool concurrently schedules a third-party translation engine to perform translation actions on the input sequence to be translated, generating corresponding translation blocks. The structural reconstruction engine performs identification and removal actions on the translation blocks to remove redundant translation content generated by the semantic compensation window, generating clean translation content. Based on the task metadata extracted from the task snapshot data, the structural reconstruction engine backfills the clean translation content into the corresponding position of the original response body template in situ, assembling and generating the translated response body.

[0033] In step S5, the exponential backoff retry mechanism performs a retry action on the damaged input sequence to be translated when an anomaly occurs in the translation call chain, ensuring the integrity of the translated response body. After the task is completed, the callback polling module uses the global request serial number to match the stored translated response body and delivers the translated response body to the caller by executing a push or response action.

[0034] See appendix Figure 2 The technical details of response entity metadata modeling and path identification in step S1 are described below:

[0035] In S110, the tree path encoder uses reflection to scan the response entity class structure to accurately identify the marked fields to be translated. The tree path encoder obtains the description information of the target response entity class, recursively traverses the member variables of the class and all its nested subclasses, and checks whether a pre-defined custom meta-annotation exists on each member variable.

[0036] When the tree path encoder locates a member variable configured with the custom meta-annotation, it identifies it as the field to be translated and simultaneously extracts the field name, class name, and data type. The specific program logic for obtaining class member attributes and their annotation information via reflection can be implemented using the reflection library built into the programming language by those skilled in the art. The specific underlying implementation scheme is well-known in the field and will not be elaborated upon here.

[0037] In S120, the tree path encoder performs a recursive parsing operation on the fields to be translated identified in step S110 to determine the logical hierarchical path of the field to be translated in the nested JSON structure. Starting from the root node of the response entity class structure, the tree path encoder traces downwards along the object reference chain, recording the hierarchical key names or array indices traversed to reach each field to be translated.

[0038] The tree-structured path encoder performs branching decisions based on the data type of the current node: if the current node is an object, the key name string is recorded as a vector component; if the current node is a set or array, the integer index of the current element is recorded as a vector component. The tree-structured path encoder then converts these recorded hierarchical key names or array indices into corresponding path vectors according to the path encoding formula, generating task metadata containing structural location index information.

[0039] The path encoding formula is as follows:

[0040] ;

[0041] In the formula: Indicates the field to be translated Path vector; Indicates the first Hierarchical key name or array index; Indicates the field to be translated Nesting depth.

[0042] The tree-based path encoder uses the aforementioned path encoding formula to vectorize the logical position of the field to be translated within a complex data tree. When the field to be translated is in a list data structure, the corresponding component in the path vector... It will automatically record the specific index value of this field in the array.

[0043] The task metadata generated in this way provides precise navigation coordinates for subsequent asynchronous processing, enabling the translated content after chunking to be located in situ within the original response template based on these coordinates. The generated task metadata is passed to the subsequent asynchronous task encapsulation stage, serving as the core retrieval identifier for structured reconstruction.

[0044] The technical details of the asynchronous task identifier and context snapshot initialization in step S2 are described below:

[0045] In S210, the identifier generator performs a generation action on the received API request, generating a unique global request serial number. The identifier generator employs a distributed unique ID generation algorithm to ensure that this global request serial number does not conflict in a multi-machine deployment environment. This global request serial number serves as the core key value linking the front-end request and the back-end processing result, and persists throughout the entire translation lifecycle. Regarding the specific algorithm used by the identifier generator, such as the Snowflake algorithm or a globally unique identifier generation strategy, those skilled in the art can choose according to concurrency requirements; its implementation principles are well-known technologies in the field and will not be elaborated upon here.

[0046] In S220, the serializer performs an associated encapsulation action on the task metadata generated in step S1, the original request parameters of the external input, the original response body template of the external input, and the target language preference of the external input to construct persistent task snapshot data.

[0047] In practice, the serializer obtains the task metadata containing the path vector generated in step S1 through a preset interface protocol, and simultaneously retrieves the original request parameters, the original response body template, and the user-specified target language preference from the current request context. The serializer uses reflection or introspection mechanisms to map the above multidimensional heterogeneous data to a unified context entity class. Subsequently, the serializer uses a preset serialization algorithm to transform the logical objects contained in the context entity class into a binary stream of a unified format or a structured message containing a specific pattern.

[0048] The task snapshot data fully encapsulates all the contextual information required by the translation task during execution. Because the serializer transforms this information into a standardized data format, the generated task snapshot data can be stably transmitted between different computing nodes in the distributed system via message queues. By storing the task snapshot data in an external distributed cache or persistent database and establishing a unique mapping between it and the global request serial number, the system can ensure that even when the background asynchronous processing cluster is completely detached from the original API call environment, it can still recover the hierarchical coordinates and complete business parameters of the fields to be translated through deserialization. This mechanism ensures the integrity and consistency of data during cross-process or cross-network transmission in the asynchronous processing chain.

[0049] Regarding the serialization algorithm used by the serializer, those skilled in the art can choose JSON serialization scheme, XML serialization scheme, or binary serialization scheme such as Protobuf or Hessian according to the system's requirements for throughput and message size. The specific encoding and decoding implementations are well-known technologies in this field and will not be elaborated here.

[0050] In S230, the message queue receives and distributes a task carrier containing the task snapshot data to activate the asynchronous translation task. Through the decoupling mechanism of the message queue, the interface service layer can immediately return a global request sequence number to the caller after successfully submitting the asynchronous translation task, without waiting for the time-consuming translation process to complete. The message queue distributes the asynchronous translation task to the nodes to be processed based on the system load, and the backend cluster performs subsequent processing based on the target language preferences and field information recorded in the task snapshot data. Regarding the middleware selection and asynchronous distribution logic of the message queue, those skilled in the art can adopt mature open-source solutions based on system throughput requirements; their deployment and maintenance are well-known technologies in the field and will not be elaborated upon here.

[0051] Through the above steps, the system establishes a linkage between request identifiers, environment snapshots, and asynchronous execution. The global request serial number not only serves as a unique identifier for the task but also establishes a strong mapping with the task snapshot data at the storage layer. This mechanism ensures that, in a complex distributed environment, each field to be processed can remain synchronized with its corresponding request context, providing a data foundation for content extraction in subsequent step S3 and in-situ backfilling in step S4.

[0052] See appendix Figure 1 The technical details of the intelligent block preprocessing based on semantic compensation window in step S3 are described below:

[0053] In step S310, the regular expression cleaner extracts the original content of the fields from the task snapshot data carried by the asynchronous translation task distributed in step S2, and performs interference symbol removal to generate normalized cleaned text. The regular expression cleaner extracts the text strings corresponding to the fields to be translated by performing deserialization parsing on the task snapshot data.

[0054] The regular expression cleaner invokes a pre-defined set of filtering rules, using regular expressions to match and remove escape characters, HTML tags, and specific control characters from the original content of the field, preventing these non-semantic symbols from interfering with the subsequent recognition by the translation engine. Regarding the matching and replacement logic of regular expressions in string cleaning, those skilled in the art can write corresponding matching expressions based on the format characteristics of the content to be processed; the execution process is well-known in the field and will not be elaborated upon here.

[0055] In S320, the semantic compensation extraction algorithm performs logical truncation on the cleaned text to divide it into blocks to be translated, and then applies the semantic compensation window at the end of the preceding blocks according to the semantic compensation formula. Perform a concatenation operation with the current block to generate a coherent input sequence to be translated.

[0056] The semantic compensation extraction algorithm first compares the length of the cleaned text with the single request length threshold of the third-party translation engine. When the length of the cleaned text exceeds the threshold, the algorithm searches backward from the length threshold for the nearest text terminator. This text terminator includes, but is not limited to, a period, a question mark, an exclamation mark, or a semicolon. By locating the position determined by the text terminator as the truncation point, the cleaned text is split into multiple blocks to be translated.

[0057] After the blocks to be translated are split, the semantic compensation extraction algorithm extracts a character segment of a preset length from the end of the previous block and uses it as a semantic compensation window. The semantic compensation extraction algorithm will use this semantic compensation window. The sequence is spliced ​​to the beginning of the current block to be translated, thus constructing an input sequence to be translated that contains the preceding context information.

[0058] The semantic compensation formula is as follows:

[0059] ;

[0060] In the formula: Indicates the first One input sequence to be translated; This represents a semantic truncation function, used to extract a specific length of characters from the end of a specified text. This indicates the previous block to be translated; Indicates the length of the semantic compensation window; This represents a string concatenation operator; This indicates the current block to be translated.

[0061] The input sequence to be translated generated by the semantic compensation formula described above ensures that each truncated text block carries the ending context of the preceding text when sent to a third-party translation engine. This approach effectively solves the semantic deviation problem caused by missing context when machine translation processes long text blocks.

[0062] In the processing of the first segment to be translated, since there is no preceding text, its corresponding semantic compensation window... The value is an empty string. The final generated input sequence to be translated is encapsulated as a translation request object and passed to the subsequent parallel call process.

[0063] The technical details of parallel translation scheduling and structured in-situ backfilling in step S4 are described below:

[0064] In step S410, the thread pool concurrently schedules the third-party translation engine to perform translation actions on the input sequences to be translated generated in step S3, generating corresponding translation blocks. The thread pool allocates multiple input sequences to different worker threads according to a preset concurrency threshold, and obtains the translation results corresponding to each block by concurrently calling the API interface of the third-party translation engine.

[0065] To address the concurrency frequency limitations of third-party translation engines, the thread pool integrates flow control logic to ensure that the request frequency remains within the interface's allowable range. For thread pool initialization, task queue management, and thread synchronization mechanisms, those skilled in the art can utilize built-in concurrency toolkits in programming languages; the specific scheduling principles are well-known in the field and will not be elaborated upon here.

[0066] In S420, the structural reconstruction engine performs identification and removal operations on the translated text blocks obtained in step S410 to remove redundant translated content introduced by splicing, generating clean translated content. This is because the input sequence to be translated... Includes the semantic compensation window at the end of the previous block to be translated. The resulting translated text chunks will contain a section of text that overlaps with the preceding translated text.

[0067] The structural reconstruction engine extracts the corresponding semantic compensation window from the current translation block. The engine translates the fragment and aligns it with the ending text of the previous translated segment. When the two have the same meaning or highly overlap, the structural reconstruction engine performs a string pruning operation, removing the overlapping part of the current translated segment's header and retaining only the corresponding original segment. The translation results.

[0068] After redundancy removal is completed, the structure reconstruction engine extracts task metadata from the task snapshot data persisted in step S2 and obtains the tree path encoding. The structural reconstruction engine uses the generated clean translation content as the input value, and then performs an in-situ backfilling operation on the original response body template based on the hierarchical coordinates determined by the path encoding formula given above. The path encoding formula is as follows:

[0069] ;

[0070] In the formula: Indicates the field to be translated Path vector; Indicates the first Hierarchical key name or array index; Indicates the field to be translated Nesting depth.

[0071] In the specific implementation of in-situ backfilling, the structural reconstruction engine parses each element in the path vector. The target nodes in the original response body template are addressed recursively in sequence.

[0072] If the key is a name, it will locate the corresponding object property;

[0073] like If it is an array index, it will locate a specific element in the collection.

[0074] When addressing reaches depth At the corresponding endpoint node, the structure reconstruction engine replaces the original text of that node with the processed, clean translation. By traversing all the fields to be translated involved in the asynchronous translation task and repeating the above backfilling action, the discrete translation blocks are finally assembled into a structurally complete translated response body.

[0075] The technical details of the dual-track delivery and fault tolerance handling in step S5 are described below:

[0076] In S510, the exponential backoff retry mechanism performs retry actions on the damaged input sequence to be translated when an anomaly occurs in the translation call chain, to ensure the generation of the translated response body. When the thread pool in step S410 receives abnormal feedback such as network timeout, interface frequency limit, or server error during the call to the third-party translation engine, the exponential backoff retry mechanism will capture the corresponding input sequence to be translated and redeliver it according to the preset retry strategy.

[0077] The exponential backoff retry mechanism reduces the instantaneous impact on third-party translation engines by progressively increasing the time interval between two attempts. If the input sequence to be translated still cannot obtain a translation result after reaching the preset maximum number of retries, the exponential backoff retry mechanism triggers the fallback protection logic, directly filling in the original text of the corresponding block to be translated as the translation result, ensuring that the overall structure of the translated response is not abnormally interrupted due to partial translation failure.

[0078] In S520, after the task processing is completed, the callback polling module uses the global request serial number generated in step S220 to match the stored translated response body, and delivers it to the caller by executing a push or response action. The callback polling module monitors the translation status bits corresponding to the task snapshot data in real time, and after confirming that the translated response body has been assembled, it retrieves the complete translated response body from the persistent cache.

[0079] In this delivery process, the callback polling module employs a dual-track delivery strategy that combines callbacks and polling. For callers that support the callback protocol, the callback polling module proactively sends a notification request containing a global request serial number and a translated response body to the caller by parsing the callback address information reserved in the original request parameters.

[0080] If the caller does not support callbacks or the callback link communication fails, the callback polling module maintains the storage state of the translated response body in the cache. In this case, the caller can actively call the query result interface and pass in the global request serial number. The callback polling module locates the corresponding translated response body in the database based on the received global request serial number and returns it as the interface response content.

[0081] Through the aforementioned exception handling and delivery mechanisms, this invention can flexibly adapt to the interaction needs of different callers while ensuring high availability of API services. The exponential backoff retry mechanism effectively mitigates the risk of task failure caused by fluctuations in third-party translation engines through differentiated delayed retry strategies, while the dual-track mechanism of the callback polling module ensures deterministic delivery of translated responses in complex network environments. The entire processing flow uses the global request sequence number as an index, realizing a closed-loop information flow from request initiation and asynchronous translation to final result acquisition.

[0082] The embodiments of this invention employ a tree-based path encoder to perform deep parsing of the response entity class structure, utilizing the generated task metadata as core coordinate anchors to solve the positioning accuracy problem of in-situ data backfilling in complex JSON nested structures. The collaborative mechanism established by the semantic compensation extraction algorithm and the structural reconstruction engine, by introducing a semantic compensation window to compensate for the contextual loss generated during logical truncation of text, combined with subsequent identification and removal actions performed on translated text blocks, achieves logical alignment of the clean translated content.

[0083] An asynchronous processing system built using an identifier generator, task snapshot data, and a message queue transforms the originally time-consuming translation process into a highly available asynchronous translation task. A deterministic association between frontend requests and backend-stored translated response bodies is achieved using a global request serial number. An exponential backoff retry mechanism, executing retries when fluctuations occur in the translation call chain, further ensures the success rate of generating translated response bodies. A callback polling module provides a dual-track delivery mechanism, ensuring the system can flexibly deliver data based on the external calling environment.

[0084] This invention, without altering the original API definition, systematically addresses the timeout risk and semantic deviation issues in API translation scenarios by performing precise identification of the content to be translated, semantically coherent segmentation, and structured in-situ reconstruction. This is achieved from two dimensions: metadata management and semantic fidelity. The components are tightly coupled through global request serial numbers and task snapshot data, ensuring a closed-loop information flow from request initiation to delivery of the translated response body. This guarantees the overall stability of the API service in multilingual environments and the accuracy of the translated response content.

Claims

1. A method for accurate translation and asynchronous chunking of API response body content, characterized in that, Includes the following steps: S1. The tree-shaped path encoder uses a reflection mechanism to scan the response entity class structure and identify the fields to be translated, and generates task metadata containing the path vectors of the fields to be translated in the JSON nested structure according to the path encoding formula. S2. The identifier generator generates a global request serial number for the API request. The serializer encapsulates the task metadata, original request parameters, original response body template and target language preference into task snapshot data, which is then distributed by the message queue to activate the asynchronous translation task. S3. The regular expression cleaner extracts the original content of the fields from the task snapshot data and generates cleaned text. The semantic compensation extraction algorithm performs logical truncation on the cleaned text to divide it into blocks to be translated and generates a semantic compensation window. The semantic compensation window and the blocks to be translated are concatenated according to the semantic compensation formula to generate the input sequence to be translated. S4. The thread pool concurrently schedules a third-party translation engine to translate the input sequence to be translated and obtain translation blocks. The structure reconstruction engine removes redundant translation content from the translation blocks and generates clean translation content. Based on the task metadata, the clean translation content is backfilled into the original response body template to assemble and generate the translated response body. S5. The exponential backoff retryer retryes the input sequence to be translated when the translation call fails. After the task is completed, the callback polling module uses the global request serial number to match the translated response body and deliver it to the caller.

2. The method for accurate translation and asynchronous chunking of API response body content according to claim 1, characterized in that, In step S1, the tree path encoder identifies the field to be translated, specifically including: The tree path encoder obtains the description information of the target response entity class from external input, and recursively traverses the member variables in the response entity class structure and its nested subclasses. Search for whether a custom meta-annotation exists on the member variable. When the member variable configured with the custom meta-annotation is located, it is identified as the field to be translated. The custom meta-annotation is pre-defined based on the identification requirements of the content to be translated in the response entity class structure.

3. The method for accurate translation and asynchronous chunking of API response body content according to claim 2, characterized in that, In step S1, the tree path encoder generates task metadata including: The tree path encoder starts from the root node of the response entity class structure, traces down the object reference chain and records the level key names or array indices traversed to reach the field to be translated; Based on the path encoding formula, the recorded hierarchical key name or array index is converted into the corresponding path vector, and the task metadata containing the path vector is constructed. The path vector represents the logical path depth and sibling index position of the field to be translated in the nested JSON structure.

4. The method for accurate translation and asynchronous chunking of API response body content according to claim 1, characterized in that, The S2 step specifically includes: The identifier generator uses a distributed unique ID generation algorithm to generate the global request serial number for the externally input API request; The serializer associates, encapsulates, and persists the task metadata, the externally input original request parameters, the externally input original response template, and the externally input target language preference to generate the task snapshot data. The message queue receives and distributes the asynchronous translation task containing the task snapshot data.

5. The method for accurate translation and asynchronous chunking of API response body content according to claim 1, characterized in that, In step S3, generating the cleaned text specifically includes: The regular expression cleaner extracts the original content of the field, calls a preset rule set, and uses regular expressions to match and remove escape characters and control characters in the original content of the field to generate the cleaned text. The preset rule set is pre-defined based on the format characteristics and non-semantic symbol types of the original content of the field.

6. The method for accurate translation and asynchronous chunking of API response body content according to claim 1, characterized in that, In step S3, generating the input sequence to be translated specifically includes: The semantic compensation extraction algorithm compares the length of the cleaned text with the length threshold of the third-party translation engine. When the length of the cleaned text exceeds the length threshold, it searches forward within the length threshold range for the nearest text terminator as a cutoff point to divide the block to be translated. The semantic compensation extraction algorithm extracts a character segment of a predetermined length from the end of the previous block to be translated as the semantic compensation window; The semantic compensation window is concatenated to the starting position of the current block to be translated according to the semantic compensation formula to generate the input sequence to be translated; The length threshold is preset based on the maximum character limit for a single request of the third-party translation engine.

7. The method for accurate translation and asynchronous chunking of API response body content according to claim 6, characterized in that, In step S3, performing the logical truncation further includes: If the semantic compensation extraction algorithm does not find the text terminator within the length threshold range, it forces a hard truncation according to the length threshold to produce the block to be translated.

8. The method for accurate translation and asynchronous chunking of API response body content according to claim 1, characterized in that, In step S4, generating the clean translation specifically includes: The thread pool distributes multiple input sequences to be translated to different worker threads and concurrently calls the third-party translation engine to obtain the translated text blocks; The structural reconstruction engine extracts the translation fragments corresponding to the semantic compensation window in the translation block, aligns and matches them with the end text of the preceding translation block, identifies and trims duplicate content to generate the clean translation content.

9. The method for accurate translation and asynchronous chunking of API response body content according to claim 1, characterized in that, In step S4, assembling and generating the translated response body specifically includes: The structural reconstruction engine parses each level element in the path vector and recursively addresses the target node in the original response body template; The original text of the target node is replaced with the clean translation content. After all the fields to be translated involved in the asynchronous translation task have been replaced, the translated response body is assembled and generated.

10. The method for accurate translation and asynchronous chunking of API response body content according to claim 1, characterized in that, The S5 step specifically includes: When the exponential backoff retry mechanism detects a call anomaly, it reissues the input sequence to be translated according to a strategy of successively increasing the time interval. If the number of retries reaches the maximum retry threshold and still fails, the original text of the block to be translated will be filled in as the translation result to perform fallback protection. The callback polling module adopts a dual-track delivery strategy of active push and passive query response, and delivers the translated response body stored according to the global request serial number; The maximum number of retries threshold is preset based on fault tolerance requirements.