Language switching method and device for virtual page, electronic equipment and storage medium
By determining the real-time order of switching text languages one by one based on the page layer and distance center value of the subview in the virtual page, the problem of untimely switching of virtual page language in the prior art is solved, improving user experience and saving resources.
Patent Information
- Application Number
- CN202411341906.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2044-09-25
AI Technical Summary
The prior art requires rebuilding the entire page or restarting the application when switching text languages in virtual pages, resulting in untimely language switching, especially when multiple virtual pages are opened, the user experience is poor.
By responding to language switching instructions, determine the real-time order based on the page layer and distance center value of the subview, iterates through the subview one by one and converts its text language, avoids rebuilding the page, directly updates the text language of the target subview, and sets the new language to the default language.
It realizes fast text language switching without rebuilding virtual pages, improves user experience, saves data processing resources, and displays the target switching language by default when creating a new page.
Smart Images

Figure CN119201320A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of page display, and in particular to a method, device, electronic device and storage medium for switching the language of a virtual page. Background Art
[0002] With the internationalization of various applications, the requirements for diversified page display languages have also increased. In particular, to switch the text language in a virtual page, you need to rebuild the entire virtual page or restart the application to complete the text language switch. If multiple virtual pages are opened, each virtual page needs to be rebuilt, resulting in untimely language switching and poor user experience. Summary of the invention
[0003] In view of the above problems, the present application provides a method, device, electronic device and storage medium for switching the language of a virtual page, which are used to quickly switch the text language in a virtual page without rebuilding the virtual page.
[0004] According to one aspect of the present application, a language switching method for a virtual page is provided, the language switching method comprising: in response to a language switching instruction, traversing the sub-views in the current virtual page based on a real-time order, and using the traversed sub-views as target sub-views; wherein the language switching instruction specifies a target switching language, and the real-time order is an order determined based on the page layer where each sub-view is located and the distance value from the center of the current virtual page; if the text language in the target sub-view is different from the target switching language, converting the text language in the target sub-view into the target switching language, and using the target switching language as the default language, so that the target switching language is displayed by default when a new virtual page is created.
[0005] In an optional manner, converting the text language in the target subview into the target switching language further includes: determining the resource code corresponding to the text resource of the text language in the target subview; determining the target text resource corresponding to the resource code in the text resource directory corresponding to the target switching language; wherein the language of the target text resource is the target switching language, and text resources with the same meaning represented by different languages have the same resource code; replacing the text resource in the target subview with the target text resource to convert the text language in the target subview into the target switching language.
[0006] In an optional manner, before traversing the sub-views of the current virtual page based on the real-time order, the language switching method further includes: determining the page layer where each sub-view is located, and the distance value between the center of each sub-view and the center of the current virtual page; multiplying the page layer where each sub-view is located and the corresponding distance value with their respective corresponding preset weight coefficients, and calculating two products corresponding to each sub-view; summing the two products corresponding to each sub-view to calculate the sum value corresponding to each sub-view, and determining the real-time order according to the size of the sum value corresponding to each sub-view.
[0007] In an optional manner, the language switching method also includes: constructing a text resource directory corresponding to different text languages, and encoding the files in each of the text resource directories so that each file corresponds to a resource code; storing text resources with the same meaning in files in the text resource directories corresponding to different text languages, so that the resource codes corresponding to text resources with the same meaning in different text resource directories are the same.
[0008] In an optional manner, the language switching method also includes: detecting whether the text resource directory corresponding to the text language in the target subview is the same as the text resource directory corresponding to the target switching language; if they are the same, it indicates that the text language in the target subview is the same as the target switching language; if they are different, it indicates that the text language in the target subview is different from the target switching language.
[0009] In an optional manner, the language switching method is applied to the current interface of the Android application; before converting the text language in the target subview into the target switching language, the language switching method also includes: detecting whether the interface corresponding to the target subview is a preset interface; wherein the preset interface corresponds to a view that can load text resources; if so, sending a switching message to a preset message event function, so that the preset message event function calls a language switching function to switch the text language in the target subview.
[0010] In an optional manner, the language switching method further includes: if it is detected that the text language of all sub-views in the current interface is converted to the target switching language, then the text language of all sub-views in the historical interface is converted to the target switching language; wherein the historical interface is the interface covered by the current interface.
[0011] According to another aspect of the present application, a language switching device for a virtual page is provided, the language switching device comprising: a response module, for responding to a language switching instruction, traversing the sub-views in the current virtual page based on a real-time order, and using the traversed sub-views as target sub-views; wherein the language switching instruction specifies a target switching language, and the real-time order is an order determined according to the page layer where each sub-view is located and the distance value from the center of the current virtual page; a switching module, for converting the text language in the target sub-view into the target switching language if the text language in the target sub-view is different from the target switching language, and using the target switching language as the default language, so that the target switching language is displayed by default when a new virtual page is created.
[0012] According to one aspect of the present application, an electronic device is provided, including: a controller; and a memory for storing one or more programs, wherein when the one or more programs are executed by the controller, the above-mentioned language switching method is executed.
[0013] According to one aspect of the present application, a computer-readable storage medium is also provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the above-mentioned language switching method.
[0014] According to one aspect of the present application, a computer program product or a computer program is also provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the above-mentioned language switching method.
[0015] This application does not need to reload the entire virtual page, but switches the text language in each subview of the virtual page based on the real-time order, because the real-time order is determined according to the page layer where each subview is located and the distance value from the center of the current virtual page. To a certain extent, it gives priority to the switching of the text language of the subview within the user's sight, thereby improving the user's sensory comfort. In addition, this application can avoid unnecessary switching processes between the same languages, thereby saving data processing resources. At the same time, the target switching language is used as the default language so that the target switching language is displayed by default when a new virtual page is created to meet the user's desired language display requirements.
[0016] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 It is a flowchart of a method for switching the language of a virtual page shown in an exemplary embodiment of the present application.
[0019] Figure 2 is a schematic diagram of an exemplary virtual page.
[0020] Figure 3 is based on Figure 1 The exemplary embodiment shown is a flow chart of another method for switching the language of a virtual page.
[0021] Figure 4 is based on Figure 1 The exemplary embodiment shown is a flow chart of another method for switching the language of a virtual page.
[0022] Figure 5 This is a diagram of the interface life cycle of existing Android applications.
[0023] Figure 6 is based on Figure 1 The exemplary embodiment shown is a flow chart of another method for switching the language of a virtual page.
[0024] Figure 7 It is a structural schematic diagram of a language switching device for a virtual page shown in an exemplary embodiment of the present application.
[0025] Figure 8 It is a structural diagram of a computer system of an electronic device shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0026] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0027] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0028] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0029] The term "multiple" as used in this application refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0030] To switch the text language in a virtual page, you need to rebuild the entire virtual page or restart the application to complete the text language switch. If multiple virtual pages are opened, each virtual page needs to be rebuilt, resulting in untimely language switching and a poor user experience.
[0031] To this end, one aspect of the present application provides a method for switching the language of a virtual page. Figure 1 , Figure 1 1 is a flowchart of a method for switching the language of a virtual page shown in an exemplary embodiment of the present application. The method for switching the language includes at least S110 to S120, which are described in detail as follows:
[0032] S110: In response to a language switching instruction, traverse the sub-views in the current virtual page based on real-time order, and use the traversed sub-views as target sub-views; wherein the language switching instruction specifies a target switching language, and the real-time order is an order determined based on the page layer where each sub-view is located and the distance value from the center of the current virtual page.
[0033] The language switching instruction is a command triggered by the user through voice input or by touching a virtual button in the current virtual page. The instruction carries the target switching language, that is, the language that the user expects the current page to display.
[0034] The current virtual page is a window for human-computer interaction, for example, a page displayed on the entire display screen. There are multiple subviews in the virtual page, similar to different display areas. The display content of each subview may be different, and all subviews constitute a complete virtual page.
[0035] This embodiment considers the page layer and center distance value of the subview in real time order, and obtains the corresponding traversal order to perform language switching operations on the subviews in the front order first, so as to ensure that the text language in the subviews in the front order is quickly switched. At the same time, the traversal method can ensure that the language of each subview is switched without omission, avoiding omission processing.
[0036] In another embodiment, corresponding preset weight coefficients are introduced to adjust the influence of the two dimensions on the sub-view traversal order, that is, the influence of the real-time order. Exemplarily, the page layer where each sub-view is located and the distance value between the center of each sub-view and the center of the current virtual page are determined; the page layer where each sub-view is located and the corresponding distance value are multiplied by the corresponding preset weight coefficients, respectively, to obtain the two products corresponding to each sub-view; the two products corresponding to each sub-view are summed to obtain the sum value corresponding to each sub-view, and the real-time order is determined according to the sum value corresponding to each sub-view. Among them, the number of page layers corresponds to the first preset weight coefficient, and the distance value corresponds to the second preset weight coefficient. The present application does not limit the specific size of the two coefficients. The corresponding real-time order can be determined by adjusting their numerical values, thereby adjusting the traversal order of each sub-view.
[0037] See also Figure 2 , Figure 2 is a schematic diagram of an exemplary virtual page. There are sub-views of different page layers, and the distance between each sub-view and the center point of the virtual page is also different. Figure 2 As shown, there are two page layers in the virtual page, and the score value corresponding to each page layer is different, and the scores decrease from top to bottom. According to the coordinates of the geometric center point of each subview and the coordinates of the center point of the virtual page, the distance between the two coordinate points can be calculated as the distance between the corresponding subview and the center point of the virtual page.
[0038] Furthermore, the first preset weight coefficient is 0.6, and the second preset weight coefficient is 0.4; as for the first page layer, the corresponding page layer value of sub-views A, C, and D is 70, and their distance from the virtual page center point ( Figure 2The distances of the subviews are a, c, and d respectively; as for subview B at the bottom page layer, the corresponding page layer value is 30, and its distance from the center point of the virtual page is b. The sum calculation process of each subview is illustrative: subview A sum = 0.6×70+0.4×a; subview B sum = 0.6×30+0.4×b; subview C sum = 0.6×70+0.4×c; subview D sum = 0.6×70+0.4×d. Then, according to the size of the four sums, the real-time order is determined. In particular, in most scenarios, users generally stay on the first-level page by default. If the same sum is calculated, the subviews at the front of the page layer will be prioritized.
[0039] S120: If the text language in the target subview is different from the target switching language, convert the text language in the target subview into the target switching language, and use the target switching language as the default language, so that the target switching language is displayed by default when a new virtual page is created.
[0040] This embodiment does not need to reload the entire virtual page, but switches the text language in each subview of the virtual page based on the real-time order, because the real-time order is determined according to the page layer where each subview is located and the distance value from the center of the current virtual page. To a certain extent, it gives priority to the switching of the text language of the subview within the user's sight, thereby improving the user's sensory comfort. In addition, the present application can avoid unnecessary switching processes between the same languages, thereby saving data processing resources. At the same time, the target switching language is used as the default language so that the target switching language is displayed by default when a new virtual page is created to meet the user's desired language display requirements.
[0041] In another exemplary embodiment of the present application, how to convert the text language in the target subview into the target switching language is described in detail. Figure 3 , Figure 3 is based on Figure 1 The exemplary embodiment shown is a flow chart of another method for switching the language of a virtual page. The language switching method is as follows Figure 1 The S120 shown further includes S310 to S330, which are described in detail as follows:
[0042] S310: Determine the resource code corresponding to the text resource of the text language in the target subview.
[0043] The text resource can be a noun, a verb, etc., that is, a resource with substantial text meaning. Different text resources correspond to different resource codes. For example, the text resource "hello" corresponds to an ID (resource code) of "1".
[0044] S320: Determine the target text resource corresponding to the resource code in the text resource directory corresponding to the target switching language; wherein, the language of the target text resource is the target switching language, and the resource codes corresponding to text resources with the same meaning in different languages are the same.
[0045] Each language corresponds to a corresponding text resource directory, and the text resource directories corresponding to different languages are different. It should be noted that regardless of the language type, the resource codes corresponding to text resources with the same meaning are fixed. For example, the ID (resource code) corresponding to "你好" is "1", that is, its number in the text resource directory corresponding to Chinese is 1, and the number of its English "hello" in the text resource directory corresponding to English is also 1. Therefore, different switching languages can be quickly determined through the encoding of the text resources.
[0046] S330: Replace the text resource in the target sub-view with the target text resource to convert the text language in the target sub-view to the target switching language.
[0047] Exemplarily, the target switching language is English, and the text resource "你好" in the target sub-view is Chinese. The target text resource: "hello" can be quickly determined according to its number "1", and thus "你好" in the target sub-view can be quickly switched to "hello".
[0048] In this embodiment, switching between different languages is performed through the encoding of text resources. Different text resource directories are set for different types of languages, and text resources with the same meaning share the same encoding and are stored in different text resource directories to facilitate quickly obtaining the text resources of the corresponding language and completing the text switching of the sub-view.
[0049] In another exemplary embodiment, how to construct text resource directories corresponding to different text languages is introduced. Specifically, construct text resource directories corresponding to different text languages, and perform encoding processing on the files in each text resource directory so that each file corresponds to a resource code; store text resources with the same meaning in the files in the text resource directories corresponding to different text languages, so that in different text resource directories, the resource codes corresponding to text resources with the same meaning are the same.
[0050] For example, the text resource directory includes but is not limited to chinese-directory, english-directory, etc. "你好" and "hello" are respectively placed in the No. 1 files in the chinese-directory and english-directory, so that in different text resource directories, the resource codes corresponding to text resources with the same meaning are the same.
[0051] In another exemplary embodiment of the present application, how to determine whether languages are the same is introduced in detail. For details, please refer to Figure 4 , Figure 4 is based on Figure 1 The exemplary embodiment shown is a flow chart of another method for switching the language of a virtual page. The language switching method is as follows Figure 1 Based on the S110 to S120 shown, it further includes S410 to S430, which are described in detail as follows:
[0052] S410: Detect whether the text resource directory corresponding to the text language in the target subview is the same as the text resource directory corresponding to the target switching language.
[0053] S420: If they are the same, it indicates that the text language in the target subview is the same as the target switching language.
[0054] S430: If they are different, it indicates that the text language in the target subview is different from the target switching language.
[0055] This embodiment can determine whether the text language is the same by detecting whether the text resource directories corresponding to the text language are the same. Different text resource directories can be encoded differently to quickly determine whether the text resource directories are the same according to the encoding, thereby determining whether the text language in the target subview is the same as the target switching language, thereby avoiding unnecessary language switching operations.
[0056] The language switching process of existing Android applications is as follows Figure 5 As shown, Figure 5 This is a diagram of the interface life cycle of existing Android applications. Activity represents an interface, and each process is described as follows:
[0057] onCreate: The first method to open the activity, this method will initialize the setContentLayout() method (screen drawing).
[0058] onStart: After the onCreate() method is completed, the activity enters the onStart() method. The current activity is visible to the user, but it cannot be interacted with yet. In this lesson, some animation initialization operations are performed.
[0059] onResume: After onStart(), the activity enters the onResume method. The current activity state is running (Running), and the activity is visible and interactive.
[0060] onPause: Called when the system is performing another activity. It is usually used to confirm changes to persistent data, stop animations, and any other content that may consume CPU. It must perform the required operations quickly. After this method is executed, the next Activity can start executing. After this method is executed, the onStop() method should be executed.
[0061] onStop: Called when the Activity is no longer visible to the user. It may be covered by another Activity or returned to the desktop. If the system memory is tight under the onStop method, it may be recycled by the system.
[0062] onDestory: Called before the Activity is destroyed. This is the last call received by the Activity. This method will be called when the Activity ends or the Activity instance is destroyed by the system.
[0063] onRestart: Called when the Activity is started again after being stopped, such as when returning to the application from the desktop, and then calling the onStart method ().
[0064] When the Activity is reloaded after switching languages, it goes through a complete lifecycle process:
[0065] 1. Language switching detection:
[0066] When the application detects that the system language has changed, it updates the language settings of the application and calls the recreate() method to recreate the Activity.
[0067] 2. onPause(): The current Activity enters the paused state. The system calls onPause() to handle tasks when the interface is paused, such as saving data or stopping animation.
[0068] 3. onStop(): When the Activity is completely invisible, the system calls onStop(). At this time, you can release resources that are no longer needed.
[0069] 4.onDestroy(): The system calls onDestroy() to destroy the current Activity instance so that a new instance can be recreated. This is the end of the old Activity life cycle.
[0070] 5. onCreate(): The system creates a new Activity instance and calls onCreate(). Here, the app loads resources for the new language, such as layouts and strings.
[0071] 6. onStart(): When the Activity becomes visible, the system calls onStart(). At this time, the paused resources can be resumed.
[0072] 7. onResume(): When the Activity returns to the foreground and is ready to interact with the user, the system calls onResume(). At this stage, the interface has already used the new language resources.
[0073] Continue application execution: The Activity enters the active state, the application runs normally, and the updated interface is displayed.
[0074] Obviously, the existing language switching methods of Android applications all require restarting the application or rebuilding the page to complete the text language switching. If there are many pages opened in the Android application, each page needs to be rebuilt, which is a cumbersome process and will reduce the user's visual experience.
[0075] To this end, any of the above-mentioned language switching methods of this application is applied to applications in the Android system, and through a custom interface and a quick notification interface refresh method, the language can be switched without rebuilding the interface, thereby saving rendering resources and improving the user experience. Figure 6 , Figure 6 is based on Figure 1 The exemplary embodiment shown is a flow chart of another method for switching the language of a virtual page. The language switching method is as follows Figure 1 Before S120 shown, it further includes S610 to S620; wherein, the language switching method is applied to the current interface of the Android application, which is described in detail as follows:
[0076] S610: Detect whether the interface corresponding to the target subview is a preset interface; wherein the preset interface corresponds to a view that can load text resources.
[0077] This application can switch the language of loadable text resources in the Android application interface. Specifically, through the interface detection of the sub-view, it can quickly determine whether the text language of the corresponding sub-view can be switched.
[0078] S620: If yes, send a switching message to a preset message event function, so that the preset message event function calls a language switching function to switch the text language in the target subview.
[0079] For example, the tool library EventBus is introduced into the Android application to implement the notification function, so as to facilitate the call of the language switching function to quickly switch the text language in the target subview. Among them, EventBus is an Android / Java event subscription / publishing framework, which is used to pass data or events to subscribers in the scenario of communication between components / threads. The feature of EventBus is that it can realize the decoupling of event subscribers and publishers, as well as transparent thread switching.
[0080] The following is an example of language switching in the Android application interface:
[0081] Step 1: Define the multi-language switching interface IlanguageSwitch (the default interface of this application)
[0082] The IlanguageSwitch interface contains the following methods:
[0083] public interface IlanguageSwitch{
[0084] void setTextById(@StringRes int id); / / Set text by resource ID
[0085] void setTextWithString(String text); / / Set text directly
[0086] void reLoadLanguage(); / / The main method called when modifying the language
[0087] }
[0088] Step 2: Define an AppTextView to implement the IlanguageSwitch interface. Here, AppTextView refers to the View that needs to switch the language (i.e., the target subview of this application), and then implement the function logic of switching the language defined in the interface. The pseudo code to implement this interface is as follows:
[0089] public class AppTextView extends TextView implements IlanguageSwitch{
[0090] private int textId; / / text resource id (i.e. the text resource code of this application)
[0091] private int textValue; / / text
[0092] public AppTextView(Context context){
[0093] super(context);
[0094] init(context,null);
[0095] }
[0096] / / Initialize and get the resource id of xml
[0097] private void init(Context context,AttributeSet attributeSet){
[0098] textValue=attributeSet.getAttributeValue(ANDROIDXML,"text");
[0099] / / Record the text resource ID here. When switching languages later, read the language of the corresponding country through this resource ID
[0100]
[0101] Step 3: All views that display text in the application need to be implemented according to the method in step 2, so that the custom view can switch languages at will without rebuilding.
[0102] Step 4: After completing the above three steps, a notification-triggered view refresh mechanism is required so that the custom view can be refreshed synchronously when the language is switched. There are many ways to implement the notification refresh function. Here, you need to introduce the tool library EventBus into the application to implement the notification function.
[0103] After introducing EventBus, you need to register the same refresh event in each Activity using the registration method provided by EventBus: EventBus.getDefault().register(this); and implement the onMessageEvent function, which is used to process received messages. Here you can switch the language of the interface.
[0104] An Activity (interface) may contain a ViewGroup, and a ViewGroup may contain multiple subviews, so here is a function encapsulated to find all subviews and implement language switching for all views on the interface:
[0105]
[0106] The logic of this method is to pass in a view (usually the root view of the Activity) and check all the child views. If it is a view that implements the IlanguageSwitch interface, the view's reLoadLanguage() function is called to update the language.
[0107] When switching languages, the onMessageEvent() function (i.e., the preset message event function of this application) will receive the message, and the above-encapsulated updateViewLanguage function (i.e., the language switching function of this application) can be called here to complete the language switching without rebuilding the interface.
[0108] public void onMessageEvent(MessageEvent event){
[0109] updateViewLanguage(view)
[0110] }
[0111] Now you can update the language by clicking a button. The Activity is not rebuilt, and the language of the previous Activity will also be switched.
[0112] In some embodiments, if it is detected that the text language of all subviews in the current interface is converted to the target switching language, the text language of all subviews in the historical interface is converted to the target switching language; wherein the historical interface is the interface covered by the current interface.
[0113] After completing the language switching of the current interface, this embodiment can switch the language of the overlay interface, so that the user can open the overlay interface, and the interface displays the text language that the user expects to display. There is no need to switch the text language after opening the overlay interface, which avoids the waiting time for language switching, thereby improving the user experience.
[0114] Another aspect of the present application also provides a language switching device for a virtual page, such as Figure 7 As shown, Figure 7It is a structural diagram of a language switching device for a virtual page shown in an exemplary embodiment of the present application. The language switching device 700 includes: a response module 710, which is used to respond to a language switching instruction, traverse the subviews in the current virtual page based on the real-time order, and use the traversed subviews as the target subviews; wherein the language switching instruction specifies the target switching language, and the real-time order is determined according to the page layer where each subview is located and the distance value from the center of the current virtual page; a switching module 730, which is used to convert the text language in the target subview to the target switching language if the text language in the target subview is different from the target switching language, and use the target switching language as the default language, so that the target switching language is displayed by default when a new virtual page is created.
[0115] In another exemplary embodiment, the switching module 730 further includes: a resource encoding determination unit, used to determine the resource encoding corresponding to the text resource of the text language in the target subview; a target text resource determination unit, used to determine the target text resource corresponding to the resource encoding in the text resource directory corresponding to the target switching language; wherein the language of the target text resource is the target switching language, and text resources with the same meaning represented by different languages have the same resource encoding; a switching unit, used to replace the text resource in the target subview with the target text resource to convert the text language in the target subview into the target switching language.
[0116] In another exemplary embodiment, the language switching device 700 also includes: a center distance determination unit, which is used to determine the page layer where each sub-view is located, and the distance value between the center of each sub-view and the center of the current virtual page; a first calculation unit, which is used to multiply the page layer where each sub-view is located and the corresponding distance value with their respective corresponding preset weight coefficients, and obtain two products corresponding to each sub-view; a second calculation unit, which is used to sum the two products corresponding to each sub-view, obtain the sum value corresponding to each sub-view, and determine the real-time order according to the size of the sum value corresponding to each sub-view.
[0117] In another exemplary embodiment, the language switching device 700 also includes: a construction unit, which is used to construct a text resource directory corresponding to different text languages, and encode the files in each text resource directory so that each file corresponds to a resource code; a storage unit, which is used to store text resources with the same meaning into files in the text resource directories corresponding to different text languages, so that the resource codes corresponding to the text resources with the same meaning in different text resource directories are the same.
[0118] In another exemplary embodiment, the language switching device 700 also includes: a detection unit, used to detect whether the text resource directory corresponding to the text language in the target subview is the same as the text resource directory corresponding to the target switching language; a same unit, used to indicate that if they are the same, the text language in the target subview is the same as the target switching language; and a different unit, used to indicate that if they are different, the text language in the target subview is different from the target switching language.
[0119] In another exemplary embodiment, the language switching method is applied to the current interface of an Android application; the language switching device 700 also includes: an interface detection unit, used to detect whether the interface corresponding to the target subview is a preset interface; wherein the preset interface corresponds to a view that can load text resources; a sending unit, used to send a switching message to a preset message event function if yes, so that the preset message event function calls the language switching function to switch the text language in the target subview.
[0120] In another exemplary embodiment, the language switching device 700 also includes: an interface switching unit, which is used to convert the text language of all sub-views in the historical interface into the target switching language if it is detected that the text language of all sub-views in the current interface is converted into the target switching language; wherein the historical interface is an interface covered by the current interface.
[0121] The language switching device of the present application does not need to reload the entire virtual page, but switches the text language in each sub-view of the virtual page based on the real-time order, because the real-time order is determined according to the page layer where each sub-view is located and the distance value from the center of the current virtual page. To a certain extent, it gives priority to the switching of the text language of the sub-view within the user's sight, thereby improving the user's sensory comfort. In addition, the present application can avoid unnecessary switching processes between the same languages, thereby saving data processing resources. At the same time, the target switching language is used as the default language so that the target switching language is displayed by default when a new virtual page is created to meet the user's desired language display requirements.
[0122] It should be noted that the language switching device provided in the above embodiment and the language switching method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs operations has been described in detail in the method embodiment and will not be repeated here.
[0123] Another aspect of the present application provides an electronic device, including: a controller; a memory for storing one or more programs, and when the one or more programs are executed by the controller, the above-mentioned language switching method is executed.
[0124] See also Figure 8 , Figure 81 is a schematic diagram of the structure of a computer system of an electronic device shown in an exemplary embodiment of the present application, which shows a schematic diagram of the structure of a computer system of an electronic device suitable for implementing an embodiment of the present application.
[0125] It should be noted that Figure 8 The computer system 800 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0126] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 802 or the program loaded from the storage part 808 to the random access memory (RAM) 803, such as executing the method in the above embodiment. In the RAM 803, various programs and data required for system operation are also stored. The CPU 801, ROM 802 and RAM 803 are connected to each other through a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0127] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed so that a computer program read therefrom is installed into the storage section 808 as needed.
[0128] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 809, and / or installed from a removable medium 811. When the computer program is executed by a central processing unit (CPU) 801, various functions defined in the system of the present application are executed.
[0129] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as a part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0130] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0131] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0132] Another aspect of the present application further provides a computer-readable storage medium having a computer program stored thereon, which implements the above-mentioned language switching method when the computer program is executed by a processor. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0133] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the language switching method provided in each of the above embodiments.
[0134] According to one aspect of an embodiment of the present application, a computer system is also provided, including a central processing unit (CPU), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage portion into a random access memory (RAM), such as executing the method in the above embodiment. In RAM, various programs and data required for system operation are also stored. CPU, ROM and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0135] The following components are connected to the I / O interface: an input part including a keyboard, a mouse, etc.; an output part including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage part including a hard disk, etc.; and a communication part including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication part performs communication processing via a network such as the Internet. A drive is also connected to the I / O interface as needed. Removable media, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., are installed on the drive as needed so that the computer program read therefrom is installed into the storage part as needed.
[0136] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A method for switching the language of a virtual page, characterized in that: The language switching method comprises: In response to a language switching instruction, traverse the subviews in the current virtual page based on a real-time order, and use the traversed subviews as target subviews; wherein the language switching instruction specifies a target switching language, and the real-time order is an order determined according to the page layer where each subview is located and the distance value from the center of the current virtual page; If the text language in the target subview is different from the target switching language, the text language in the target subview is converted into the target switching language, and the target switching language is used as the default language, so that the target switching language is displayed by default when a new virtual page is created.
2. The language switching method according to claim 1, characterized in that: The converting the text language in the target subview into the target switching language further includes: Determine the resource code corresponding to the text resource of the text language in the target subview; In the text resource directory corresponding to the target switching language, determine the target text resource corresponding to the resource code; wherein the language of the target text resource is the target switching language, and text resources with the same meaning represented by different languages have the same resource code; The text resource in the target subview is replaced with the target text resource to convert the text language in the target subview into the target switching language.
3. The language switching method according to claim 1, characterized in that: Before traversing the subviews of the current virtual page based on the real-time order, the language switching method further includes: Determine the page layer where each subview is located, and the distance between the center of each subview and the center of the current virtual page; The page layer and the corresponding distance value of each subview are multiplied by the preset weight coefficients corresponding to each subview to obtain two products corresponding to each subview; The two products corresponding to each sub-view are summed to obtain the sum value corresponding to each sub-view, and the real-time order is determined according to the sum value corresponding to each sub-view.
4. The language switching method according to claim 1, characterized in that: The language switching method further includes: Constructing text resource directories corresponding to different text languages, and encoding files in each of the text resource directories so that each file corresponds to a resource code; The text resources with the same meaning are stored in files in the text resource directories corresponding to different text languages, so that the resource codes corresponding to the text resources with the same meaning in different text resource directories are the same.
5. The language switching method according to claim 1, characterized in that: The language switching method further includes: Detecting whether the text resource directory corresponding to the text language in the target subview is the same as the text resource directory corresponding to the target switching language; If they are the same, it indicates that the text language in the target subview is the same as the target switching language; If they are different, it indicates that the text language in the target subview is different from the target switching language.
6. The language switching method according to any one of claims 1 to 5, characterized in that: The language switching method is applied to the current interface of the Android application; Before converting the text language in the target subview to the target switching language, the language switching method further includes: Detecting whether the interface corresponding to the target subview is a preset interface; wherein the preset interface corresponds to a view that can load text resources; If yes, a switching message is sent to a preset message event function, so that the preset message event function calls a language switching function for switching the text language in the target subview.
7. The language switching method according to claim 6, characterized in that: The language switching method further includes: If it is detected that the text language of all subviews in the current interface is converted to the target switching language, the text language of all subviews in the historical interface is converted to the target switching language; wherein the historical interface is the interface covered by the current interface.
8. A language switching device for a virtual page, characterized in that: The switching device comprises: A response module, for responding to a language switching instruction, traversing the subviews in the current virtual page based on a real-time order, and taking the traversed subviews as target subviews; wherein the language switching instruction specifies a target switching language, and the real-time order is an order determined according to the page layer where each subview is located and the distance value from the center of the current virtual page; The switching module is used to convert the text language in the target subview into the target switching language if the text language in the target subview is different from the target switching language, and use the target switching language as the default language so that the target switching language is displayed by default when a new virtual page is created.
9. An electronic device, characterized in that: include: Controller; A memory is used to store one or more programs. When the one or more programs are executed by the controller, the controller implements the language switching method described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the language switching method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Language conversion method, device, device and storage medium
CN109344412A
Translation method and device, electronic equipment and storage medium
CN116894444A
Multi-language switching method and device, electronic equipment, storage medium and program product
CN117056001A
Interface style editing method and device, medium and equipment
CN117289918A
Systems and methods for language translation in network browsing applications
US20060265652A1
