Translation method and device for response data of application programming interface and electronic equipment

By automating the identification and classification of translation fields, the problem of low efficiency in the translation of application programming interface response data is solved, achieving an efficient and accurate translation process.

CN121543601APending Publication Date: 2026-02-17GRG BANKING IT
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511709821.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-20
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

In existing technologies, the translation of application programming interface response data involves a large amount of repetitive coding work, resulting in low development efficiency and difficulty in guaranteeing translation accuracy.

Method used

By intercepting API response data, we automatically identify fields to be translated using custom annotations, encapsulate them as entities to be translated, categorize them into entity lists according to translation type, execute matching translation strategies, and finally update the response data.

Benefits of technology

It decouples translation logic from business logic, reduces redundant development work, improves translation accuracy and efficiency, and solves the performance bottleneck of traditional field-by-field queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121543601A_ABST
    Figure CN121543601A_ABST
Patent Text Reader

Abstract

The invention discloses a translation method and device for application programming interface response data and electronic equipment, and belongs to the technical field of computers. The method comprises the following steps: intercepting response data of an application programming interface to be returned, and determining a field to be translated in the response data and a translation type corresponding to the field to be translated; packaging the to-be-translated field into a to-be-translated entity according to a translation type corresponding to the to-be-translated field, and writing the to-be-translated entity into an entity list corresponding to the translation type; for the entity list in which the to-be-translated entities are written, executing a translation strategy matched with the translation type corresponding to the entity list to obtain a translation result of each to-be-translated field; and updating the response data according to each translation result to obtain translated response data. According to the method and the device, the quality of translating the response data of the application programming interface is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of computer technology, and in particular relates to a method, apparatus and electronic device for translating application programming interface response data. Background Technology

[0002] Backend databases typically store constant IDs or non-text data, while the user's front-end interface displays the corresponding text values ​​or detailed text descriptions. Related technologies commonly employ hard-coding for manual translation, requiring repeated writing of translation code at each data display interface to convert data from its stored form to its displayed form. As business grows and the number of interfaces increases, this repetitive coding work increases developers' workload, reduces development efficiency, and makes it difficult to guarantee translation accuracy during manual coding due to potential differences in translation logic styles and approaches among developers. Summary of the Invention

[0003] This application aims to address at least one of the technical problems existing in the related art. To this end, this application proposes a method, apparatus, and electronic device for translating application programming interface (API) response data, thereby improving the quality of translating API response data.

[0004] In a first aspect, this application provides a method for translating application programming interface response data, the method comprising: Intercept the response data of the application programming interface to be returned, and determine the fields to be translated in the response data and the translation type corresponding to the fields to be translated; Based on the translation type corresponding to the field to be translated, the field to be translated is encapsulated into an entity to be translated and written into the entity list corresponding to the translation type; For the entity list written to the entities to be translated, execute the translation strategy that matches the translation type corresponding to the entity list to obtain the translation result of each of the fields to be translated; The response data is updated based on the translation results to obtain the translation-complete response data.

[0005] In the above technical solution, by intercepting the API response data to be returned and automatically identifying the fields to be translated using custom annotations, the manual writing of translation logic in each interface can be avoided. This automated process not only decouples the translation logic from the business logic but also significantly reduces repetitive development work and improves development efficiency. Subsequently, based on the translation type corresponding to the field to be translated, the field to be translated is encapsulated into an entity to be translated and written into an entity list corresponding to the translation type. The entity to be translated serves as an intermediate carrier, allowing the translation strategy to focus only on the conversion of the value to be translated without needing to consider other information of the field to be translated. The entities to be translated are classified into entity lists according to translation type, and a translation strategy matching its translation type is executed for each entity list. This classification and matching mechanism ensures the accuracy and efficiency of the translation process, avoids the mixing of different types of translation logic during the translation process, and reduces the inefficiency and high error rate caused by manually setting translation logic, thereby improving the quality of translating application programming interface response data.

[0006] According to some embodiments of this application, the step of executing a translation strategy that matches the translation type corresponding to the entity list to obtain the translation results for each of the fields to be translated includes: Obtain feature information for each entity to be translated in the entity list, wherein the structure of the feature information is determined based on the translation type; Based on the feature information, each entity to be translated is divided into at least one entity group, and the feature information of each entity to be translated in the entity group is the same. For each entity group, a translation mapping relationship corresponding to the entity group is obtained based on the feature information of the entity to be translated in the entity group. The translation result of the fields to be translated for each entity to be translated is determined based on the translation mapping relationship.

[0007] In the above technical solution, by obtaining the feature information of each entity to be translated in the entity list, and dividing each entity to be translated into at least one entity group based on the feature information, the feature information of each entity to be translated in the entity group is the same. The traditional method of querying the database or cache field by field once will generate a large number of input and output operations, which slows down the response speed of the application programming interface. However, by dividing the entity into entity groups with the same feature information and performing only one query on the entity group to obtain the translation mapping relationship, the number of calls to data sources such as databases or external services can be greatly reduced. This helps to solve the performance bottleneck of traditional field-by-field single query, improves the performance of the application programming interface, and thus improves the efficiency of translating the response data of the application programming interface.

[0008] Secondly, this application provides a device for translating application programming interface response data, the device comprising: The determination module is used to intercept the response data of the application programming interface to be returned, and to determine the fields to be translated in the response data and the translation type corresponding to the fields to be translated. The encapsulation module is used to encapsulate each field to be translated into a translation entity according to the translation type corresponding to the field to be translated and write it into an entity list corresponding to the translation type. The translation module is used to execute a translation strategy that matches the translation type corresponding to each of the entity lists to obtain the translation result of each of the fields to be translated. The update module is used to update the response data according to each of the translation results to obtain the translation-completed response data.

[0009] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method for translating application programming interface response data as described in the first aspect above.

[0010] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method for translating application programming interface response data as described in the first aspect above.

[0011] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the application programming interface response data translation method as described in the first aspect.

[0012] In a sixth aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method for translating application programming interface response data as described in the first aspect above.

[0013] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0014] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating a method for translating application programming interface response data provided in some embodiments of this application; Figure 2 This is a schematic diagram of the structure of a translation device for application programming interface response data provided in some embodiments of this application; Figure 3 These are schematic diagrams of the structure of electronic devices provided in some embodiments of this application. Detailed Implementation

[0015] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0016] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0017] The following description, in conjunction with the accompanying drawings, details the method, apparatus, and electronic device for translating application programming interface response data provided in this application through specific embodiments and application scenarios.

