Dynamic language switching method, device and system
By performing language configuration updates, text refreshes, and translation processing in the HarmonyOS NEXT system, the problem of low language switching efficiency is solved, the accuracy and efficiency of dynamic language switching are improved, and the development process is simplified.
Patent Information
- Application Number
- CN202510469050.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-15
- Publication Date
- 2025-09-12
AI Technical Summary
The existing language switching method in the HarmonyOS NEXT system has problems such as update omissions, low efficiency and easy errors. In particular, when multiple layers of components are nested, it is impossible to achieve cross-page/module linkage updates.
In the HarmonyOS NEXT system, based on the application initialization results and language selection operations, language configuration updates are performed, the language change callback function is determined, and dynamic language switching is achieved through UI text refresh and translation text processing, including language configuration updates, text refresh responses, translation text processing and UI component display updates.
It improves the accuracy and efficiency of language switching, reduces the error rate of page synchronization updates, improves the UI component refresh efficiency and development convenience, and simplifies business component code.
Smart Images

Figure CN120631476A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a dynamic language switching method, device and system. Background Art
[0002] With the acceleration of globalization and the popularization of artificial intelligence technology, more and more websites and applications need to provide multilingual support. The language switching function is a key module for realizing global services.
[0003] At present, the language switching method is mainly used when the system language needs to be switched, especially in the HarmonyOS NEXT system (this system is the latest operating system launched by Huawei, whose core features include multi-device interconnection capabilities, deep integration of AI and operating systems, and privacy protection functions. This system aims to create a full-scene intelligent operating system in the era of intelligent connection of all things, and has also made significant progress in ecological construction). The staff manually traverses all components to call updates, and the update task is heavy. When nesting multiple layers of components, it is easy to miss updates, and cross-page / module linkage updates cannot be achieved. It is time-consuming, labor-intensive and error-prone. Therefore, the existing language switching method has problems with the accuracy and efficiency of language switching. It can be seen that it is particularly important to provide a new language switching method to improve the accuracy and efficiency of the system's language switching. Summary of the Invention
[0004] The present invention provides a dynamic language switching method, device and system, which can improve the language switching accuracy and language switching efficiency of systems and applications.
[0005] To solve the above technical problems, the first aspect of the present invention discloses a dynamic language switching method. The method is applied to an electronic device equipped with a HarmonyOS NEXT system, wherein the electronic device has an application program of a target application installed therein, and the electronic device is communicatively connected to a network attached storage device, and the electronic device can access the network attached storage device through the application program. The method comprises:
[0006] When the target application needs to switch the language, based on the predetermined application initialization result of the target application and the detected language selection operation, a corresponding language configuration update operation is performed on the target application to obtain a language configuration update result;
[0007] Determine a language change callback function according to the language configuration update result, and perform a corresponding UI text refresh operation based on the determined target event listening component and the language change callback function to obtain a UI text refresh result;
[0008] Determining a text content requirement form according to the determined text application scenario, and performing corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, a preset translation result acquisition method, and a preset translation result access method to obtain a translation text processing result;
[0009] Based on the translated text processing result, a corresponding UI component display update operation is performed to achieve language switching of the target application.
[0010] As an optional implementation, in the first aspect of the present invention, performing a corresponding language configuration update operation on the target application based on the predetermined application initialization result of the target application and the detected language selection operation to obtain a language configuration update result includes:
[0011] Determining current language configuration information of the target application according to a predetermined application initialization result of the target application, and performing a corresponding language information normalization processing operation on the current language configuration information to obtain a language normalization processing result;
[0012] Determining target required language configuration information corresponding to the target application based on the detected language selection operation and a preset basic language setting method;
[0013] Based on the language normalization processing result, the target required language configuration information and the preset internationalized program language setting method, a corresponding language setting operation is performed on the target application to obtain a language configuration update result.
[0014] As an optional embodiment, in the first aspect of the present invention, performing corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, the preset translation result acquisition method, and the preset translation result access method to obtain the translation text processing result includes:
[0015] According to the text content requirement form, the preset translation result acquisition method and the UI text refresh result, a corresponding translation text acquisition operation is performed to obtain a first returned translation result; the text content requirement form includes one of a singular translation text form, a plural translation text form and a character string form;
[0016] According to the preset translation result access method and the first returned translation result, a corresponding multilingual resource acquisition operation is performed to obtain a second returned translation result;
[0017] performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result;
[0018] The translation text processing result is determined according to the third returned translation result.
[0019] As an optional embodiment, in the first aspect of the present invention, performing a corresponding translation text acquisition operation based on the text content requirement form, a preset translation result acquisition method, and the UI text refresh result to obtain a first returned translation result includes:
[0020] When the text content requirement form includes the singular translation text form, determining the first form translation text as the first returned translation result according to the UI text refresh result and the preset first text acquisition method;
[0021] When the text content requirement form includes the plural translation text form, determining the second form translation text according to the UI text refresh result and the preset second text acquisition method as the first returned translation result;
[0022] When the text content required form includes the character string form, a third form translation text is determined according to the UI text refresh result and a preset third text acquisition method as the first returned translation result.
[0023] As an optional embodiment, in the first aspect of the present invention, the method further comprises:
[0024] When it is detected that the target application is started, the corresponding singleton initialization and language loading operations are performed on the internationalization manager corresponding to the target application to obtain the application initialization result corresponding to the target application;
[0025] Furthermore, performing corresponding singleton initialization and language loading operations on the internationalization manager corresponding to the target application to obtain an application initialization result corresponding to the target application includes:
[0026] Based on the target application and its corresponding internationalization manager, executing a corresponding unique instance call operation on a class responsible for managing internationalization functions to obtain a first initialization result;
[0027] Performing corresponding internal state initialization operations on the event monitoring device and resource management module included in the internationalization manager to obtain a second initialization result;
[0028] Performing a corresponding default language configuration loading operation on the target application and its corresponding internationalization manager to obtain a third initialization result;
[0029] An application initialization result corresponding to the target application is determined according to the first initialization result, the second initialization result, and the third initialization result.
[0030] As an optional implementation manner, in the first aspect of the present invention, determining a language change callback function according to the language configuration update result includes:
[0031] Generate a target trigger event according to the language configuration update result;
[0032] According to the target triggering event, a language change callback function is determined from one or more preset callback functions.
[0033] As an optional embodiment, in the first aspect of the present invention, after performing a corresponding multilingual resource acquisition operation according to the preset translation result access method and the first returned translation result to obtain a second returned translation result, the method further includes:
[0034] determining placeholder content information according to the second returned translation result;
[0035] Determining, based on the placeholder content information, whether the second returned translation result satisfies a preset placeholder content replacement condition;
[0036] When it is determined that the second returned translation result satisfies the placeholder content replacement condition, performing the step of performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result;
[0037] When it is determined that the second returned translation result does not satisfy the placeholder content replacement condition, a translation text processing result is determined based on the second returned translation result.
[0038] A second aspect of the present invention discloses a dynamic language switching device, comprising an electronic device equipped with a HarmonyOS NEXT system, wherein an application program for a target application is installed in the electronic device, and the electronic device is communicatively connected to a network attached storage device, wherein the electronic device can access the network attached storage device through the application program, and the device comprises:
[0039] a language configuration update module configured to, when language switching of the target application is required, perform a corresponding language configuration update operation on the target application based on a predetermined application initialization result of the target application and a detected language selection operation, and obtain a language configuration update result;
[0040] A text refresh module is used to determine a language change callback function according to the language configuration update result, and perform a corresponding UI text refresh operation based on the determined target event listening component and the language change callback function to obtain a UI text refresh result;
[0041] A text processing module is used to determine the text content requirement form according to the determined text application scenario, and based on the text content requirement form, a preset translation result acquisition method and a preset translation result access method, perform corresponding translation text processing operations on the UI text refresh result to obtain a translation text processing result;
[0042] The display update module is used to perform a corresponding UI component display update operation based on the translation text processing result to achieve language switching of the target application.
[0043] As an optional implementation, in the second aspect of the present invention, the language configuration update module performs a corresponding language configuration update operation on the target application based on a predetermined application initialization result of the target application and a detected language selection operation, and the manner of obtaining the language configuration update result specifically includes:
[0044] Determining current language configuration information of the target application according to a predetermined application initialization result of the target application, and performing a corresponding language information normalization processing operation on the current language configuration information to obtain a language normalization processing result;
[0045] Determining target required language configuration information corresponding to the target application based on the detected language selection operation and a preset basic language setting method;
[0046] Based on the language normalization processing result, the target required language configuration information and the preset internationalized program language setting method, a corresponding language setting operation is performed on the target application to obtain a language configuration update result.
[0047] As an optional embodiment, in the second aspect of the present invention, the text processing module performs corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, the preset translation result acquisition method, and the preset translation result access method. The method of obtaining the translation text processing result specifically includes:
[0048] According to the text content requirement form, the preset translation result acquisition method and the UI text refresh result, a corresponding translation text acquisition operation is performed to obtain a first returned translation result; the text content requirement form includes one of a singular translation text form, a plural translation text form and a character string form;
[0049] According to the preset translation result access method and the first returned translation result, a corresponding multilingual resource acquisition operation is performed to obtain a second returned translation result;
[0050] performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result;
[0051] The translation text processing result is determined according to the third returned translation result.
[0052] As an optional embodiment, in the second aspect of the present invention, the text processing module performs a corresponding translation text acquisition operation based on the text content requirement form, a preset translation result acquisition method, and the UI text refresh result, and the method for obtaining the first returned translation result specifically includes:
[0053] When the text content requirement form includes the singular translation text form, determining the first form translation text as the first returned translation result according to the UI text refresh result and the preset first text acquisition method;
[0054] When the text content requirement form includes the plural translation text form, determining the second form translation text according to the UI text refresh result and the preset second text acquisition method as the first returned translation result;
[0055] When the text content required form includes the character string form, a third form translation text is determined according to the UI text refresh result and a preset third text acquisition method as the first returned translation result.
[0056] As an optional embodiment, in the second aspect of the present invention, the device further includes:
[0057] An application initialization module is configured to, when detecting that a target application is started, perform corresponding singleton initialization and language loading operations on the internationalization manager corresponding to the target application, and obtain an application initialization result corresponding to the target application;
[0058] Furthermore, the application initialization module performs corresponding singleton initialization and language loading operations on the internationalization manager corresponding to the target application, and obtains the application initialization result corresponding to the target application in a manner specifically including:
[0059] Based on the target application and its corresponding internationalization manager, executing a corresponding unique instance call operation on a class responsible for managing internationalization functions to obtain a first initialization result;
[0060] Performing corresponding internal state initialization operations on the event monitoring device and resource management module included in the internationalization manager to obtain a second initialization result;
[0061] Performing a corresponding default language configuration loading operation on the target application and its corresponding internationalization manager to obtain a third initialization result;
[0062] An application initialization result corresponding to the target application is determined according to the first initialization result, the second initialization result, and the third initialization result.
[0063] As an optional implementation, in the second aspect of the present invention, the text refresh module determines the language change callback function according to the language configuration update result in a manner that specifically includes:
[0064] Generate a target trigger event according to the language configuration update result;
[0065] According to the target triggering event, a language change callback function is determined from one or more preset callback functions.
[0066] As an optional implementation, in the second aspect of the present invention, the text processing module is further configured to, after performing the corresponding multilingual resource acquisition operation according to the preset translation result access method and the first returned translation result to obtain the second returned translation result, determine the placeholder content information according to the second returned translation result; determine, based on the placeholder content information, whether the second returned translation result meets the preset placeholder content replacement condition; when it is determined that the second returned translation result meets the placeholder content replacement condition, perform the step of performing the corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result; when it is determined that the second returned translation result does not meet the placeholder content replacement condition, determine the translation text processing result according to the second returned translation result.
[0067] A third aspect of the present invention discloses an electronic device, comprising:
[0068] a memory storing executable program code;
[0069] a processor coupled to the memory;
[0070] The processor calls the executable program code stored in the memory to execute a dynamic language switching method disclosed in the first aspect of the present invention.
[0071] A fourth aspect of the present invention discloses a computer storage medium, wherein the computer storage medium stores computer instructions. When the computer instructions are called, they are used to execute a dynamic language switching method disclosed in the first aspect of the present invention.
[0072] A fifth aspect of the present invention discloses a dynamic language switching system, the system comprising a dynamic language switching device disclosed in the second aspect of the present invention, and a network attached storage device communicatively connected to the device; or
[0073] The system includes the electronic device disclosed in the third aspect of the present invention, and a network attached storage device communicatively connected to the electronic device.
[0074] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0075] In an embodiment of the present invention, when it is necessary to switch the language of a target application, based on a predetermined application initialization result of the target application and a detected language selection operation, a corresponding language configuration update operation is performed on the target application to obtain a language configuration update result; based on the language configuration update result, a language change callback function is determined, and based on the determined target event listening component and the language change callback function, a corresponding UI text refresh operation is performed to obtain a UI text refresh result; based on the determined text application scenario, a text content requirement form is determined, and based on the text content requirement form, a preset translation result acquisition method, and a preset translation result access method, a corresponding translation text processing operation is performed on the UI text refresh result to obtain a translation text processing result; based on the translation text processing result, a corresponding UI component display update operation is performed to achieve language switching of the target application. It can be seen that the present invention can realize the dynamic language switching function through the language configuration update link, the text refresh response link, the translation text processing link and the UI component display update link, which is conducive to improving the comprehensiveness, integrity and rationality of the dynamic language switching method of the system application, and thus is conducive to improving the language switching efficiency and convenience of the system application, as well as the language switching accuracy and reliability of the system application, thereby helping to improve the refresh efficiency and convenience of the UI component, reduce the page synchronization update error rate, and in addition, help to improve the development convenience and simplicity, and improve the simplicity of business component code. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0077] Figure 1 This is a flow chart of a dynamic language switching method disclosed in an embodiment of the present invention;
[0078] Figure 2 This is a flow chart of another dynamic language switching method disclosed in an embodiment of the present invention;
[0079] Figure 3 This is a structural diagram of a dynamic language switching device disclosed in an embodiment of the present invention;
[0080] Figure 4 is a structural diagram of another dynamic language switching device disclosed in an embodiment of the present invention;
[0081] Figure 5 It is a structural diagram of an electronic device disclosed in an embodiment of the present invention;
[0082] Figure 6 The diagram is a schematic diagram of the system structure relationship of a dynamic language switching system disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0083] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of 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. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0084] The terms "first," "second," and so on, in the description and claims of the present invention and the accompanying drawings are used to distinguish between different items, not to describe a specific order. Furthermore, the terms "including," "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, apparatus, product, or end comprising a series of steps or elements is not limited to the listed steps or elements but may optionally include steps or elements not listed therein, or may optionally include other steps or elements inherent to such process, method, product, or end.
[0085] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present invention. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute a separate or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0086] The present invention discloses a dynamic language switching method, device, and system, which can realize dynamic language switching functions through language configuration update links, text refresh response links, translation text processing links, and UI component display update links, etc., which is conducive to improving the comprehensiveness, integrity, and rationality of the dynamic language switching method of system applications, thereby improving the efficiency and convenience of language switching in system applications, as well as improving the accuracy and reliability of language switching in system applications, thereby improving the efficiency and convenience of UI component refresh and reducing the error rate of page synchronization update. In addition, it is conducive to improving development convenience and simplicity, and improving the simplicity of business component code. Detailed descriptions are given below.
[0087] Example 1
[0088] See also Figure 1 , Figure 1 This is a flow chart of a dynamic language switching method disclosed in an embodiment of the present invention. Figure 1 The described method can be applied to an electronic device equipped with the HarmonyOS NEXT system, in which an application program of the target application is installed, and the electronic device is in communication connection with a network attached storage device, and the electronic device can access the network attached storage device through the application program, which is not limited in the embodiment of the present invention. Figure 1 As shown, the dynamic language switching method includes the following operations:
[0089] 101. When language switching of a target application is required, a corresponding language configuration update operation is performed on the target application based on a predetermined application initialization result of the target application and a detected language selection operation to obtain a language configuration update result.
[0090] Optionally, the language selection operation detected above is illustrated as follows: the user selects a new language and calls the setLanguage(language) method to trigger language switching, which is not limited in this embodiment of the present invention.
[0091] Optionally, the above-mentioned execution of a corresponding language configuration update operation on the target application to obtain a language configuration update result is illustrated as follows: updating the system language configuration and sending an emitter event, which is not limited in the embodiment of the present invention.
[0092] Optionally, the dynamic update of the language configuration and the real-time refresh of the UI text are achieved through an emitter event-driven mechanism, which is not limited in the embodiment of the present invention.
[0093] 102. Determine a language change callback function according to the language configuration update result, and execute a corresponding UI text refresh operation based on the determined target event monitoring component and the language change callback function to obtain a UI text refresh result.
[0094] Optionally, the above-mentioned execution of a corresponding text refresh response operation is illustrated by an example: the event monitoring component executes the onLanguageChange() callback function to refresh the UI text, which is not limited in the embodiment of the present invention.
[0095] Optionally, for example: when an emitter event (i.e., a language switching event) is triggered, the onLanguageChange() callback function is executed. In the callback function, the UI text is refreshed to ensure that the displayed content is consistent with the new language; that is, when a language switching event is triggered, the callback function callback is executed to update the UI language display to ensure that the UI component responds to language switching in real time, thereby improving the user experience. This is not limited in the embodiments of the present invention.
[0096] Optionally, this step can implement the UI text refresh function based on the event listening component and the language change callback function, and realize dynamic UI update through the event-driven mechanism without restarting the application or component, which is conducive to improving the refresh efficiency and timeliness of the UI text, and thus helps to improve the timeliness, real-timeness and efficiency of the UI component in responding to language switching, thereby ensuring that the UI component responds to language switching in real time, improving user experience, and supporting multi-module collaborative updates, which is not limited in the embodiments of the present invention.
[0097] 103. According to the determined text application scenario, determine the text content requirement form, and based on the text content requirement form, the preset translation result acquisition method and the preset translation result access method, perform corresponding translation text processing operations on the UI text refresh result to obtain the translation text processing result.
[0098] Optionally, the above-mentioned corresponding translation text processing operation is performed on the UI text refresh result. For example, the tr() or trPlural() method or the getStringSync() method is called, multilingual resources are obtained through $r(), and placeholder replacement is processed. This embodiment of the present invention is not limited thereto.
[0099] 104. Based on the translated text processing result, perform corresponding UI component display update operations to achieve language switching of the target application.
[0100] Optionally, the above-mentioned execution of the corresponding UI component display update operation is illustrated as follows: displaying the processed translated text in the UI component to complete the language switch, which is not limited in this embodiment of the present invention.
[0101] Optional, Figure 6This is a schematic diagram of the system structure relationship of a dynamic language switching system disclosed in an embodiment of the present invention. Specifically, this solution can be applied to the App internationalization system of the HarmonyOS NEXT ArkTS programming language. The external modules / components using the internationalization function involved in this solution, such as pages, UI components or other functional modules in the application, rely on / call the internationalization function of UgI18nManager; UgI18nManager is the core management module of the internationalization function, which adopts the singleton mode to ensure the global unique instance, implements the system i18n interface and includes the emitter event processing function for processing events such as language switching; the system i18n interface is the underlying interface of the internationalization function, and the system i18n interface includes i18n.System and resourceManager; i18n.System provides system-level Internationalization support, such as system language settings, decouples internationalization functions from the underlying system interface to improve flexibility and scalability; resourceManager: responsible for managing international resource files (such as multilingual texts), separating the specific implementation of internationalization functions from the underlying interface to facilitate maintenance and expansion; specific implementation methods of internationalization functions include: tr(): used to obtain the translated text in singular form; trPlural(): used to obtain the translated text in plural form; getRequestLanguage(): used to obtain the requested language and execute the language specification conversion logic to ensure the standardization of the language code and improve the accuracy and compatibility of the internationalization function, which is not limited in the embodiments of the present invention.
[0102] Optionally, this solution uses an event bus-driven global language state management architecture, combined with a singular-plural dynamic parameterization processing engine and an intelligent language identification conversion system, to achieve millisecond-level response for cross-component language switching, automatic adaptation of multi-language plural rules, and seamless compatibility of server-side interface language protocols, forming a full-link closed-loop internationalization solution for the HarmonyOS NEXT system App from resource loading, state synchronization to interface communication, which is not limited in the embodiments of the present invention.
[0103] Optionally, the language switching logic is decoupled from the UI update through modular design and event-driven mechanism to improve the flexibility and maintainability of the code, which is not limited in the embodiment of the present invention.
[0104] Optionally, the practical application of this solution can be achieved through the UG_I18N_LANGUAGE_CHANGE global event bus: improved response speed: the average UI refresh time after language switching is reduced from the native 420ms of ArkTS to 150ms (measured data), code simplicity: the amount of business component code is reduced by 68% (no need to write update monitoring logic), error rate reduction: the failure rate of multi-page synchronous update is reduced from 12% to 0.3%; enhanced complex number processing system, multi-parameter support: can handle complex statements such as %dapples, %d oranges, asynchronous to synchronous optimization: loading time is reduced from 210ms±50ms of ArkTS to 80ms±20ms, development convenience: through trPlural(key,nums) encapsulation call, the amount of code is reduced by 55%; streamlined repeated calling code: through tr('key') call, the writing of repeated code is reduced, and the embodiment of the present invention is not limited.
[0105] It can be seen that the dynamic language switching method described in the embodiment of the present invention can realize the dynamic language switching function through the language configuration update link, the text refresh response link, the translation text processing link and the UI component display update link, which is conducive to improving the comprehensiveness, integrity and rationality of the dynamic language switching method of the system application, and thus is conducive to improving the language switching efficiency and convenience of the system application, as well as improving the language switching accuracy and reliability of the system application, thereby helping to improve the UI component refresh efficiency and convenience, reduce the page synchronization update error rate, and in addition, is conducive to improving the development convenience and simplicity, and improving the simplicity of business component code.
[0106] In an optional embodiment, the above-mentioned performing a corresponding language configuration update operation on the target application based on the predetermined application initialization result of the target application and the detected language selection operation to obtain the language configuration update result may include:
[0107] Determining current language configuration information of the target application according to a predetermined application initialization result of the target application, and performing a corresponding language information normalization processing operation on the current language configuration information to obtain a language normalization processing result;
[0108] Determine target language configuration information corresponding to the target application based on the detected language selection operation and the preset basic language setting method;
[0109] Based on the language normalization processing result, the target required language configuration information and the preset international program language setting method, the corresponding language setting operation is performed on the target application to obtain the language configuration update result.
[0110] Optionally, language standard conversion is implemented through the getRequestLanguage() method to ensure the standardization of the language code, which is not limited in the embodiment of the present invention.
[0111] Optionally, the above-mentioned current language configuration information of the target application is determined based on the application initialization result of the predetermined target application. For example, the i18n.System.getAppLanguage() method is called to obtain the current language configuration information of the target application. Furthermore, the current language configuration information, such as the system language set by the user or the application default language, is not limited in the embodiment of the present invention.
[0112] Optionally, the above performs corresponding language information normalization processing operations on the current language configuration information, for example: converting en-US to en; further, returning the normalized language code for use by the application, which is not limited in the embodiment of the present invention.
[0113] Optionally, the above-mentioned target required language configuration information corresponding to the target application is determined based on the detected language selection operation and the preset basic language setting method. For example: calling the setLanguage(language) method to set a new language configuration, that is, the target required language configuration information, which is not limited in the embodiment of the present invention.
[0114] Optionally, the above-mentioned corresponding language setting operations are performed on the target application, for example: updating the system language configuration, such as calling i18n.System.setAppLanguage(language); sending an emitter event to trigger the UG_I18N_LANGUAGE_CHANGE event to notify all listeners that the language has been switched; updating the internal language state of the application to ensure that subsequent operations use the new language; this is not limited in the embodiment of the present invention.
[0115] It can be seen that this optional embodiment can realize the language configuration update function through language information normalization processing operations and language setting operations, which is conducive to improving the comprehensiveness and rationality of the language configuration update method, and then conducive to improving the accuracy and reliability of the language configuration update, thereby conducive to improving the compatibility and consistency of the language code, and conducive to improving the diversity and flexibility of the language format.
[0116] In another optional embodiment, the above-mentioned performing corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, the preset translation result acquisition method, and the preset translation result access method to obtain the translation text processing result may include:
[0117] According to the text content requirement form, the preset translation result acquisition method and the UI text refresh result, a corresponding translation text acquisition operation is performed to obtain a first returned translation result; the text content requirement form includes one of a singular translation text form, a plural translation text form and a character string form;
[0118] According to the preset translation result access method and the first returned translation result, a corresponding multilingual resource acquisition operation is performed to obtain a second returned translation result;
[0119] Performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result;
[0120] The translation text processing result is determined according to the third returned translation result.
[0121] Optionally, for the preset translation result acquisition method, multiple resource calling methods are provided to meet the needs of different scenarios. Specifically, when the text application scenario is static text or a scenario that does not require translation, the text content requirement form is a string form; when the text application scenario is in a singular form and requires translation, the text content requirement form is a singular translation text form; when the text application scenario is in a plural form and requires translation, the text content requirement form is a plural translation text form. The embodiments of the present invention do not limit this.
[0122] Optionally, the translation result access method may be a $r() method. Specifically, multilingual resources are obtained through $r(), which is not limited in the embodiment of the present invention.
[0123] Optionally, the above-mentioned corresponding placeholder processing operation is performed on the second returned translation result, for example: processing placeholder replacement, such as replacing {name} with an actual value; further, returning the processed translation text for display by the UI component, which is not limited in this embodiment of the present invention.
[0124] It can be seen that this optional embodiment can determine the translation text processing result through translation text acquisition operations, multilingual resource acquisition operations and placeholder processing operations, which is conducive to improving the comprehensiveness and rationality of the translation text processing result determination method, and thus is conducive to improving the accuracy and reliability of the determined translation text processing results, thereby helping to improve the accuracy and readability of the translation text. In addition, it is proposed that the text content requirement form includes one of the singular translation text form, plural translation text form and character string form, and provides multiple resource calling methods to meet the needs of different scenarios.
[0125] In another optional embodiment, the above-mentioned performing corresponding translation text acquisition operations based on the text content requirement form, the preset translation result acquisition method, and the UI text refresh result to obtain the first returned translation result may include:
[0126] When the required text content format includes a singular translation text format, the first format translation text is determined according to the UI text refresh result and the preset first text acquisition method as the first returned translation result;
[0127] When the required text content format includes plural translation text formats, the second format translation text is determined according to the UI text refresh result and the preset second text acquisition method, and is returned as the first translation result;
[0128] When the required text content format includes a character string format, a third format translation text is determined according to the UI text refresh result and a preset third text acquisition method, and is returned as the first translation result.
[0129] Optionally, the first text acquisition method may correspond to the tr() method; the second text acquisition method may correspond to the trPlural() method; the third text acquisition method may correspond to the getStringSync() method, which is applicable to scenarios where static text or no translation is required, and is not limited in the embodiments of the present invention.
[0130] Optionally, the above method determines the first form of translated text based on the UI text refresh result and the preset first text acquisition method as the first returned translation result. For example, the singular form of the translated text is obtained from the Mapp.strings resource file, and the corresponding translation result is returned according to the current language. This embodiment of the present invention is not limited to this.
[0131] Optionally, the second form of translated text is determined based on the UI text refresh result and the preset second text acquisition method, and is returned as the first translation result. For example: the plural form of the translated text is obtained from the Mapp.plurals resource file, and the corresponding translation result is returned according to the current language and quantity. This embodiment of the present invention is not limited to this.
[0132] Optionally, the third form of translated text is determined based on the UI text refresh result and the preset third text acquisition method as the first returned translation result. For example, the string value is directly obtained without relying on the resource file, which is not limited in the embodiment of the present invention.
[0133] It can be seen that this optional embodiment can match corresponding translation text determination methods according to the text content requirement forms including singular translation text form, plural translation text form and character string form, which is conducive to improving the diversity, flexibility and pertinence of the translation text determination method, and thus is conducive to improving the accuracy and reliability of the determined translation text, thereby helping to improve the accuracy and reliability of the first returned translation result.
[0134] In yet another optional embodiment, the above-mentioned determining of the language change callback function according to the language configuration update result may include:
[0135] Generate target trigger events based on language configuration update results;
[0136] According to the target trigger event, a language change callback function is determined from one or more preset callback functions.
[0137] Optionally, UgI18nManager includes an emitter event processing function to support dynamic language switching; further, in a module that needs to monitor language switching, the event monitoring component registers a listener through emitter.on('UG_I18N_LANGUAGE_CHANGE', callback), which is not limited in this embodiment of the present invention.
[0138] Optionally, the language change callback function is exemplified by the onLanguageChange() callback function, which is not limited in this embodiment of the present invention.
[0139] Optionally, after updating the system language configuration and obtaining the language configuration update result, trigger / send an emitter event to notify all listeners that the language has been switched; when the emitter event is triggered (i.e., the corresponding target trigger event), execute the onLanguageChange() callback function; further, it is necessary to pre-execute: the event listening component registers the listener through emitter.on('UG_I18N_LANGUAGE_CHANGE', callback), which is not limited in this embodiment of the present invention.
[0140] It can be seen that this optional embodiment can generate a target trigger event based on the language configuration update result and then determine the language change callback function, which is beneficial to improving the comprehensiveness and rationality of the method for determining the language change callback function, and further beneficial to improving the accuracy and reliability of the determined language change callback function.
[0141] In yet another optional embodiment, after performing the corresponding multilingual resource acquisition operation according to the preset translation result access mode and the first returned translation result to obtain the second returned translation result, the method may further include the following operations:
[0142] Determining placeholder content information according to the second returned translation result;
[0143] Determining whether the second returned translation result satisfies a preset placeholder content replacement condition based on the placeholder content information;
[0144] When it is determined that the second returned translation result satisfies the placeholder content replacement condition, a step of performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result;
[0145] When it is determined that the second returned translation result does not meet the placeholder content replacement condition, a translation text processing result is determined based on the second returned translation result.
[0146] Optionally, the above-mentioned determining whether the second returned translation result satisfies a preset placeholder content replacement condition based on the placeholder content information may include:
[0147] Determining, based on the placeholder content information, whether the second returned translation result has target content that needs to be supplemented with actual values;
[0148] When it is determined that the second returned translation result contains target content that needs to be supplemented with an actual value, determining that the second returned translation result satisfies a placeholder content replacement condition;
[0149] When it is determined that the second returned translation result does not have target content that needs to be supplemented with an actual value, it is determined that the second returned translation result does not meet the placeholder content replacement condition.
[0150] It can be seen that this optional embodiment can execute the corresponding placeholder processing operation when it is determined that the placeholder content replacement conditions are met, and directly determine the translation text processing result when it is determined that the placeholder content replacement conditions are not met. This is conducive to improving the timeliness, accuracy and rationality of the execution of the placeholder content processing operation, and thus is conducive to improving the processing accuracy and efficiency of the placeholder content, reducing unnecessary processing operations and the resulting waste of resources, thereby helping to improve the accuracy and reliability of the determined translation text processing results, and to a certain extent, helping to improve the efficiency and convenience of determining the translation text processing results.
[0151] Example 2
[0152] See also Figure 2 , Figure 2 This is a flow chart of another dynamic language switching method disclosed in an embodiment of the present invention. Figure 2 The described method can be applied to an electronic device equipped with the HarmonyOS NEXT system, in which an application program of the target application is installed, and the electronic device is in communication connection with a network attached storage device, and the electronic device can access the network attached storage device through the application program, which is not limited in the embodiment of the present invention. Figure 2 As shown, the dynamic language switching method includes the following operations:
[0153] 201. When it is detected that the target application is started, corresponding singleton initialization and language loading operations are performed on the internationalization manager corresponding to the target application to obtain an application initialization result corresponding to the target application.
[0154] Optionally, for example, initializing a singleton instance of UgI18nManager (i.e., the internationalization manager corresponding to the target application) and loading a default language configuration are described, which is not limited in the embodiment of the present invention.
[0155] 202. When language switching of the target application is required, a corresponding language configuration update operation is performed on the target application based on the predetermined application initialization result of the target application and the detected language selection operation to obtain a language configuration update result.
[0156] 203. Determine a language change callback function according to the language configuration update result, and execute a corresponding UI text refresh operation based on the determined target event monitoring component and the language change callback function to obtain a UI text refresh result.
[0157] 204. Determine the text content requirement form according to the determined text application scenario, and perform corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, the preset translation result acquisition method, and the preset translation result access method to obtain the translation text processing result.
[0158] 205. Based on the translated text processing result, perform corresponding UI component display update operations to implement language switching of the target application.
[0159] In the embodiment of the present invention, for other descriptions of steps 201 to 205, please refer to the other detailed descriptions of steps 101 to 104 in the first embodiment, which will not be repeated in the embodiment of the present invention.
[0160] It can be seen that the embodiment of the present invention can realize the dynamic language switching function through the language configuration update link, the text refresh response link, the translation text processing link and the UI component display update link, which is conducive to improving the comprehensiveness, integrity and rationality of the dynamic language switching method of the system application, and thus is conducive to improving the language switching efficiency and convenience of the system application, and is conducive to improving the language switching accuracy and reliability of the system application, thereby helping to improve the refresh efficiency and convenience of the UI component, and reducing the error rate of page synchronization update. In addition, it is conducive to improving development convenience and simplicity, and improving the simplicity of business component code; and it can also provide an application initialization processing method, which is conducive to improving the comprehensiveness, integrity and rationality of a dynamic language switching method, and thus is conducive to ensuring that the language state is consistent when the application starts, adopting a singleton mode, reducing memory usage, and improving resource utilization.
[0161] In an optional embodiment, performing corresponding singleton initialization and language loading operations on the internationalization manager corresponding to the target application to obtain an application initialization result corresponding to the target application may include:
[0162] Based on the target application and its corresponding internationalization manager, executing a corresponding call operation on a unique instance of a class responsible for managing internationalization functions to obtain a first initialization result;
[0163] Performing corresponding internal state initialization operations on the event monitoring device and resource management module included in the internationalization manager to obtain a second initialization result;
[0164] Performing a corresponding default language configuration loading operation on the target application and its corresponding internationalization manager to obtain a third initialization result;
[0165] An application initialization result corresponding to the target application is determined according to the first initialization result, the second initialization result, and the third initialization result.
[0166] Optionally, the above-mentioned internationalization manager based on the target application and its corresponding internationalization manager executes the corresponding unique instance call operation for the class responsible for managing the internationalization function to obtain the first initialization result. For example: when the application starts, the UgI18nManager.getInstance() method is called to ensure a globally unique instance, which is not limited in the embodiment of the present invention.
[0167] Optionally, the above-mentioned internal state initialization operation is performed on the event listening device and resource management module included in the internationalization manager to obtain a second initialization result. For example, the internal state of UgI18nManager is initialized, including the event listener (emitter) and the resource management module, which is not limited in the embodiment of the present invention.
[0168] Optionally, the above-mentioned default language configuration loading operation is performed on the target application and its corresponding internationalization manager to obtain a third initialization result. For example, the default language configuration is loaded to ensure that the language state is consistent when the application is started. This embodiment of the present invention is not limited thereto.
[0169] It can be seen that this optional embodiment can achieve application initialization of the target application through unique instance call operations, internal state initialization operations and default language configuration loading operations, which is beneficial to improving the comprehensiveness, integrity and rationality of the application initialization method of the target application, and thus is beneficial to improving the accuracy and reliability of the application initialization of the target application, thereby helping to optimize the subsequent language switching effect.
[0170] Example 3
[0171] See also Figure 3 , Figure 3 This is a structural diagram of a dynamic language switching device disclosed in an embodiment of the present invention. Figure 3 The described device may include an electronic device equipped with a HarmonyOS NEXT system, an application program of the target application is installed in the electronic device, and the electronic device is communicatively connected to a network attached storage device, and the electronic device can access the network attached storage device through the application program, which is not limited in the embodiment of the present invention. Figure 3 As shown, the dynamic language switching device may include:
[0172] The language configuration update module 301 is used to perform a corresponding language configuration update operation on the target application based on the predetermined application initialization result of the target application and the detected language selection operation when the language of the target application needs to be switched, and obtain a language configuration update result.
[0173] The text refresh module 302 is used to determine the language change callback function according to the language configuration update result, and execute the corresponding UI text refresh operation based on the determined target event monitoring component and the language change callback function to obtain the UI text refresh result.
[0174] The text processing module 303 is used to determine the text content requirement form according to the determined text application scenario, and based on the text content requirement form, the preset translation result acquisition method and the preset translation result access method, perform corresponding translation text processing operations on the UI text refresh result to obtain the translation text processing result.
[0175] The display update module 304 is configured to execute corresponding UI component display update operations based on the translated text processing result, so as to implement language switching of the target application.
[0176] It can be seen that implementation Figure 3 The described dynamic language switching device can realize dynamic language switching function through language configuration update link, text refresh response link, translation text processing link and UI component display update link, which is conducive to improving the comprehensiveness, integrity and rationality of the dynamic language switching method of system applications, and thus is conducive to improving the language switching efficiency and convenience of system applications, as well as improving the language switching accuracy and reliability of system applications, thereby improving the UI component refresh efficiency and convenience, reducing the page synchronization update error rate, and in addition, is conducive to improving development convenience and simplicity, and improving the simplicity of business component code.
[0177] In an optional embodiment, the language configuration update module 301 performs a corresponding language configuration update operation on the target application based on the predetermined application initialization result of the target application and the detected language selection operation. The language configuration update result is obtained in the following manner:
[0178] Determining current language configuration information of the target application according to a predetermined application initialization result of the target application, and performing a corresponding language information normalization processing operation on the current language configuration information to obtain a language normalization processing result;
[0179] Determine target language configuration information corresponding to the target application based on the detected language selection operation and the preset basic language setting method;
[0180] Based on the language normalization processing result, the target required language configuration information and the preset international program language setting method, the corresponding language setting operation is performed on the target application to obtain the language configuration update result.
[0181] It can be seen that implementation Figure 4 The described device can realize the language configuration update function through language information standardization processing operations and language setting operations, which is conducive to improving the comprehensiveness and rationality of the language configuration update method, and further conducive to improving the accuracy and reliability of the language configuration update, thereby conducive to improving the compatibility and consistency of the language code, and conducive to improving the diversity and flexibility of the language format.
[0182] In another optional embodiment, the text processing module 303 performs corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, the preset translation result acquisition method, and the preset translation result access method. The method for obtaining the translation text processing result specifically includes:
[0183] According to the text content requirement form, the preset translation result acquisition method and the UI text refresh result, a corresponding translation text acquisition operation is performed to obtain a first returned translation result; the text content requirement form includes one of a singular translation text form, a plural translation text form and a character string form;
[0184] According to the preset translation result access method and the first returned translation result, a corresponding multilingual resource acquisition operation is performed to obtain a second returned translation result;
[0185] Performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result;
[0186] The translation text processing result is determined according to the third returned translation result.
[0187] It can be seen that implementation Figure 4The described device can also determine the translation text processing results through translation text acquisition operations, multilingual resource acquisition operations and placeholder processing operations, which is conducive to improving the comprehensiveness and rationality of the translation text processing result determination method, and thus is conducive to improving the accuracy and reliability of the determined translation text processing results, thereby helping to improve the accuracy and readability of the translation text. In addition, the text content requirement form is proposed to include one of the singular translation text form, plural translation text form and character string form, and multiple resource calling methods are provided to meet the needs of different scenarios.
[0188] In another optional embodiment, the text processing module 303 performs corresponding translation text acquisition operations according to the text content requirement form, the preset translation result acquisition method, and the UI text refresh result. The method of obtaining the first returned translation result specifically includes:
[0189] When the required text content format includes a singular translation text format, the first format translation text is determined according to the UI text refresh result and the preset first text acquisition method as the first returned translation result;
[0190] When the required text content format includes plural translation text formats, the second format translation text is determined according to the UI text refresh result and the preset second text acquisition method, and is returned as the first translation result;
[0191] When the required text content format includes a character string format, a third format translation text is determined according to the UI text refresh result and a preset third text acquisition method, and is returned as the first translation result.
[0192] It can be seen that implementation Figure 4 The described device can also match corresponding translation text determination methods according to the text content requirement forms, including singular translation text form, plural translation text form and character string form, which is conducive to improving the diversity, flexibility and pertinence of the translation text determination methods, and thus is conducive to improving the accuracy and reliability of the determined translation text, thereby helping to improve the accuracy and reliability of the first returned translation result.
[0193] In another optional embodiment, Figure 4 As shown, the device may also include:
[0194] The application initialization module 305 is configured to, when detecting that the target application is started, perform corresponding singleton initialization and language loading operations on the internationalization manager corresponding to the target application, and obtain an application initialization result corresponding to the target application.
[0195] It can be seen that implementation Figure 4The described device can also provide an application initialization processing method, which is conducive to improving the comprehensiveness, integrity and rationality of a dynamic language switching method, thereby ensuring the consistency of the language state when the application is started, adopting a singleton mode, reducing memory usage and improving resource utilization.
[0196] In another optional embodiment, the application initialization module 305 performs corresponding singleton initialization and language loading operations on the internationalization manager corresponding to the target application, and obtains the application initialization result corresponding to the target application in a manner specifically including:
[0197] Based on the target application and its corresponding internationalization manager, executing a corresponding call operation on a unique instance of a class responsible for managing internationalization functions to obtain a first initialization result;
[0198] Performing corresponding internal state initialization operations on the event monitoring device and resource management module included in the internationalization manager to obtain a second initialization result;
[0199] Performing a corresponding default language configuration loading operation on the target application and its corresponding internationalization manager to obtain a third initialization result;
[0200] An application initialization result corresponding to the target application is determined according to the first initialization result, the second initialization result, and the third initialization result.
[0201] It can be seen that implementation Figure 4 The described device can also realize application initialization of the target application through unique instance call operations, internal state initialization operations and default language configuration loading operations, which is conducive to improving the comprehensiveness, integrity and rationality of the application initialization method of the target application, and thus is conducive to improving the accuracy and reliability of the application initialization of the target application, thereby facilitating the optimization of subsequent language switching effects.
[0202] In another optional embodiment, the text refresh module 302 determines the language change callback function according to the language configuration update result in the following manner:
[0203] Generate target trigger events based on language configuration update results;
[0204] According to the target trigger event, a language change callback function is determined from one or more preset callback functions.
[0205] It can be seen that implementation Figure 4 The described device can also generate a target trigger event based on the language configuration update result and then determine a language change callback function, which is beneficial to improving the comprehensiveness and rationality of the method for determining the language change callback function, and further beneficial to improving the accuracy and reliability of the determined language change callback function.
[0206] In another optional embodiment, the text processing module 303 is further configured to, after executing a corresponding multilingual resource acquisition operation according to a preset translation result access method and the first returned translation result to obtain a second returned translation result, determine placeholder content information according to the second returned translation result; determine, based on the placeholder content information, whether the second returned translation result satisfies a preset placeholder content replacement condition; when it is determined that the second returned translation result satisfies the placeholder content replacement condition, execute a step of performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result; and when it is determined that the second returned translation result does not satisfy the placeholder content replacement condition, determine a translation text processing result according to the second returned translation result.
[0207] It can be seen that implementation Figure 4 The described device can also perform corresponding placeholder processing operations when it is determined that the placeholder content replacement conditions are met, and directly determine the translation text processing results when it is determined that the placeholder content replacement conditions are not met. This is conducive to improving the timeliness, accuracy, and rationality of the execution of the placeholder content processing operations, and thus is conducive to improving the accuracy and efficiency of the placeholder content processing, reducing unnecessary processing operations and the resulting waste of resources, thereby helping to improve the accuracy and reliability of the determined translation text processing results, and to a certain extent, helping to improve the efficiency and convenience of determining the translation text processing results.
[0208] Example 4
[0209] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. Figure 5 The electronic device described may include a server, wherein the server includes a local server or a cloud server, which is not limited in the embodiment of the present invention. Figure 5 As shown, the electronic device may include:
[0210] A memory 401 storing executable program code;
[0211] a processor 402 coupled to the memory 401;
[0212] Furthermore, it may also include an input interface 403 and an output interface 404 coupled to the processor 402;
[0213] The processor 402 calls the executable program code stored in the memory 401 to execute the steps of the dynamic language switching method described in the first or second embodiment.
[0214] Example 5
[0215] An embodiment of the present invention discloses a computer storage medium storing a computer program for electronic data exchange, wherein the computer program enables a computer to execute the steps of a dynamic language switching method described in the first or second embodiment.
[0216] Example 6
[0217] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute the steps of a dynamic language switching method described in embodiment 1 or embodiment 2.
[0218] Example 7
[0219] The embodiment of the present invention discloses a dynamic language switching system, which includes a dynamic language switching device described in the third embodiment, and a network attached storage device in communication with the device; or
[0220] The system includes the electronic device described in the fourth embodiment and a network attached storage device communicatively connected to the electronic device.
[0221] The device embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, i.e., they may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Those skilled in the art can understand and implement the present invention without inventive effort.
[0222] Through the detailed description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus the necessary general hardware platform, or of course, by means of hardware. Based on this understanding, the above technical solution, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, which can be stored in a computer-readable storage medium, the storage medium including a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.
[0223] Finally, it should be noted that the dynamic language switching method, device, and system disclosed in the embodiments of the present invention are merely preferred embodiments of the present invention and are intended to illustrate the technical solutions of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments may be modified or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A dynamic language switching method, the method being applied to an electronic device equipped with the HarmonyOS NEXT system, wherein the electronic device has a target application installed therein, and the electronic device is communicatively connected to a network attached storage device, and the electronic device can access the network attached storage device through the application, characterized in that: The method comprises: When the target application needs to switch the language, based on the predetermined application initialization result of the target application and the detected language selection operation, a corresponding language configuration update operation is performed on the target application to obtain a language configuration update result; Determine a language change callback function according to the language configuration update result, and perform a corresponding UI text refresh operation based on the determined target event listening component and the language change callback function to obtain a UI text refresh result; Determining a text content requirement form according to the determined text application scenario, and performing corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, a preset translation result acquisition method, and a preset translation result access method to obtain a translation text processing result; Based on the translated text processing result, a corresponding UI component display update operation is performed to achieve language switching of the target application.
2. A dynamic language switching method according to claim 1, characterized in that: The performing a corresponding language configuration update operation on the target application based on the predetermined application initialization result of the target application and the detected language selection operation to obtain a language configuration update result includes: Determining current language configuration information of the target application according to a predetermined application initialization result of the target application, and performing a corresponding language information normalization processing operation on the current language configuration information to obtain a language normalization processing result; Determining target required language configuration information corresponding to the target application based on the detected language selection operation and a preset basic language setting method; Based on the language normalization processing result, the target required language configuration information and the preset internationalized program language setting method, a corresponding language setting operation is performed on the target application to obtain a language configuration update result.
3. The dynamic language switching method according to claim 1, wherein: The method of performing corresponding translation text processing operations on the UI text refresh result based on the text content requirement form, the preset translation result acquisition method, and the preset translation result access method to obtain the translation text processing result includes: According to the text content requirement form, the preset translation result acquisition method and the UI text refresh result, a corresponding translation text acquisition operation is performed to obtain a first returned translation result; the text content requirement form includes one of a singular translation text form, a plural translation text form and a character string form; According to the preset translation result access method and the first returned translation result, a corresponding multilingual resource acquisition operation is performed to obtain a second returned translation result; performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result; The translation text processing result is determined according to the third returned translation result.
4. A dynamic language switching method according to claim 3, characterized in that: The step of performing a corresponding translation text acquisition operation according to the text content requirement form, the preset translation result acquisition method, and the UI text refresh result to obtain a first returned translation result includes: When the text content requirement form includes the singular translation text form, determining the first form translation text as the first returned translation result according to the UI text refresh result and the preset first text acquisition method; When the text content requirement form includes the plural translation text form, determining the second form translation text according to the UI text refresh result and the preset second text acquisition method as the first returned translation result; When the text content required form includes the character string form, a third form translation text is determined according to the UI text refresh result and a preset third text acquisition method as the first returned translation result.
5. A dynamic language switching method according to any one of claims 1 to 4, characterized in that: The method further comprises: When it is detected that the target application is started, the corresponding singleton initialization and language loading operations are performed on the internationalization manager corresponding to the target application to obtain the application initialization result corresponding to the target application; Furthermore, performing corresponding singleton initialization and language loading operations on the internationalization manager corresponding to the target application to obtain an application initialization result corresponding to the target application includes: Based on the target application and its corresponding internationalization manager, executing a corresponding unique instance call operation on a class responsible for managing internationalization functions to obtain a first initialization result; Performing corresponding internal state initialization operations on the event monitoring device and resource management module included in the internationalization manager to obtain a second initialization result; Performing a corresponding default language configuration loading operation on the target application and its corresponding internationalization manager to obtain a third initialization result; An application initialization result corresponding to the target application is determined according to the first initialization result, the second initialization result, and the third initialization result.
6. A dynamic language switching method according to any one of claims 1 to 4, characterized in that: The determining of the language change callback function according to the language configuration update result includes: Generate a target trigger event according to the language configuration update result; According to the target triggering event, a language change callback function is determined from one or more preset callback functions.
7. A dynamic language switching method according to claim 3, characterized in that: After performing a corresponding multilingual resource acquisition operation according to the preset translation result access mode and the first returned translation result to obtain a second returned translation result, the method further includes: determining placeholder content information according to the second returned translation result; Determining, based on the placeholder content information, whether the second returned translation result satisfies a preset placeholder content replacement condition; When it is determined that the second returned translation result satisfies the placeholder content replacement condition, performing the step of performing a corresponding placeholder processing operation on the second returned translation result to obtain a third returned translation result; When it is determined that the second returned translation result does not satisfy the placeholder content replacement condition, a translation text processing result is determined based on the second returned translation result.
8. A dynamic language switching device, characterized in that: The apparatus includes an electronic device equipped with a HarmonyOS NEXT system, an application program of a target application is installed in the electronic device, and the electronic device is communicatively connected to a network attached storage device, and the electronic device can access the network attached storage device through the application program. The apparatus includes: a language configuration update module configured to, when language switching of the target application is required, perform a corresponding language configuration update operation on the target application based on a predetermined application initialization result of the target application and a detected language selection operation, and obtain a language configuration update result; A text refresh module is used to determine a language change callback function according to the language configuration update result, and perform a corresponding UI text refresh operation based on the determined target event listening component and the language change callback function to obtain a UI text refresh result; A text processing module is used to determine the text content requirement form according to the determined text application scenario, and based on the text content requirement form, a preset translation result acquisition method and a preset translation result access method, perform corresponding translation text processing operations on the UI text refresh result to obtain a translation text processing result; The display update module is used to perform a corresponding UI component display update operation based on the translation text processing result to achieve language switching of the target application.
9. An electronic device, characterized in that: The electronic device comprises: a memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the dynamic language switching method according to any one of claims 1 to 7.
10. A computer storage medium, characterized in that The computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the dynamic language switching method according to any one of claims 1 to 7.
11. A dynamic language switching system, characterized in that: The system comprises a dynamic language switching device as claimed in claim 8, and a network attached storage device communicatively connected to the device; or The system comprises the electronic device according to claim 9, and a network attached storage device communicatively connected to the electronic device.
Citation Information
Patent Citations
Page language switching method, system and device and computer readable storage medium
CN109901886A
Page multi-language switching method and device, computer equipment and storage medium
CN114546559A