Back-end language switching method and device, equipment and storage medium
By intercepting the interface response data on the backend and matching it with the preset dictionary table, language switching is achieved, which solves the problems of slow response speed, high maintenance cost and security risks in traditional international processing methods, significantly improves the language switching efficiency and user experience, and at the same time enhances the security of the system.
Patent Information
- Application Number
- CN202411776771.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-12-05
AI Technical Summary
Traditional international processing methods rely on front-end technology, resulting in slow response speed, high maintenance costs, and security risks of back-end data being exposed to the front-end.
By intercepting the response data of the target interface on the backend, obtaining the path information to match the preset interface field table, determining the switchable field, and matching the preset dictionary table based on the language to be converted, replacing the fields in the response data to achieve language switching.
The efficiency of language switching is significantly improved without modifying the original business code, reducing the time for loading language packages on the front end, improving the user interface rendering speed, and reducing security risks and enhancing the security of the system by performing translation processing on the back end.
Smart Images

Figure CN119645554A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a backend language switching method, device, equipment and storage medium. Background Art
[0002] With the rapid development of globalization and Internet technology, multi-language support has become an indispensable and important function of modern software applications. Especially in multinational enterprises, cross-border e-commerce, and web applications and mobile applications for global users, providing multi-language interfaces and content has become a key factor in attracting and retaining users. However, traditional internationalization processing methods often rely on front-end technology, that is, dynamically loading the corresponding language package on the client according to the language selected by the user. Although this method meets the multi-language needs to a certain extent, it has problems such as slow response speed, high maintenance cost, and possible security risks caused by directly exposing back-end data to the front-end. Summary of the invention
[0003] In view of this, the purpose of the present invention is to provide a backend language switching method, device, equipment and storage medium, which can significantly improve the efficiency of language switching without modifying the original business code. The specific scheme is as follows:
[0004] In a first aspect, the present application discloses a backend language switching method, comprising:
[0005] If the response data of the target interface of the backend is intercepted, the path information corresponding to the target interface is obtained, and the path information is matched with the preset interface field table to determine the switchable field;
[0006] Determining a plurality of to-be-converted fields in the response data based on the switchable fields, and determining a current language and a to-be-converted language corresponding to the response data, so as to match the plurality of to-be-converted fields with a preset dictionary table based on the to-be-converted language;
[0007] If there is a complete match, replacing the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table;
[0008] If a complete match is not possible, determine several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols among the several fields to be converted, and replace the several first fields to be converted with several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and replace the several second fields to be converted with preset placeholders in the preset dictionary table.
[0009] Optionally, if the response data of the target interface of the backend is intercepted, the path information corresponding to the target interface is obtained, and the path information is matched with the preset interface field table to determine the switchable field, including:
[0010] Determine whether there is a target interface for data feedback among the multiple data interfaces of the back end, and if the target interface exists, intercept data of the target interface to obtain response data fed back by the target interface;
[0011] Path information corresponding to the target interface is obtained, and the path information is matched with a preset interface field table to determine a switchable field type corresponding to the target interface, and a switchable field is determined according to the switchable field type.
[0012] Optionally, determining a number of to-be-converted fields in the response data based on the switchable fields, and determining a current language and a to-be-converted language corresponding to the response data, so as to match the number of to-be-converted fields with a preset dictionary table based on the to-be-converted language, includes:
[0013] Extracting a number of fields to be converted corresponding to the switchable fields in the response data;
[0014] Determine the current language corresponding to the response data, and determine the language to be converted corresponding to the response data according to the received language conversion instruction;
[0015] The plurality of fields to be converted are matched with fields corresponding to the language to be converted in a preset dictionary table.
[0016] Optionally, if there is a complete match, replacing the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table includes:
[0017] If the plurality of to-be-converted fields completely match the fields corresponding to the to-be-converted language in the preset dictionary table, extracting a plurality of first target conversion fields corresponding to the plurality of to-be-converted fields from the preset dictionary table; the plurality of first target conversion fields are fields corresponding to the to-be-converted language;
[0018] The plurality of to-be-converted fields are replaced based on the plurality of first target conversion fields.
[0019] Optionally, if the complete match cannot be achieved, determining several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols among the several fields to be converted, and replacing the several first fields to be converted by several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and replacing the several second fields to be converted by preset placeholders in the preset dictionary table, includes:
[0020] If the plurality of fields to be converted cannot completely match the fields corresponding to the language to be converted in the preset dictionary table, extracting a plurality of first fields to be converted corresponding to the current language from the plurality of fields to be converted, and using the fields that do not match the current language from the plurality of fields to be converted as a plurality of second fields to be converted representing symbols;
[0021] Matching the first to-be-converted fields with the preset dictionary table to determine the second target conversion fields corresponding to the first to-be-converted fields, and replacing the first to-be-converted fields with the second target conversion fields;
[0022] A placeholder in the preset dictionary table is extracted, and the plurality of second fields to be converted are replaced by the placeholder.
[0023] Optionally, the backend language switching method further includes:
[0024] If the plurality of to-be-converted fields cannot completely match the fields corresponding to the to-be-converted language in the preset dictionary table, and the plurality of first to-be-converted fields cannot completely match the preset dictionary table, then the backend language switching is exited.
[0025] Optionally, the backend language switching method further includes:
[0026] If a new language request is received, determining a target new language corresponding to the new language request, and obtaining a target new language package corresponding to the target new language;
[0027] The preset dictionary table is updated based on the target new language package, so as to provide a language switching service corresponding to the target new language based on the obtained updated dictionary table.
[0028] In a second aspect, the present application discloses a backend language switching device, comprising:
[0029] An information matching module, for obtaining path information corresponding to the target interface if the response data of the target interface of the back end is intercepted, and matching the path information with the preset interface field table to determine the switchable field;
[0030] A field matching module, which determines a number of to-be-converted fields in the response data based on the switchable fields, and determines a current language and a to-be-converted language corresponding to the response data, so as to match the number of to-be-converted fields with a preset dictionary table based on the to-be-converted language;
[0031] A first field conversion module, configured to replace the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table if there is a complete match;
[0032] The second field conversion module is used to determine, if a complete match cannot be made, several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols among the several fields to be converted, and replace the several first fields to be converted with several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and replace the several second fields to be converted with preset placeholders in the preset dictionary table.
[0033] In a third aspect, the present application discloses an electronic device, comprising:
[0034] Memory, used to store computer programs;
[0035] The processor is used to execute the computer program to implement the backend language switching method as described above.
[0036] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the backend language switching method as described above.
[0037] In the present application, after intercepting the response data of the target interface of the back-end, the path information corresponding to the target interface can be obtained, and the path information can be matched with the preset interface field table to determine the switchable fields; then, based on the switchable fields, several fields to be converted in the response data are determined, and the current language and the language to be converted corresponding to the response data are determined, so as to match the several fields to be converted with the preset dictionary table based on the language to be converted; if there is a complete match, the several fields to be converted are replaced based on several first target conversion fields corresponding to the several fields to be converted in the preset dictionary table; if there is not a complete match, several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols in the several fields to be converted are determined, and the several first fields to be converted are replaced by several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and the several second fields to be converted are replaced by preset placeholders in the preset dictionary table. It can be seen that, through the method of the present application, after intercepting the response data of the target interface of the back-end, the path information corresponding to the target interface is matched with the preset interface field table to determine the switchable field, and then the field to be converted in the response data is determined according to the switchable field, and then the field to be converted is matched with the preset dictionary table. In the case of a complete match, the field to be converted is replaced according to the target conversion field in the dictionary table. In the case of a complete match, it is necessary to determine the first field to be converted corresponding to the current language and the second field to be converted representing the symbol in the field to be converted, and replace the first field to be converted by the field in the preset dictionary table, and replace the second field to be converted by the preset placeholder. In this way, the real-time translation and dynamic language switching of the interface response data can be realized by setting the language dictionary table, the interface and field table and the interceptor logic. And by calling the back-end interface for language switching, the efficiency of language switching can be significantly improved without modifying the original business code, which effectively improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0039] Figure 1 A flow chart of a backend language switching method disclosed in this application;
[0040] Figure 2 This is an interface field representation diagram disclosed in this application;
[0041] Figure 3 A dictionary representation intended for the present application;
[0042] Figure 4 A schematic diagram of a backend language switching system disclosed in this application;
[0043] Figure 5 A schematic diagram of a backend language switching system processing logic disclosed in this application;
[0044] Figure 6 This is a schematic diagram of the structure of a back-end language switching device disclosed in this application;
[0045] Figure 7 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] In the prior art, traditional internationalization processing methods often rely on front-end technology, that is, dynamically loading the corresponding language package on the client side according to the language selected by the user. Although this method meets the multi-language requirements to a certain extent, it has problems such as slow response speed, high maintenance cost, and possible security risks caused by directly exposing back-end data to the front-end.
[0048] In order to overcome the above technical problems, the present application discloses a backend language switching method, apparatus, device and storage medium, which can significantly improve the efficiency of language switching without modifying the original business code.
[0049] See also Figure 1 As shown, an embodiment of the present invention discloses a backend language switching method, including:
[0050] Step S11: If the response data of the target interface of the backend is intercepted, the path information corresponding to the target interface is obtained, and the path information is matched with the preset interface field table to determine the switchable field.
[0051] In this embodiment, it is necessary to intercept the response data of the back-end interface, and then determine the path information of the intercepted interface, and match the preset interface field table according to the path information to determine the switchable field in the preset interface field table corresponding to the path information. Specifically, it is necessary to determine whether there is a target interface for data feedback among the several data interfaces of the back-end. If there is a target interface for data feedback, the data of the target interface is intercepted to obtain the response data fed back by the target interface. It should be noted that when intercepting data, it is necessary to intercept through the interceptor set in the language switching system, and the interceptor can translate the fields that need to be internationalized in the response message of the interface according to the language environment. The language environment refers to the current language of the field in the current response message and the language that needs to be converted to, that is, the language to be converted.
[0052] Further, after intercepting the response data of the target interface, it is necessary to obtain the path information corresponding to the target interface, and match the path information with the preset interface field table to determine the switchable field type corresponding to the target interface, and determine the switchable field according to the switchable field type, specifically, Figure 2 As shown, it is necessary to obtain the URI (Uniform Resource Identifier) path information corresponding to the target interface and match it with the preset interface field table to determine the switchable field type corresponding to the target interface, and then determine the switchable field according to the determined switchable field type. It should be noted that the interface field table will store which fields corresponding to each interface need to be switched in language. For example, if the input language needs to be converted to English, but the current input field contains English input by the user, then no language switching is required. In the message corresponding to some interfaces, the code field does not need to be switched in language, but the name field needs to be switched in language, so the name field is matched to the table. For example, the uri in the message represents the uri path of the interface, and the field represents the field name. If the field has a hierarchy, "." is used to represent the hierarchy, such as productTypeList.name. In this way, by introducing the interface field table, it is precisely controlled which fields in each interface need to be internationalized, which reduces maintenance costs and effectively improves management efficiency.
[0053] Step S12: determining a plurality of fields to be converted in the response data based on the switchable fields, and determining a current language and a language to be converted corresponding to the response data, so as to match the plurality of fields to be converted with a preset dictionary table based on the language to be converted.
[0054] In this embodiment, it is necessary to determine the field to be converted in the response data according to the determined switchable field, and then match the field to be converted with the preset dictionary table based on the language to be converted corresponding to the response data. Specifically, it is necessary to extract several fields to be converted corresponding to the switchable field in the response data, that is, after determining the switchable field corresponding to the target interface in the interface field, it is necessary to convert the body part of the response data into JsonNode, and then traverse the JsonNode to determine the field corresponding to the switchable field, and use the field corresponding to the switchable field as the field to be converted to obtain several fields to be converted. Then it is necessary to determine the current language corresponding to the response data, and determine the language to be converted corresponding to the response data according to the received language conversion instruction. For example, the field in the current response data is Chinese. According to the received instruction, the Chinese in the field needs to be converted to English, then the current language corresponding to the response data is Chinese, and the corresponding language to be converted is English. Further, it is necessary to match the determined several fields to be converted with the fields corresponding to the language to be converted in the preset dictionary table. In this way, the language of the interface response data can be dynamically adjusted according to the user's language environment or choice, to meet the user's personalized language needs, and improve the flexibility and adaptability of the system.
[0055] Step S13: If there is a complete match, replacing the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table.
[0056] In this embodiment, when matching the field to be converted with the field corresponding to the language to be converted in the preset dictionary table, it is first necessary to accurately match the field to be converted. Specifically, if the several fields to be converted in the determined response data completely match the fields corresponding to the language to be converted in the preset dictionary table, then several first target conversion fields corresponding to the several fields to be converted are extracted from the preset dictionary table; wherein the several first target conversion fields are fields corresponding to the language to be converted, and then the several fields to be converted are replaced based on the several first target conversion fields. It should be noted that accurate matching means that the string must be completely matched. For example, if there is a "cloud server" field value in the return message data of the interface, the Chinese column of the language dictionary table must have a "cloud server" text value. If there is no less than one field in the several fields to be converted that fails to match the preset dictionary table, it indicates that the accurate matching has failed.
[0057] It should be noted that the preset dictionary table stores text information in each language, each column represents a language, and each row represents the same text information in different languages, such as Figure 3As shown in the figure, zh indicates the Chinese column, en indicates the English column, and you can add a language column. The first column is the original language column. The original language is the default language text in the interface response message. For example, the backend interface data returns Chinese data without switching the language. When switching the language, the text that matches the first column will be translated into the corresponding language text. For example, the original response message is as follows:
[0058] {
[0059] "code": "ECS",
[0060] "name": "Cloud Server",
[0061] "productTypeList": [{
[0062] "name": "FPGA type",
[0063] }]
[0064] }.
[0065] If the language information in the message header fed back by the interface is English, the text that matches the zh column will be converted into the text in the en column. The converted message is as follows:
[0066] {
[0067] "code": "ECS",
[0068] "name": " Cloud Server ",
[0069] "productTypeList": [{
[0070] "name": "FPGA model",
[0071] }]
[0072] }.
[0073] Step S14: If a complete match cannot be made, determine several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols among the several fields to be converted, and replace the several first fields to be converted with several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and replace the several second fields to be converted with preset placeholders in the preset dictionary table.
[0074] In this embodiment, if the exact match fails, a locator match is required. Specifically, if the several fields to be converted cannot completely match the fields corresponding to the language to be converted in the preset dictionary table, it is necessary to extract several first fields to be converted corresponding to the current language from the several fields to be converted, and use the fields that do not match the current language from the several fields to be converted as several second fields to be converted representing symbols. Specifically, the string needs to be divided into two parts: the default language (current language) and the non-default language. For example, if the default language is Chinese, the string is divided into several first fields to be converted in the Chinese part and several second fields to be converted in the non-Chinese part during the placeholder matching. The data of the Chinese part remains unchanged, and the non-Chinese part is replaced with a placeholder. Then, it is necessary to match the several first fields to be converted with the preset dictionary table to determine the several second target conversion fields corresponding to the several first fields to be converted, and replace the several first fields to be converted with the several second target conversion fields. Finally, the placeholder in the preset dictionary table is extracted, and the several second fields to be converted are replaced with the placeholder. For example, if the text information in the response data is "The CPU usage of host: test-001 is higher than 20%", the text after placeholder replacement is "The {2} usage of host {1} is higher than {3}", and then the Chinese part of the replaced text "The {2} usage of host {1} is higher than {3}" is matched with the preset dictionary table, and the Chinese in it is converted into the language to be converted.
[0075] It should be noted that the back-end language switching method in the present application also includes: if the several fields to be converted cannot completely match the fields corresponding to the language to be converted in the preset dictionary table, and the several first fields to be converted cannot completely match the preset dictionary table, then exit the back-end language switching. That is, if the several fields to be converted in the response data cannot completely match the fields corresponding to the language to be converted in the preset dictionary table, locator matching is required, but when performing locator matching, the first field to be converted corresponding to the current language cannot completely match the field corresponding to the language to be converted in the preset dictionary table, then it is necessary to directly exit the language switching.
[0076] It is further necessary to explain that the back-end language switching method in the present application also includes: if a new language request is received, the target new language corresponding to the new language request is determined, and the target new language package corresponding to the target new language is obtained; the preset dictionary table is updated based on the target new language package, so as to provide a language switching service corresponding to the target new language based on the updated dictionary table obtained. That is, if a new language request is received, the target new language corresponding to the new language request needs to be added to the preset dictionary table, and the target new language package corresponding to the target new language needs to be obtained first, and then the target new language package is updated to the preset dictionary table, and the language switching service corresponding to the target new language is provided through the updated updated dictionary table. For example, if a new language request for Spanish is received, the Spanish language package needs to be obtained, and the Spanish language package needs to be installed in the new dictionary table, and then the Spanish language switching service is provided through the updated new dictionary table. In this way, the supported language types and interface ranges can be expanded to meet the possible multilingual needs in the future, and the user experience is effectively improved.
[0077] It can be seen that, through the method of the present application, after intercepting the response data of the target interface of the back-end, the path information corresponding to the target interface is matched with the preset interface field table to determine the switchable field, and then the field to be converted in the response data is determined according to the switchable field, and then the field to be converted is matched with the preset dictionary table. If it can be completely matched, the field to be converted is replaced according to the target conversion field in the dictionary table. If it cannot be completely matched, it is necessary to determine several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols in the field to be converted, and replace the first field to be converted by the field in the preset dictionary table, and replace the second field to be converted by the preset placeholder. In this way, on the one hand, by directly translating on the back end, the time required for the front end to load the language pack is greatly reduced, thereby speeding up the user interface rendering speed, enabling users to obtain the required information more quickly, and avoiding the direct exposure of sensitive data on the back end to the front end. By performing translation processing on the back end, potential security risks are effectively reduced, the security of the system is enhanced, and the user experience is significantly improved; on the other hand, by introducing the interface field table and the dictionary table, it is precisely controlled which fields of which interfaces need to be internationalized, further reducing maintenance costs and improving management efficiency; on another hand, the language of the interface response data can be dynamically adjusted according to the user's language environment or choice to meet the user's personalized language needs, and the back-end interface return data can be converted according to the language without modifying the original business code, thereby improving the flexibility and adaptability of the system.
[0078] See also Figure 4As shown, an embodiment of the present invention discloses a backend language switching system, including:
[0079] In this embodiment, Figure 4 As shown in the figure, the backend language switching system mainly includes a cache module, an interceptor module and a text matching module, wherein the cache module is mainly used to cache the data in the preset dictionary table and the preset interface field table, so as not to frequently request the database when switching languages; the interceptor module is used to intercept all interface URI data and body data in the response message and convert the information in the body data in the response message into information in the corresponding language and then return it to the caller. The specific logic is to perform an exact match on the data first, and if the exact match fails, perform a placeholder match; the text matching module mainly performs an exact match and a placeholder match on the data.
[0080] It should be noted that the execution logic of the backend language switching system is as follows Figure 5 As shown, first, it is necessary to intercept the interface response data, then obtain the URI path information corresponding to the target interface, and match the URI path information with the preset interface field table to determine the switchable fields, and determine several fields to be converted in the response data according to the switchable fields, and accurately match the several fields to be converted with the preset dictionary table, and the matched language is the language to be converted that needs to be converted. If all fields have matching fields of the language to be converted in the preset dictionary table, the exact match is successful, and the fields to be converted are replaced with the fields that have been matched successfully. If the match fails, fuzzy matching, that is, placeholder matching, is performed. It is necessary to determine several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols in the several fields to be converted, and then match the several first fields to be converted with the preset dictionary table. If all match successfully, the first fields to be converted are replaced with the fields that have been matched successfully, and the second fields to be converted are replaced with the placeholders in the preset dictionary table. If the several first fields to be converted cannot completely match the preset dictionary table, the language conversion is exited.
[0081] See also Figure 6 As shown, an embodiment of the present invention discloses a backend language switching device, comprising:
[0082] The information matching module 11 is used to obtain the path information corresponding to the target interface if the response data of the target interface of the back end is intercepted, and match the path information with the preset interface field table to determine the switchable field;
[0083] A field matching module 12 determines a plurality of to-be-converted fields in the response data based on the switchable fields, and determines a current language and a to-be-converted language corresponding to the response data, so as to match the plurality of to-be-converted fields with a preset dictionary table based on the to-be-converted language;
[0084] A first field conversion module 13, configured to replace the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table if there is a complete match;
[0085] The second field conversion module 14 is used to determine, if a complete match cannot be made, a number of first fields to be converted corresponding to the current language and a number of second fields to be converted representing symbols among the number of fields to be converted, and replace the number of first fields to be converted with a number of second target conversion fields corresponding to the number of first fields to be converted in the preset dictionary table, and replace the number of second fields to be converted with preset placeholders in the preset dictionary table.
[0086] In this embodiment, after intercepting the response data of the target interface of the back-end, the path information corresponding to the target interface can be obtained, and the path information can be matched with the preset interface field table to determine the switchable fields; then, based on the switchable fields, several fields to be converted in the response data are determined, and the current language and the language to be converted corresponding to the response data are determined, so as to match the several fields to be converted with the preset dictionary table based on the language to be converted; if there is a complete match, the several fields to be converted are replaced based on several first target conversion fields corresponding to the several fields to be converted in the preset dictionary table; if there is not a complete match, several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols in the several fields to be converted are determined, and the several first fields to be converted are replaced by several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and the several second fields to be converted are replaced by preset placeholders in the preset dictionary table. It can be seen that, through the method of the present application, after intercepting the response data of the target interface of the backend, the path information corresponding to the target interface is matched with the preset interface field table to determine the switchable field, and then the field to be converted in the response data is determined according to the switchable field, and then the field to be converted is matched with the preset dictionary table. In the case of a complete match, the field to be converted is replaced according to the target conversion field in the dictionary table. In the case of a complete match, it is necessary to determine the first field to be converted corresponding to the current language and the second field to be converted representing the symbol in the field to be converted, and replace the first field to be converted by the field in the preset dictionary table, and replace the second field to be converted by the preset placeholder. In this way, the real-time translation and dynamic language switching of the interface response data can be realized by setting the language dictionary table, the interface and field table and the interceptor logic. And by calling the backend interface for language switching, the efficiency of language switching can be significantly improved without modifying the original business code, which effectively improves the user experience.
[0087] In some embodiments, the information matching module 11 may specifically include:
[0088] A data interception unit is used to determine whether there is a target interface for data feedback among the multiple data interfaces of the back end, and if the target interface exists, intercept the data of the target interface to obtain the response data fed back by the target interface;
[0089] The switchable field determination unit is used to obtain the path information corresponding to the target interface, and match the path information with the preset interface field table to determine the switchable field type corresponding to the target interface, and determine the switchable field according to the switchable field type.
[0090] In some embodiments, the field matching module 12 may specifically include:
[0091] A field-to-be-converted extraction unit, used for extracting a number of fields to be converted corresponding to the switchable fields in the response data;
[0092] a language determination unit, configured to determine a current language corresponding to the response data, and determine a language to be converted corresponding to the response data according to a received language conversion instruction;
[0093] The field matching unit is used to match the plurality of to-be-converted fields with fields corresponding to the to-be-converted language in a preset dictionary table.
[0094] In some embodiments, the first field conversion module 13 may specifically include:
[0095] A first field extraction unit is configured to extract a plurality of first target conversion fields corresponding to the plurality of fields to be converted from the preset dictionary table if the plurality of fields to be converted completely match the fields corresponding to the language to be converted in the preset dictionary table; the plurality of first target conversion fields are fields corresponding to the language to be converted;
[0096] The first field conversion unit is configured to replace the plurality of to-be-converted fields based on the plurality of first target conversion fields.
[0097] In some embodiments, the second field conversion module 14 may specifically include:
[0098] a second field extraction unit, configured to extract a plurality of first fields to be converted corresponding to the current language from the plurality of fields to be converted, if the plurality of fields to be converted do not completely match the fields corresponding to the language to be converted in the preset dictionary table, and use the fields that do not match the current language from the plurality of fields to be converted as a plurality of second fields to be converted representing symbols;
[0099] A second field conversion unit, configured to match the plurality of first to-be-converted fields with the preset dictionary table to determine a plurality of second target conversion fields corresponding to the plurality of first to-be-converted fields, and replace the plurality of first to-be-converted fields with the plurality of second target conversion fields;
[0100] The third field conversion unit is used to extract the placeholders in the preset dictionary table and replace the plurality of second fields to be converted with the placeholders.
[0101] In some embodiments, the backend language switching device may specifically include:
[0102] The language switching exit unit is used to exit the backend language switching if the plurality of to-be-converted fields cannot completely match the fields corresponding to the to-be-converted language in the preset dictionary table, and the plurality of first to-be-converted fields cannot completely match the preset dictionary table.
[0103] In some embodiments, the backend language switching device may specifically include:
[0104] a new language package acquisition unit, configured to, upon receiving a new language request, determine a target new language corresponding to the new language request, and acquire a target new language package corresponding to the target new language;
[0105] The dictionary table updating unit is used to update the preset dictionary table based on the target new language package, so as to provide a language switching service corresponding to the target new language based on the updated dictionary table obtained.
[0106] Furthermore, the present application also discloses an electronic device. Figure 7 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.
[0107] Figure 7 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the back-end language switching method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0108] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0109] In addition, the memory 22 as a carrier for resource storage may be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage method may be temporary storage or permanent storage.
[0110] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the back-end language switching method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.
[0111] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the backend language switching method disclosed above is implemented. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the above embodiments, and no further description will be given here.
[0112] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0113] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0114] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0115] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0116] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A backend language switching method, characterized in that: include: If the response data of the target interface of the backend is intercepted, the path information corresponding to the target interface is obtained, and the path information is matched with the preset interface field table to determine the switchable field; Determining a plurality of to-be-converted fields in the response data based on the switchable fields, and determining a current language and a to-be-converted language corresponding to the response data, so as to match the plurality of to-be-converted fields with a preset dictionary table based on the to-be-converted language; If there is a complete match, replacing the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table; If a complete match is not possible, determine several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols among the several fields to be converted, and replace the several first fields to be converted with several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and replace the several second fields to be converted with preset placeholders in the preset dictionary table.
2. The backend language switching method according to claim 1, characterized in that: If the response data of the target interface of the backend is intercepted, the path information corresponding to the target interface is obtained, and the path information is matched with the preset interface field table to determine the switchable field, including: Determine whether there is a target interface for data feedback among the multiple data interfaces of the back end, and if the target interface exists, intercept data of the target interface to obtain response data fed back by the target interface; Path information corresponding to the target interface is obtained, and the path information is matched with a preset interface field table to determine a switchable field type corresponding to the target interface, and a switchable field is determined according to the switchable field type.
3. The backend language switching method according to claim 1, characterized in that: The determining, based on the switchable fields, a plurality of fields to be converted in the response data, and determining a current language and a language to be converted corresponding to the response data, so as to match the plurality of fields to be converted with a preset dictionary table based on the language to be converted, includes: Extracting a number of fields to be converted corresponding to the switchable fields in the response data; Determine the current language corresponding to the response data, and determine the language to be converted corresponding to the response data according to the received language conversion instruction; The plurality of to-be-converted fields are matched with fields corresponding to the to-be-converted languages in a preset dictionary table.
4. The backend language switching method according to claim 1, characterized in that: If there is a complete match, replacing the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table comprises: If the plurality of to-be-converted fields completely match the fields corresponding to the to-be-converted language in the preset dictionary table, extracting a plurality of first target conversion fields corresponding to the plurality of to-be-converted fields from the preset dictionary table; the plurality of first target conversion fields are fields corresponding to the to-be-converted language; The plurality of to-be-converted fields are replaced based on the plurality of first target conversion fields.
5. The backend language switching method according to claim 1, characterized in that: If the complete match cannot be made, determining a plurality of first fields to be converted corresponding to the current language and a plurality of second fields to be converted representing symbols among the plurality of fields to be converted, and replacing the plurality of first fields to be converted by a plurality of second target conversion fields corresponding to the plurality of first fields to be converted in the preset dictionary table, and replacing the plurality of second fields to be converted by a preset placeholder in the preset dictionary table, including: If the plurality of fields to be converted cannot completely match the fields corresponding to the language to be converted in the preset dictionary table, extracting a plurality of first fields to be converted corresponding to the current language from the plurality of fields to be converted, and using the fields that do not match the current language from the plurality of fields to be converted as a plurality of second fields to be converted representing symbols; Matching the first to-be-converted fields with the preset dictionary table to determine the second target conversion fields corresponding to the first to-be-converted fields, and replacing the first to-be-converted fields with the second target conversion fields; A placeholder in the preset dictionary table is extracted, and the plurality of second fields to be converted are replaced by the placeholder.
6. The backend language switching method according to claim 5, characterized in that: Also includes: If the plurality of to-be-converted fields cannot completely match the fields corresponding to the to-be-converted language in the preset dictionary table, and the plurality of first to-be-converted fields cannot completely match the preset dictionary table, then the backend language switching is exited.
7. The backend language switching method according to any one of claims 1 to 6, characterized in that: Also includes: If a new language request is received, determining a target new language corresponding to the new language request, and obtaining a target new language package corresponding to the target new language; The preset dictionary table is updated based on the target new language package, so as to provide a language switching service corresponding to the target new language based on the obtained updated dictionary table.
8. A back-end language switching device, characterized in that: include: An information matching module, for obtaining path information corresponding to the target interface if the response data of the target interface of the back end is intercepted, and matching the path information with the preset interface field table to determine the switchable field; A field matching module, which determines a number of to-be-converted fields in the response data based on the switchable fields, and determines a current language and a to-be-converted language corresponding to the response data, so as to match the number of to-be-converted fields with a preset dictionary table based on the to-be-converted language; A first field conversion module, configured to replace the plurality of fields to be converted based on a plurality of first target conversion fields corresponding to the plurality of fields to be converted in the preset dictionary table if there is a complete match; The second field conversion module is used to determine, if a complete match cannot be made, several first fields to be converted corresponding to the current language and several second fields to be converted representing symbols among the several fields to be converted, and replace the several first fields to be converted with several second target conversion fields corresponding to the several first fields to be converted in the preset dictionary table, and replace the several second fields to be converted with preset placeholders in the preset dictionary table.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the backend language switching method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the backend language switching method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method and device for realizing web front-end project language conversion and medium
CN111859201A
Language switching method and device, electronic equipment and storage medium
CN115098200A
Content replacement method and device, equipment and storage medium
CN116501855A
Application internationalization implementation method and device, electronic equipment and storage medium
CN118276971A
International language dynamic switching method based on back end
CN118410814A
Cited By
Enterprise application internationalization method and device based on meta-model context awareness, equipment and storage medium
CN121579123A