[0018] The method for translating application programming interface response data can be applied to the terminal, and can be executed by the hardware or software in the terminal.

[0019] The method for translating application programming interface (API) response data provided in this application embodiment can be executed by an electronic device or a functional module or entity within an electronic device that can implement the method for translating API response data. The electronic devices mentioned in this application embodiment include, but are not limited to, backend servers and cloud servers. The following description uses an electronic device as the execution subject to illustrate the method for translating API response data provided in this application embodiment.

[0020] Figure 1 This is a flowchart illustrating a method for translating application programming interface response data provided in some embodiments of this application. For example... Figure 1 As shown, the method for translating the application programming interface response data includes steps 110, 120, 130, and 140.

[0021] Step 110: Intercept the response data of the application programming interface to be returned, and determine the fields to be translated in the response data and the translation type corresponding to the fields to be translated.

[0022] Understandably, in a distributed architecture, the method for translating application programming interface (API) response data is typically applied to the backend or backend server to intercept the API response data returned to the frontend (such as the client or application).

[0023] Application Programming Interface (API) response data is typically in the form of key-value pairs or nested tags, and can include multi-level nested objects and arrays. Some fields (such as codes or enumeration values) may not be directly displayed on the front end, so they need to be translated and converted.

[0024] In some embodiments, the interception of the response data from the application programming interface to be returned includes: Intercept the response data of the application programming interface that is about to be returned by AOP aspects.

[0025] For example, a global response handler, GlobalTransHandler, is introduced to intercept response data from application programming interfaces (APIs). This global response handler is implemented based on Spring's Aspect-Oriented Programming (AOP) mechanism. By implementing the `beforeBodyWrite` method of the `ResponseBodyAdvice` interface, it performs unified processing on the response body (response data) before it is returned to the front end, and uses `@RestControllerAdvice` to globally intercept the return values ​​of all `@RestController` methods. This design helps replace the redundant pattern of manually writing translation logic for each interface in traditional methods, decoupling translation logic from business logic. Developers do not need to manually call translation methods, which helps improve development efficiency and code maintainability.

[0026] The process involves determining the fields to be translated in the response data and their corresponding translation types. For example, this can be achieved by identifying fields using custom annotations marked on them, and then dynamically parsing the field types and annotation attributes / metadata of the custom annotations using reflection to distinguish between fields requiring translation (e.g., enumeration types, dictionary-encoded types) and fields that do not require processing. In some embodiments, dynamic rules (e.g., regular expressions matching field names) or context-awareness (e.g., processing only classes under specific package paths) can also be used to determine the fields to be translated in the response data.

[0027] Step 120: Based on the translation type corresponding to the field to be translated, encapsulate the field to be translated into a translation entity and write it into the entity list corresponding to the translation type.

[0028] Translation types can be considered as logical classifications of how data to be translated is transformed into corresponding translation results. Translation types provide a rule-based processing framework for data translation in different scenarios. Each translation type corresponds to a specific set of rules that need to be followed during the translation process, including data source, parsing method, and result format.

[0029] Specifically, each translation type can be associated with different data sources (such as in-memory dictionaries, database tables, enumeration classes, external APIs, etc.), and each translation type corresponds to independent translation logic (such as dictionary key-value matching, enumeration annotation parsing, SQL join queries, etc.). Translation types can include dictionary types, enumeration types, and database table types, and support extensions for other custom translation types.

[0030] Understandably, the field to be translated is encapsulated into a translation entity based on the translation type corresponding to the field to be translated. The translation entity can be considered as an intermediate carrier in the translation process. During the encapsulation process, only the relevant information required for translation is retained, so that the translation strategy can focus only on the transformation of the value to be translated, without having to pay attention to other information such as the original position of the field to be translated.

[0031] For example, in some embodiments, when the translation type corresponding to the field to be translated is dictionary translation, the field to be translated is encapsulated into a translation entity, including: encapsulating the translation entity based on the dictionary encoding corresponding to the field to be translated, the value of the field to be translated, and a container for storing the translation result of the field to be translated, wherein the dictionary encoding is used to identify the dictionary in the data source.

[0032] In some embodiments, the entity to be translated may also include the path of the field to be translated in the response data and a reference to its parent object. By recording the complete path of the field to be translated in the entity to be translated, the translation result can be accurately backfilled into the response data according to the path, so as to perform subsequent update steps on the response data.

[0033] Step 130: For the entity list after writing the entities to be translated, execute the translation strategy that matches the translation type corresponding to the entity list to obtain the translation result of each of the fields to be translated.

[0034] It is understandable that the entities to be translated are written into entity lists corresponding to the translation type, that is, the entities to be translated are classified into multiple entity lists according to the translation type, and the translation types of the entities to be translated in the same entity list are the same.

[0035] By implementing a dedicated translation strategy that precisely matches the translation type for the entity list, logical isolation between different translation types can be achieved, improving code obfuscation and redundancy between different translation types. This helps avoid translation errors or performance losses caused by type mixing. Furthermore, each translation type has a corresponding translation strategy, which can ensure that the translation logic is adapted to the characteristics of the field to be translated.

[0036] Understandably, the translation operations are centralized in the implementation class corresponding to the translation strategy, decoupled from the business logic. When a new translation type needs to be added, only the new translation strategy class needs to be implemented, without modifying other business logic classes. This adheres to the open / closed principle, improves adaptability to different translation types, and makes the translation process more flexible and scalable. By executing translation strategies that match the translation type, the accuracy of the translation results for each field can also be improved.

[0037] Step 140: Update the response data according to each of the translation results to obtain the translation completed response data.

[0038] In some embodiments, where the entity to be translated of the field to be translated encapsulates a container for storing the translation result of the field to be translated, the method further includes: Update the entity corresponding to each field to be translated based on the translation result of each field to be translated.

[0039] In some embodiments, where the path of the field to be translated in the response data is encapsulated in the entity to be translated of the field to be translated, updating the response data according to each of the translation results includes: Based on the path of the field to be translated in the entity to be translated in the response data, the translation result of the field to be translated is written into the response data.

[0040] In some embodiments, the object corresponding to the field to be translated has a container field for storing translation results, and updating the response data according to each of the translation results includes: The translation result of the field to be translated is filled into the container field of the object corresponding to the field to be translated.

[0041] Here's a specific example: The original response data is "{"username": "test", "status":1}", and the translated response data is "{"username": "test", "status": 1,"transResultMap": {"status_trans": "Enabled"}}". The frontend can directly use `status_trans` to display it without needing to handle encoding mapping.

[0042] The method for translating API response data provided in this application intercepts the API response data to be returned and automatically identifies the fields to be translated using custom annotations, avoiding the need to manually write translation logic in each interface. This automated process not only decouples translation logic from business logic but also significantly reduces repetitive development work and improves development efficiency. Subsequently, based on the translation type corresponding to the field to be translated, the field to be translated is encapsulated into an entity to be translated and written into an entity list corresponding to the translation type. The entity to be translated serves as an intermediate carrier, allowing the translation strategy to focus only on the conversion of the value to be translated without needing to consider other information of the field to be translated. The entities to be translated are classified into entity lists according to translation type, and a translation strategy matching its translation type is executed for each entity list. This classification and matching mechanism ensures the accuracy and efficiency of the translation process, avoids the mixing of different types of translation logic during the translation process, and reduces the inefficiency and high error rate caused by manually setting translation logic, thereby improving the quality of translating API response data.

[0043] In some embodiments of this application, the step of executing a translation strategy that matches the translation type corresponding to the entity list to obtain the translation results for each of the fields to be translated includes: Obtain feature information for each entity to be translated in the entity list, wherein the structure of the feature information is determined based on the translation type; Based on the feature information, each entity to be translated is divided into at least one entity group, and the feature information of each entity to be translated in the entity group is the same. For each entity group, a translation mapping relationship corresponding to the entity group is obtained based on the feature information of the entity to be translated in the entity group. The translation result of the fields to be translated for each entity to be translated is determined based on the translation mapping relationship.

[0044] Feature information can be considered as a set of attributes related to the entity to be translated or the corresponding field to be translated, used to describe the specific translation requirements of the entity to be translated. It can be understood that all entities to be translated in the same entity list have the same translation type, and the translation type of the entity list is the same as the translation type of the entities to be translated in the list.

[0045] For example, if the translation type is a dictionary, the feature information can include the dictionary table name corresponding to the entity to be translated, the field name corresponding to the field to be translated, and the field name corresponding to the translation result of the field to be translated. Based on this structural feature information, the translation mapping relationship between the field to be translated in the dictionary table and the field corresponding to the translation result in the dictionary table can be identified from the data source. In the current example, the translation mapping relationship should include multiple sets of mapping relationships between the fields to be translated and the translation results, so that the translation result can be found based on the translation mapping relationship in the future. Similarly, if the translation type is an enumeration type or other types, the translation mapping relationship can also be determined based on the feature information structure that matches the translation type.

[0046] By dividing the entities to be translated into at least one entity group based on feature information, fields with the same translation requirements can be quickly identified in the entity list. These fields can then be processed in batches. In other words, operating on an entity group basis, the translation mapping relationship for each entity within a group can be obtained with a single query based on feature information. Subsequent translations are then based directly on this single query's mapping relationship to determine the translation results for each entity. Since the feature information of all translated entities is the same, the obtained translation mapping relationships are also identical. This batch processing operation reduces the number of calls to databases or external services, thereby reducing repetitive operations and improving response speed.

[0047] For example, when the entity list is translated as a dictionary, the dictionary codes corresponding to the entities to be translated can be used as feature information. These codes can be combined into batch query parameters, allowing a single query to retrieve all key-value pairs, thus reducing the number of queries from N to 1, significantly lowering the query load during translation. As another example, when the translation type is an enumeration, the translation strategy can use reflection to batch read the annotation values ​​of the enumeration class, avoiding the need to instantiate each enumeration object individually, reducing memory overhead and the number of reflection calls.

[0048] The method for translating application programming interface (API) response data provided in this application obtains the feature information of each entity to be translated in the entity list and divides each entity to be translated into at least one entity group based on the feature information. The feature information of each entity to be translated in the entity group is the same. The traditional method of querying the database or cache field by field once will generate a large number of input and output operations, which slows down the response speed of the API. However, by dividing the entity into entity groups with the same feature information and performing a query only once on the entity group to obtain the translation mapping relationship, the number of calls to data sources such as databases or external services can be greatly reduced. This helps to solve the performance bottleneck of the traditional field-by-field query, improves the performance of the API, and thus improves the efficiency of translating API response data.

[0049] In some embodiments of this application, the translation type includes at least one of dictionary type, enumeration type, and database table type; obtaining the feature information of each entity to be translated in the entity list includes: When the translation type is dictionary type, the dictionary code corresponding to the entity to be translated is used as the feature information of the entity to be translated, and the dictionary code is used to identify the dictionary in the data source; When the translation type is an enumeration type, the feature information of the entity to be translated is composed of the enumeration name, source field name and target field name corresponding to the entity to be translated. The enumeration name is used to identify the enumeration class in the data source, the source field name is used to specify the field corresponding to the field to be translated in the enumeration class, and the target field name is used to specify the field corresponding to the translation result of the field to be translated in the enumeration class. When the translation type is a database table type, the feature information of the entity to be translated is composed of the database table name, source field name, and target field name corresponding to the entity to be translated. The database table name is used to identify the database table in the data source, the source field name is used to specify the field corresponding to the field to be translated in the database table, and the target field name is used to specify the field corresponding to the translation result of the field to be translated in the database table.

[0050] In this embodiment, the translation type may include dictionary type, enumeration type, and database table type, and supports extensions to other custom types. For example, the translation type may also be a cache type or configuration file type, etc. When the translation type is a cache type, the feature information of the entity to be translated is composed of the cache name, source field name, and target field name corresponding to the entity to be translated.

[0051] Understandably, dictionary types refer to types translated through a predefined dictionary (key-value pairs), which are typically stored in memory or a database; enumeration types refer to types translated through Java enumeration classes, where each instance has a unique value and a corresponding text description, and annotation values ​​or method return values ​​of the enumeration class can be obtained through reflection; database table types refer to types translated through database tables, with the translation results obtained from a predefined database table, typically through SQL queries.

[0052] Understandably, the process of obtaining the feature information of each entity to be translated in the instance list is determined by the translation type. Specifically, when the translation type is dictionary-based, the feature information of the entities to be translated is directly encoded using dictionary encoding. Dictionary encoding, as a single feature, can reduce the complexity of feature combination and is used for fast querying of static text.

[0053] When the translation type is an enumeration type, the feature information consists of three parts: enumeration name, source field name, and target field name. The enumeration name is located to the specific enumeration class, the source field name is located to the enumeration constant, and the target field name is located to the translation result field. The combination of the three can avoid ambiguity between fields with the same name in different enumerations, while the target field name can flexibly specify the storage location of the translation result and adapt to the field naming conventions of different languages. When the translation type is a database table, the feature information consists of three parts: the database table name, the source field name, and the target field name. The table name locates the specific database table, the source field name locates the column to be translated, and the target field name locates the translation result column. In addition, by combining the table name and field name, multiple fields in the same table can be translated in batches, reducing database connection overhead.

[0054] In some embodiments, the step of composing the feature information of the entity to be translated based on the enumeration name, source field name, and target field name corresponding to the entity to be translated includes: The feature information of the entity to be translated is obtained by concatenating the enumeration name, source field name, and target field name corresponding to the entity to be translated.

[0055] In some embodiments, the step of composing the feature information of the entity to be translated based on the enumeration name, source field name, and target field name corresponding to the entity to be translated includes: The feature information of the entity to be translated is obtained by concatenating the enumeration name, source field name, and target field name corresponding to the entity to be translated.

[0056] In some embodiments, when the translation type is a dictionary type, obtaining the feature information of each entity to be translated in the entity list includes: Using the dictionary code corresponding to the entity to be translated as the feature information of the entity to be translated, obtain the dictionary code corresponding to each translated entity in the entity list; The dictionary codes corresponding to each translated entity are deduplicated, and the deduplicated dictionary codes are used as the feature information of each entity to be translated in the entity list.

[0057] The method for translating application programming interface (API) response data provided in this application embodiment, when the translation type is dictionary-based, uses the dictionary encoding corresponding to the entity to be translated as the feature information of the entity to be translated. The dictionary type uses a single dictionary encoding as feature information, simplifying the structure of the feature information and improving query efficiency. When the translation type is enumeration-based, the feature information of the entity to be translated is composed of the enumeration name, source field name, and target field name corresponding to the entity to be translated. The enumeration type, through the combination of enumeration name, source field name, and target field name, avoids ambiguity of fields with the same name in different enumerations, which helps improve translation accuracy. When the translation type is database table-based, the feature information of the entity to be translated is composed of the database table name, source field name, and target field name corresponding to the entity to be translated. The database table type, through the combination of table name and field name, can batch process the translation of multiple fields in the same table, reducing the number of database queries and helping to improve the efficiency of translating API response data.

[0058] In some embodiments of this application, the translation type includes at least one of dictionary type, enumeration type, and database table type; the step of obtaining the translation mapping relationship corresponding to the entity group based on the feature information of the entities to be translated in the entity group includes: When the translation type is a dictionary type, the correspondence between key-value pairs in the dictionary identified by the dictionary encoding is used as the translation mapping relationship; When the translation type is an enumeration type, the mapping relationship between the field to be translated and the field corresponding to the translation result in the enumeration class identified by the enumeration name is extracted as the translation mapping relationship; When the translation type is a database table type, the mapping relationship between the fields corresponding to the translation fields and the fields corresponding to the translation results in the database table identified by the database table name is extracted as the translation mapping relationship.

[0059] In this embodiment, the translation type may include dictionary type, enumeration type, and database table type, and supports extensions of other custom types. For example, the translation type may also be a cache type or configuration file type. When the translation type is a cache type, the mapping relationship between the field corresponding to the source field name and the field corresponding to the target field name in the cache identified by the cache name is extracted as the translation mapping relationship.

[0060] It is understandable that using the correspondence between key-value pairs in a dictionary identified by dictionary encoding as a translation mapping relationship is equivalent to obtaining a dictionary from a data source through dictionary encoding and using the key-value pairs in the dictionary as a translation mapping relationship.

[0061] Extracting the mapping relationship between the fields to be translated and the fields corresponding to the translation results in the enumeration class identified by the enumeration name is equivalent to obtaining the enumeration class from the data source by the enumeration name and extracting the mapping relationship between the fields to be translated and the fields corresponding to the translation results in the enumeration class.

[0062] Extracting the mapping relationship between the fields corresponding to the translation fields and the fields corresponding to the translation results in the database table identified by the database table name is equivalent to obtaining the database table from the data source by the database table name and extracting the mapping relationship between the fields corresponding to the translation fields and the fields corresponding to the translation results in the database table.

[0063] In some embodiments, when first extracting the mapping relationship between the field to be translated and the field corresponding to the translation result in the enumeration class identified by the enumeration name, the method includes: The enumeration class identified by the enumeration name is dynamically loaded and parsed through reflection mechanism to obtain all enumeration constants and their corresponding field values ​​in the enumeration class; Extract the source field value and target field value of each of the enumeration constants from the enumeration class; Construct a mapping relationship to map the source field value of each enumeration constant to its corresponding target field value.

[0064] This application's embodiments dynamically parse enumeration classes using reflection and construct a mapping relationship between enumeration constants and target field values, enabling efficient and flexible translation logic. This method not only improves translation accuracy and efficiency but also reduces hard coding, enhancing code maintainability and extensibility.

[0065] In some embodiments, the method further includes: After extracting the mapping relationship between the fields to be translated and the fields corresponding to the translation results in the enumeration class identified by the enumeration name, the mapping relationship is written into the cache.

[0066] In subsequent translation operations, the system first checks if the required mapping relationship exists in the cache. If it does, it retrieves the mapping relationship directly from the cache, avoiding repeated reflection operations. This embodiment of the application uses a caching mechanism to ensure that the mapping relationship of each enumeration set is resolved only once through reflection, reducing the number of reflection operations and improving the performance and response speed of translating response data.

[0067] In some embodiments, the step of extracting the mapping relationship between the fields corresponding to the translation fields in the database table identified by the database table name and the fields corresponding to the translation results as the translation mapping relationship includes: A list of source fields is generated based on the values ​​of the fields to be translated for each entity in the entity group. Based on the feature information and the source field list, the mapping relationship between the values ​​of the source fields and the values ​​of the target fields, which are stored in the form of a database table, is obtained from the data source, and the mapping relationship is used as the translation mapping relationship corresponding to the entity group.

[0068] In this embodiment of the application, by generating a source field list, multiple fields can be processed at once, reducing multiple queries to the database and improving efficiency.

[0069] The application programming interface response data translation method provided in this application embodiment helps to achieve efficient translation operations for different translation types (dictionary type, enumeration type, database table type) by obtaining the translation mapping relationship corresponding to entity groups based on feature information. For dictionary type, the dictionary is obtained from the data source through dictionary encoding, and the key-value pairs in the dictionary are used as the translation mapping relationship. For enumeration type, the enumeration class is dynamically parsed through reflection mechanism, the source field value and target field value of the enumeration constant are extracted, and the mapping relationship is constructed. A caching mechanism can also be used to ensure that the mapping relationship of each enumeration set is parsed only once through reflection mechanism. For database table type, the mapping relationship between translation fields and translation results can be obtained in batches from the data source by generating a source field list. By reducing the number of calls to the data source, the overall performance of translating the response data is improved, and the maintainability and extensibility of the code are enhanced, making the translation logic more flexible and able to adapt to possible changes in translation needs.

[0070] In some embodiments of this application, the step of executing a translation strategy that matches the translation type corresponding to the entity list to obtain the translation results for each of the fields to be translated further includes: For each entity to be translated in the entity list, determine whether the caching mechanism is enabled for the field to be translated based on the cache identifier corresponding to the field to be translated of the entity; When the caching mechanism is enabled for the field to be translated, the system searches the cache for a matching cached value based on the value of the field to be translated and the feature information of the corresponding entity to be translated. If a matching cached value exists and the cached value is valid, the cached value is used as the translation result for the field to be translated.

[0071] As is understandable, caching is a technique for storing and retrieving data to reduce the number of accesses to the original data source and improve system performance. For example, ConcurrentReferenceHashMap (a thread-safe hash table) can be used as a cache.

[0072] In some embodiments, the cache is provided with an invalidation mechanism; the invalidation mechanism includes a timed cleanup mechanism, an access verification mechanism, and a capacity limit mechanism.

[0073] For example, a timed cleanup mechanism could be to start a daemon thread during class initialization. This thread would perform cleanup operations at a preset frequency, such as iterating through all cached items and removing expired cached items whose lifespan (which can be determined based on the timestamp of the corresponding cached item) exceeds a preset threshold. An access-time validation mechanism could be to check whether a cached item has expired when a method retrieves the cached data. If the cached item has expired, it would be removed, and the corresponding identifier would be returned.

[0074] A capacity limiting mechanism can prevent the addition of new cache when the cache size exceeds a preset capacity threshold.

[0075] In this embodiment, the memory usage of the cache can be effectively reduced by periodically cleaning up expired cache items through a daemon thread. When retrieving cache items from the cache, it is checked whether the cache items have expired to ensure that the retrieved cache items are valid. By limiting the maximum capacity of the cache, excessive memory usage by the cache can be avoided.

[0076] In some embodiments, the method further includes: determining whether the cached value is valid; The step of determining whether the cached value is valid includes: Compare the current time with the timestamp of the cached value to obtain the lifespan of the cached value; determine whether the cached value is valid based on the lifespan.

[0077] In this embodiment of the application, by verifying the validity of the cache value when obtaining the cache, expired or invalid cache data can be avoided, thereby reducing errors that occur during the translation process.

[0078] In some embodiments, the method further includes: if the caching mechanism is enabled for the field to be translated, and if there is no matching cached value or the cached value is invalid, for the field to be translated, according to the translation type corresponding to the field to be translated, encapsulate the field to be translated into an entity to be translated and write it into an entity list corresponding to the translation type; for each entity list, execute a translation strategy that matches the translation type corresponding to the entity list to obtain the translation result of each field to be translated.

[0079] In some embodiments, a combined strategy of "caching priority + batch query" is adopted, which can significantly improve translation efficiency and solve the performance bottlenecks in traditional methods. Specifically: if the field to be translated has a caching mechanism enabled, a unique cache key is generated based on the value of the field to be translated and the feature information of the entity to be translated. The generated cache key is then used to search the cache for a matching cache value.

[0080] If a matching cached value exists and is valid, the translation result in the cache is used directly, avoiding repeated translation of already translated fields and reducing the number of calls to translation resources.

[0081] For fields that are not cached or whose cached values ​​are invalid, the translation process is executed normally. After being combined with other fields to be translated, a batch query request is generated to retrieve all the necessary mapping relationships from the data source at once, and these key-value pairs are stored in the cache for later use.

[0082] Batch queries reduce the number of accesses to the data source, improve query efficiency, and thus help increase translation speed.

[0083] The method for translating application programming interface response data provided in this application embodiment, when the field to be translated is caching, retrieves the translated dictionary data from the cache along with the value of the field to be translated and the feature information of the corresponding entity to be translated, reducing repeated access to the data source. In addition, the effectiveness of the cache can be ensured through a timed cleanup mechanism, an access-time verification mechanism, and a capacity limit mechanism. This improves the accuracy and efficiency of the translation, reduces the number of calls to the data source, and enhances the overall performance of translating response data.

[0084] In some embodiments of this application, the method further includes: If the caching mechanism is enabled for the field to be translated, the translation result of the field to be translated is stored in the cache in the form of key-value pairs; The key in the key-value pair is generated based on the value of the field to be translated and the feature information of the entity to be translated corresponding to the field to be translated, and the value in the key-value pair is generated based on the translation result and time information.

[0085] In some embodiments, the cache data structure design includes: ConcurrentReferenceHashMap is used as the underlying storage structure for the cache; The data structure of the cached items in the cache is a key-value pair, where the key is of type String and is used to uniquely identify the cached item; the value is a custom TransCacheVal object. The TransCacheVal object includes: a timestamp, used to record the creation time of cached items; and a realVal, used to store the actual cached business data (Object type, supporting arbitrary data).

[0086] The cache data structure design in this application embodiment can guarantee thread safety and implement expiration management through timestamps.

[0087] The method for translating application programming interface response data provided in this application embodiment stores the translation result in the cache in the form of key-value pairs when the field to be translated is enabled by the caching mechanism. The key in the key-value pair is generated based on the value of the field to be translated and the feature information of the entity to be translated, while the value in the key-value pair is generated based on the translation result and time information. This caching mechanism not only improves the efficiency of translation, but also realizes the expiration management of the cache through time information, which helps to ensure the timeliness and accuracy of the cached data.

[0088] In some embodiments of this application, determining the field to be translated in the response data and the translation type corresponding to the field to be translated includes: Iterate through the response data and filter each object in the response data; If an object passes the filter, the fields of the object are traversed in the source code of the object, and if a container field for storing translation results is detected, the object is determined to be the object to be translated. If a field in the source code of the object to be translated contains a field marked with a custom annotation, then that field is identified as the field to be translated. Based on the custom annotations marked on the field to be translated, determine the translation type corresponding to the field to be translated.

[0089] An annotation is a special markup that can be attached to program elements such as classes, methods, and fields. Custom annotations are developer-defined annotations used to provide additional information in the code. In this application, custom annotations can be used to mark fields to be translated and their translation types. These annotations provide the translation requirements for the fields, enabling the fields to be identified as fields to be translated during the traversal process.

[0090] For example, a custom annotation could be "@TransDict", which is placed on a field to mark it as a field to be translated and indicates that the translation type for the field is a dictionary. Alternatively, it could be "@TransEnum", which is placed on a field to mark it as a field to be translated and indicates that the translation type for the field is an enumeration.

[0091] For example, the source code of an object can be the source code of the class to which the object belongs. In this embodiment, it is necessary to access the object's field information, therefore, it is necessary to access the source code of the class to which the object belongs. Exemplarily, this can be achieved through reflection, which allows a program to dynamically access and manipulate the fields, methods, etc., of a class at runtime.

[0092] In some embodiments, filtering the objects in the response data includes: The objects are filtered according to a preset path list. If the object or class is in the preset path list, the object is determined to pass the filter.

[0093] In this embodiment of the application, a preset path list is set. The preset path name is usually the path of the class to which the object belongs (e.g., the package name where the class is located). By traversing only the classes with the specified path and directly terminating the traversal for classes with non-specified paths, the traversal boundary is set. This avoids unnecessary processing of classes with non-specified paths, thereby improving efficiency and avoiding getting trapped in a circular reference chain.

[0094] In some embodiments, the traversal of the fields of the object includes: If the field type is a basic type (such as int, String, etc.) or a third-party class (such as java.util.Date, etc.), then the field is skipped and its internal structure is not traversed.

[0095] If the field type is a container type (such as List, Set, Map, etc.), only its elements or values ​​are traversed, and the properties of the container class itself are not traversed.

[0096] This application's embodiments implement deep automated processing of complex object structures. This method can recursively process complex data structures such as nested objects, collections (List, Set), arrays, and Maps, automatically scanning all fields of the annotations to be translated and completing the translation. Compared to traditional methods, this method eliminates the need to manually write mapping logic for different data structures, facilitating fully automated translation of objects with arbitrary structures and covering complex return value requirements across various business scenarios.

[0097] The method for translating application programming interface response data provided in this application embodiment traverses the response data. If an object passes the filter in the response data, the method traverses the fields of the object in the source code of the object. For objects that pass the filter, a reflection mechanism can be used to traverse their fields. If the object contains a container field for storing translation results, the object is marked as an object to be translated. If a field in the source code of the object to be translated is marked with a custom annotation, the field is determined as a field to be translated. Based on the custom annotation of the field to be translated, the translation type corresponding to the field to be translated can be determined. This achieves efficient determination of the fields to be translated in the response data and their corresponding translation types. The custom annotation marks the fields to be translated and also provides translation type information for the fields, which helps to improve the efficiency and accuracy of translation. The annotation also provides a flexible way to specify the translation requirements of the fields, making the translation process more efficient and reliable.

[0098] In some embodiments of this application, the type of the custom annotation corresponds one-to-one with the translation type. When a field is annotated with a custom annotation, the custom annotation is used to indicate the translation type corresponding to the field. The custom annotation is set with annotation attributes, which include at least a cache identifier indicating whether the annotated field has a caching mechanism enabled.

[0099] Annotation attributes are information that can be carried in annotations, similar to methods in an interface. When defining an annotation, you can define attributes to allow it to carry more information. For example, the annotation attributes of the custom annotation "@TransDict(dicCode="sys_status", useCache=false)" include a cache flag (useCache) indicating whether caching is enabled, and the dictionary encoding (dicCode) of the annotated field.

[0100] In some embodiments, when the translation type is a dictionary type, the custom annotation is further provided with annotation attributes to indicate the dictionary encoding of the annotated field; When the translation type is an enumeration type, the custom annotation is also set with an annotation attribute to indicate the enumeration name corresponding to the annotated field; When the translation type is a database table type, the custom annotation is also set with annotation attributes to indicate the database table name corresponding to the annotated field.

[0101] In this embodiment, by designing a series of annotations such as @TransDict and @TransEnum, the fields that need to be translated are directly marked, and translation parameters (such as dictionary encoding dictCode) can be specified through custom annotation attributes. This annotation-driven approach allows developers to configure translation rules declaratively, thereby achieving "configurable translation" and avoiding the limitations of hard-coded mapping in traditional methods. The use of annotations not only enables dynamic configuration of translation rules, reducing code modification costs, but also clearly distinguishes between fields to be translated and ordinary fields, improving code readability and maintainability.

[0102] The application programming interface (API) response data translation method provided in this application embodiment achieves direct marking of fields requiring translation through the design of custom annotations. Parameters such as cache identifiers and translation parameters can be specified through annotation attributes. The type of the custom annotation corresponds one-to-one with the translation type, indicating the translation type and related parameters of the field, thus avoiding the limitations of hard-coded mapping in traditional methods. The use of annotations not only allows for dynamic configuration of translation rules, reducing code modification costs, but also clearly distinguishes between fields to be translated and ordinary fields, improving code readability and maintainability.

[0103] The following is an example of how to implement a method for translating application programming interface (API) response data: The front end initiates a request, the back end controller processes the business logic, and obtains and returns the raw object containing the encoding; The global response interceptor GlobalTransHandler is used to intercept the return value and call the translate(body) method in the translation utility class TransUtils to translate the returned original object (i.e., the response data of the application programming interface to be returned). This is the entry operation of the translation utility class TransUtils. The entire translation process is coordinated by the TransUtils.translate() method. The specific steps are as follows: First, check the translation switch TransConfig.ENABLE. If the switch is off, return the original object directly. If the switch is on, initialize the translation task list, which covers translation tasks corresponding to various translation types (dictionary type, enumeration type, database table type, or custom type). The TransUtils.getTransEntityList() method performs a deep traversal of the original object (supporting collections and nested objects), scanning for fields annotated with @TransDict, which are the fields to be translated. These fields are then encapsulated into translation entities (i.e., entities to be translated). The encapsulation function can be TransDictEntity(dictCode, key), where dictCode is the dictionary code corresponding to the field to be translated, and key is the value of the field to be translated. TransUtils calls different handlers based on the translation type. For example, dictionary translation calls TransDictHandler. There are also handlers for enumeration translation, table translation, and custom translation. Taking the dictionary translation subprocess (i.e. the processing logic of TransDictHandler) as an example, its processing steps are as follows: (1) Check the cache. If the cache is hit, the value in the cache is directly obtained. If the cache is not hit, the field to be translated is added to the query list. (2) Query the uncached fields to be translated in batches through BaseTransQuery. (3) Match the key and value to update the value field of the entity. Then, the object is traversed through depth using the TransUtils.putTransResult() method to store the translation results in transResultMap; Finally, GlobalTransHandler returns the processed object, which is then serialized and returned to the front end. The front end receives the object and displays the translation results from transResultMap.

[0104] This application's embodiments construct a modular translation architecture, dividing the translation logic into three layers: global interception (GlobalTransHandler), overall processing (TransUtils), and specific translation (TransDictHandler / TransEnumHandler, etc.). This architecture supports various translation types, covering dictionaries, enumerations, database tables, and custom logic, and can meet diverse translation needs. To address the issues of rigid translation logic and limited scalability in traditional methods, this application introduces abstract interfaces (such as BaseTransQuery) and configuration classes (TransConfig). These components enable flexible extension of new translation types or replacement of data sources, thereby improving the scalability of translating response data.

[0105] In practical applications, different developers may adopt different translation logics, such as differences in caching strategies and query methods. This may lead to inconsistent text returned by the same encoding on different interfaces. To solve this problem, this application embodiment uses the translation utility class TransUtils to uniformly schedule various processors (such as TransDictHandler) and standardizes the query and caching logic based on TransCache and BaseTransQuery, thereby ensuring that the translation results of the same encoding remain consistent throughout the system.

[0106] Furthermore, TransUtils employs a plug-in design, supporting custom processors. When a new translation type (such as "third-party interface translation") is needed, the extension can be completed simply by implementing the corresponding interface, effectively reducing the cost of code updates.

[0107] The method for translating application programming interface (API) response data provided in this application embodiment can be executed by an API response data translation device. This application embodiment uses an API response data translation device to execute the method as an example to illustrate the API response data translation device provided in this application embodiment.

[0108] Figure 2 This is a schematic diagram of the structure of a translation device for application programming interface response data provided in some embodiments of this application. For example... Figure 2 As shown, the translation device 200 for application programming interface response data includes: The determination module 201 is used to intercept the response data of the application programming interface to be returned, and determine the field to be translated in the response data and the translation type corresponding to the field to be translated; The encapsulation module 202 is used to encapsulate the field to be translated into an entity to be translated according to the translation type corresponding to the field to be translated and write it into the entity list corresponding to the translation type; Translation module 203 is used to execute a translation strategy that matches the translation type corresponding to the entity list after the entity to be translated is written, and to obtain the translation result of each of the fields to be translated; The update module 204 is used to update the response data according to each of the translation results to obtain the translation completed response data.

[0109] In some embodiments, the translation module 203 is used for: Obtain feature information for each entity to be translated in the entity list, wherein the structure of the feature information is determined based on the translation type; Based on the feature information, each entity to be translated is divided into at least one entity group, and the feature information of each entity to be translated in the entity group is the same. For each entity group, a translation mapping relationship corresponding to the entity group is obtained based on the feature information of the entity to be translated in the entity group. The translation result of the fields to be translated for each entity to be translated is determined based on the translation mapping relationship.

[0110] In some embodiments, the translation type includes at least one of dictionary type, enumeration type, and database table type; obtaining the feature information of each entity to be translated in the entity list includes: When the translation type is dictionary type, the dictionary code corresponding to the entity to be translated is used as the feature information of the entity to be translated, and the dictionary code is used to identify the dictionary in the data source; When the translation type is an enumeration type, the feature information of the entity to be translated is composed of the enumeration name, source field name and target field name corresponding to the entity to be translated. The enumeration name is used to identify the enumeration class in the data source, the source field name is used to specify the field corresponding to the field to be translated in the enumeration class, and the target field name is used to specify the field corresponding to the translation result of the field to be translated in the enumeration class. When the translation type is a database table type, the feature information of the entity to be translated is composed of the database table name, source field name, and target field name corresponding to the entity to be translated. The database table name is used to identify the database table in the data source, the source field name is used to specify the field corresponding to the field to be translated in the database table, and the target field name is used to specify the field corresponding to the translation result of the field to be translated in the database table.

[0111] In some embodiments, the translation type includes at least one of dictionary type, enumeration type, and database table type; obtaining the translation mapping relationship corresponding to the entity group based on the feature information of the entities to be translated in the entity group includes: When the translation type is a dictionary type, the correspondence between key-value pairs in the dictionary identified by the dictionary encoding is used as the translation mapping relationship; When the translation type is an enumeration type, the mapping relationship between the field to be translated and the field corresponding to the translation result in the enumeration class identified by the enumeration name is extracted as the translation mapping relationship; When the translation type is a database table type, the mapping relationship between the fields corresponding to the translation fields and the fields corresponding to the translation results in the database table identified by the database table name is extracted as the translation mapping relationship.

[0112] In some embodiments, the translation module 203 is further configured to: For each entity to be translated in the entity list, determine whether the caching mechanism is enabled for the field to be translated based on the cache identifier corresponding to the field to be translated of the entity; When the caching mechanism is enabled for the field to be translated, the system searches the cache for a matching cached value based on the value of the field to be translated and the feature information of the corresponding entity to be translated. If a matching cached value exists and the cached value is valid, the cached value is used as the translation result for the field to be translated.

[0113] In some embodiments, the translation device 200 for application programming interface response data further includes a caching module, which is used for: If the caching mechanism is enabled for the field to be translated, the translation result of the field to be translated is stored in the cache in the form of key-value pairs; The key in the key-value pair is generated based on the value of the field to be translated and the feature information of the entity to be translated corresponding to the field to be translated, and the value in the key-value pair is generated based on the translation result and time information.

[0114] In some embodiments, the determining module 201 is configured to: Iterate through the response data and filter each object in the response data; If an object passes the filter, the fields of the object are traversed in the source code of the object, and if a container field for storing translation results is detected, the object is determined to be the object to be translated. If a field in the source code of the object to be translated contains a field annotated with a custom annotation, then that field is identified as the field to be translated. Based on the custom annotations marked on the field to be translated, determine the translation type corresponding to the field to be translated.

[0115] In some embodiments, the types of the custom annotations correspond one-to-one with the translation types. When a field is annotated with a custom annotation, the custom annotation is used to indicate the translation type corresponding to the field. The custom annotation is set with annotation attributes, which include at least a cache identifier indicating whether the annotated field has a caching mechanism enabled.

[0116] The translation device for application programming interface response data in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the scope of the device.

[0117] The device for translating application programming interface response data in this embodiment can be a device with an operating system. This operating system can be a Microsoft (Windows) operating system, an Android operating system, an iOS operating system, or other possible operating systems; this embodiment does not specifically limit the specific operating system.

[0118] The application programming interface response data translation device provided in this application embodiment can implement all the processes implemented in the above application programming interface response data translation method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0119] Figure 3 These are schematic diagrams of the structure of an electronic device provided in some embodiments of this application. In some embodiments, such as Figure 3 As shown, this application embodiment also provides an electronic device 300, including a processor 301, a memory 302, and a computer program stored in the memory 302 and executable on the processor 301. When the program is executed by the processor 301, it implements the various processes of the above-described application programming interface response data translation method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0120] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0121] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described method embodiment for translating application programming interface response data, and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0122] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0123] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method for translating application programming interface response data.

[0124] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0125] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described application programming interface response data translation method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0126] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0127] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0128] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the related technology, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0129] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

[0130] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0131] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.

Claims

1. A method for translating application programming interface (API) response data, characterized in that, include: Intercept the response data of the application programming interface to be returned, and determine the fields to be translated in the response data and the translation type corresponding to the fields to be translated; Based on the translation type corresponding to the field to be translated, the field to be translated is encapsulated into an entity to be translated and written into the entity list corresponding to the translation type; For the entity list written to the entities to be translated, execute the translation strategy that matches the translation type corresponding to the entity list to obtain the translation result of each of the fields to be translated; The response data is updated based on the translation results to obtain the translation-complete response data.

2. The method according to claim 1, characterized in that, The translation strategy, which matches the translation type corresponding to the entity list, is executed to obtain the translation results for each of the fields to be translated, including: Obtain feature information for each entity to be translated in the entity list, wherein the structure of the feature information is determined based on the translation type; Based on the feature information, each entity to be translated is divided into at least one entity group, and the feature information of each entity to be translated in the entity group is the same. For each entity group, a translation mapping relationship corresponding to the entity group is obtained based on the feature information of the entity to be translated in the entity group. The translation result of the fields to be translated for each entity to be translated is determined based on the translation mapping relationship.

3. The method according to claim 2, characterized in that, The translation type includes at least one of dictionary type, enumeration type, and database table type; obtaining the feature information of each entity to be translated in the entity list includes: When the translation type is dictionary type, the dictionary code corresponding to the entity to be translated is used as the feature information of the entity to be translated, and the dictionary code is used to identify the dictionary in the data source; When the translation type is an enumeration type, the feature information of the entity to be translated is composed of the enumeration name, source field name and target field name corresponding to the entity to be translated. The enumeration name is used to identify the enumeration class in the data source, the source field name is used to specify the field corresponding to the field to be translated in the enumeration class, and the target field name is used to specify the field corresponding to the translation result of the field to be translated in the enumeration class. When the translation type is a database table type, the feature information of the entity to be translated is composed of the database table name, source field name, and target field name corresponding to the entity to be translated. The database table name is used to identify the database table in the data source, the source field name is used to specify the field corresponding to the field to be translated in the database table, and the target field name is used to specify the field corresponding to the translation result of the field to be translated in the database table.

4. The method according to claim 3, characterized in that, The translation type includes at least one of dictionary type, enumeration type, and database table type; the step of obtaining the translation mapping relationship corresponding to the entity group based on the feature information of the entities to be translated in the entity group includes: When the translation type is a dictionary type, the correspondence between key-value pairs in the dictionary identified by the dictionary encoding is used as the translation mapping relationship; When the translation type is an enumeration type, the mapping relationship between the field to be translated and the field corresponding to the translation result in the enumeration class identified by the enumeration name is extracted as the translation mapping relationship; When the translation type is a database table type, the mapping relationship between the fields corresponding to the translation fields and the fields corresponding to the translation results in the database table identified by the database table name is extracted as the translation mapping relationship.

5. The method according to claim 1, characterized in that, The step of executing a translation strategy that matches the translation type corresponding to the entity list to obtain the translation results for each of the fields to be translated also includes: For each entity to be translated in the entity list, determine whether the caching mechanism is enabled for the field to be translated based on the cache identifier corresponding to the field to be translated of the entity; When the caching mechanism is enabled for the field to be translated, the system searches the cache for a matching cached value based on the value of the field to be translated and the feature information of the corresponding entity to be translated. If a matching cached value exists and the cached value is valid, the cached value is used as the translation result for the field to be translated.

6. The method according to claim 2 or 5, characterized in that, The method further includes: If the caching mechanism is enabled for the field to be translated, the translation result of the field to be translated is stored in the cache in the form of key-value pairs; The key in the key-value pair is generated based on the value of the field to be translated and the feature information of the entity to be translated corresponding to the field to be translated, and the value in the key-value pair is generated based on the translation result and time information.

7. The method according to claim 1, characterized in that, The step of determining the field to be translated in the response data and the translation type corresponding to the field to be translated includes: Iterate through the response data and filter each object in the response data; If an object passes the filter, the fields of the object are traversed in the source code of the object, and if a container field for storing translation results is detected, the object is determined to be the object to be translated. If a field in the source code of the object to be translated contains a field marked with a custom annotation, then that field is identified as the field to be translated. Based on the custom annotations marked on the field to be translated, determine the translation type corresponding to the field to be translated.

8. The method according to claim 7, characterized in that, The types of the custom annotations correspond one-to-one with the translation types. When a field is annotated with a custom annotation, the custom annotation is used to indicate the translation type corresponding to the field. The custom annotation is set with annotation attributes, which include at least a cache identifier indicating whether the annotated field has a caching mechanism enabled.

9. A device for translating application programming interface response data, characterized in that, include: The determination module is used to intercept the response data of the application programming interface to be returned, and to determine the fields to be translated in the response data and the translation type corresponding to the fields to be translated. The encapsulation module is used to encapsulate the field to be translated into an entity to be translated according to the translation type corresponding to the field to be translated and write it into the entity list corresponding to the translation type; The translation module is used to execute a translation strategy that matches the translation type of the entity list after the entity to be translated is written, and to obtain the translation result of each of the fields to be translated. The update module is used to update the response data according to each of the translation results to obtain the translation-completed response data.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method for translating application programming interface response data as described in any one of claims 1-8.