A resource lookup method and related apparatus
By splitting internationalization resource files into key-value pairs, the problems of long resource parsing time and large installation packages during application internationalization are solved, resulting in faster startup and language switching, and improved user experience.
Patent Information
- Application Number
- CN202111058332.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-09
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2041-09-09
AI Technical Summary
Existing technologies require runtime resource parsing or network acquisition during application internationalization, which increases runtime and results in excessively large application installation packages, impacting user experience.
By splitting internationalization resource files into key-value pairs, the key and value are loaded directly, reducing resource parsing time during application startup or language switching. The key and value files are stored separately in the installation package, reducing redundant storage and memory pressure.
It effectively reduces the time spent parsing internationalization resources each time the application starts or the language is switched, reduces the size of the application installation package and memory pressure, and improves the user experience.
Smart Images

Figure CN115774560B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of electronic technology, and in particular to a resource search method and related apparatus. Background Technology
[0002] As the business expands, applications become increasingly internationalized. The same application can be used in multiple regions or countries. However, since users in different countries or regions use different application resources (such as language resources and display resources), in order to meet the needs of users, the corresponding application resources need to be internationalized for different regions or applications.
[0003] However, common internationalization operations require runtime resource parsing to obtain the final result, or retrieving corresponding internationalization resources via network connection, which increases the overall runtime and application display time. On the other hand, saving all resources for each country and region results in an excessively large application installation package, slow download speeds, and a negative impact on user experience. Summary of the Invention
[0004] This application provides a resource search method and related apparatus. By directly loading the internationalized resource key and value, the time spent parsing internationalized resources can be reduced each time the application starts or the application language is switched.
[0005] In a first aspect, this application provides a resource search method, which includes: an electronic device running a first application, the current running environment of the first application being a first running environment; the electronic device determining a first key of a display element on a first page of the first application; the electronic device searching for a first value corresponding to the first key in a first value file based on the first running environment; the electronic device displaying the first page according to the first value of the display element on the first page; when the electronic device receives a resource switching request, the resource switching request being used to switch the first running environment to a second running environment; in response to the resource switching request, the electronic device searching for a second value corresponding to the first key in a second value file based on the second running environment; and the electronic device displaying the first page according to the second value of the display element on the first page.
[0006] An electronic device runs a first application, and the internationalization resource file of the first application is a resource file after key-value pair splitting. The electronic device can split the internationalization resource file into key-value pairs during the installation of the first application; it can also split the internationalization resource file into key-value pairs during the packaging and compilation of the first application to generate the installation package of the first application; or it can obtain the internationalization resource file after key-value pair splitting from other devices; this application does not limit this.
[0007] An electronic device runs a first application and determines the lookup path key value of the display elements on the first page (the page to be displayed). If the current running environment of the first application is a first running environment, the electronic device looks up the value corresponding to the key value in the first value file. The electronic device displays the first page according to the value value of the display elements on the first page. If the current running environment of the first application is a second running environment, the electronic device looks up the value corresponding to the key value in the second value file. The electronic device displays the first page according to the value value of the display elements on the first page. In this embodiment, by directly loading the internationalization resource key and value, the time spent parsing internationalization resources each time the application starts or the application language is switched can be reduced.
[0008] In conjunction with the first aspect, in one possible implementation, before the electronic device runs the first application, the method further includes: the electronic device installing the first application based on the installation package of the first application, the installation package of the first application including a first resource file and a second resource file, the first resource file and the second resource file storing data in a key-value pair pattern; the first resource file provides a first operating environment, and the second resource file provides a second operating environment; the electronic device converts the first resource file and the second resource file into a key file, a first value file, and a second value file, the key file including the keys of the first resource file and the second resource file, the first value file including the values of the first resource file, the second value file including the values of the second resource file, the key file and the first value file having a first mapping relationship, and the key file and the second value file having a second mapping relationship. This specifically describes one way in which the electronic device converts internationalization resource files. The electronic device separates multiple resource files in the internationalization resource file into key-value pairs, saves the keys from multiple resource files into one file, and removes duplicate keys. That is, the internationalization module converts n resource files into one key file and n value files, the n value files corresponding one-to-one with the n resource files, and each value file includes the value from one of the resource files. This reduces redundant storage of key values across multiple resource files, thus reducing the size of internationalization resource files. Furthermore, when an electronic device installs the first application, it parses and converts all internationalization resources in the installation package, storing them as keys and values separately. This reduces the memory pressure on the device when switching application resource files and during startup.
[0009] In conjunction with the first aspect, in one possible implementation, the electronic device, based on the current first operating environment, searches for the first value corresponding to the first key in the first value file. This includes: the electronic device finding the position of the first key in the key file, and then obtaining the index value of the value corresponding to the first key in the first value file based on the first mapping relationship; the electronic device finding the first value in the first value file based on the index value. This specifically describes how the electronic device runs the first application based on the converted internationalized resource file. By directly loading the internationalized resource key and value, the time spent parsing internationalized resources each time the application starts or the application language is switched can be reduced.
[0010] In conjunction with the first aspect, in one possible implementation, before the electronic device runs the first application, the method further includes: the electronic device converting a first resource file and a second resource file into a key file, a first value file, and a second value file using a packaging and compilation tool. The first and second resource files store data in a key-value pair pattern. The first resource file provides a first runtime environment, and the second resource file provides a second runtime environment. The key file includes the keys of both the first and second resource files, the first value file includes the values of both the first and second resource files, and the key file and the first value file have a first mapping relationship, and the key file and the second value file have a second mapping relationship. The electronic device generates an installation package for the first application, which includes the key file, the first value file, and the second value file. This specifically describes one method by which the electronic device converts internationalized resource files. Converting internationalized resource files during the application compilation stage can reduce the size of the application installation package without increasing the application installation time.
[0011] In conjunction with the first aspect, in one possible implementation, before the electronic device runs the first application, the method further includes: the electronic device obtaining the installation package of the first application, the installation package of the first application including a key file, a first value file, and a second value file. That is, the electronic device can directly obtain the internationalized resource file after separating the key-value pairs through an application market or other devices.
[0012] In conjunction with the first aspect, in one possible implementation, the electronic device, based on its current first operating environment, searches for the first value corresponding to the first key in the first value file. This includes: the electronic device obtaining the first value file from the server of the first application based on its current first operating environment; and the electronic device searching for the first value corresponding to the first key in the first value file. Here, the electronic device obtains the internationalization resource file of the first application through a third-party server of the first application. Based on this, the electronic device can download the internationalization resource file of the application according to different regions, reducing the consumption of file download or transmission. Furthermore, the internationalization resource file can be separated into key-value pairs based on the third-party server of the first application, allowing the electronic device to directly obtain the internationalization resource file after key-value pair separation. For the first application running on resource-constrained electronic devices, this solves the problem of excessive internationalization resource consumption by the first application leading to abnormal system operation of the electronic device.
[0013] In one possible implementation, the data structure hierarchy of the first resource file is the first level, and the data structure hierarchy of the key file is the second level, with the values in the second level being lower than those in the first level. This embodiment establishes a lookup mapping relationship between keys and values, flattening the resource file structure, which can accelerate the search for internationalized target values and reduce the time spent parsing internationalized resources each time the first application starts or when application resource files are switched.
[0014] In conjunction with the first aspect, in one possible implementation, the data structure of each key in the key file includes: the index of the key in the string, the length of the key, the position of the corresponding value in value.bin, and the index position of the next key node in the key file.
[0015] In one possible implementation, the index position of the next key node in the key file for each key is calculated using a hash.
[0016] Secondly, this application provides a resource conversion method, which includes: an electronic device converting a first resource file and a second resource file into a key file, a first value file, and a second value file using a packaging and compilation tool; the first resource file and the second resource file store data in a key-value pair pattern; the first resource file provides a first runtime environment, the second resource file provides a second runtime environment; the key file includes the keys of the first resource file and the second resource file; the first value file includes the values of the first resource file; the second value file includes the values of the second resource file; the key file and the first value file have a first mapping relationship; and the key file and the second value file have a second mapping relationship; the electronic device generates an installation package of a first application, the installation package of the first application including the key file, the first value file, and the second value file.
[0017] In this embodiment, the electronic device converts internationalization resource files during the application compilation phase. The electronic device separates multiple resource files within the internationalization resource files into key-value pairs, saving the keys from multiple resource files into a single file and removing duplicate keys. Specifically, the internationalization module converts n resource files into one key file and n value files, with each of the n value files corresponding one-to-one with the n resource files. Each value file includes the value from one of the resource files. This reduces redundant storage of key values across multiple resource files, reducing the size of the internationalization resource files and thus reducing the application installation package size without increasing application installation time. Furthermore, storing keys and values separately reduces the memory pressure on the electronic device when switching application resource files and during startup.
[0018] In conjunction with the second aspect, in one possible implementation, after the electronic device generates the installation package of the first application, the process further includes: the electronic device installing the first application based on the installation package; the electronic device running the first application, with the current running environment of the first application being the first running environment; the electronic device determining the display format of the display elements of the page to be displayed in the first application based on the key file and the first value file, and displaying the page to be displayed; when the electronic device receives a resource switching request, the resource switching request is used to switch the first running environment to the second running environment; in response to the resource switching request, the electronic device determining the display format of the display elements of the page to be displayed in the first application based on the key file and the second value file, and displaying the page to be displayed. When the electronic device runs the first application, it determines the lookup path key value of the display elements of the first page (the page to be displayed); if the current running environment of the first application is the first running environment, the electronic device looks up the value corresponding to the key value in the first value file and displays the first page according to the value value; if the current running environment of the first application is the second running environment, the electronic device looks up the value corresponding to the key value in the second value file and displays the first page according to the value value. In this embodiment, by directly loading the internationalization resource key and value, the time spent parsing internationalization resources each time the application starts or the application language is switched can be reduced.
[0019] In conjunction with the second aspect, in one possible implementation, the electronic device determines the display format of the display elements of the page to be displayed in the first application based on the key file and the first value file, and then displays the page to be displayed. This includes: the electronic device determining the first key of the display elements of the page to be displayed in the first application; the electronic device finding the position of the first key in the key file, and then obtaining the index value of the value corresponding to the first key in the first value file based on the first mapping relationship; the electronic device finding the first value in the first value file based on the index value; and the electronic device displaying the page to be displayed according to the first value. This specifically describes how the electronic device runs the first application based on the converted internationalization resource file. By directly loading the internationalization resource key and value, the time spent parsing internationalization resources each time the application starts or the application language is switched can be reduced.
[0020] In one possible implementation, the data structure hierarchy of the first resource file is the first level, and the data structure hierarchy of the key file is the second level, with the values in the second level being lower than those in the first level. This embodiment establishes a lookup mapping relationship between keys and values, flattening the resource file structure, which can accelerate the search for internationalized target values and reduce the time spent parsing internationalized resources each time the first application starts or when application resource files are switched.
[0021] In conjunction with the second aspect, in one possible implementation, the data structure of each key in the key file includes: the index of the key in the string, the length of the key, the position of the corresponding value in value.bin, and the index position of the next key node in the key file.
[0022] In one possible implementation, the index position of the next key node in the key file for each key is calculated using a hash.
[0023] Thirdly, this application provides an electronic device, including: one or more processors and one or more memories; the one or more memories are coupled to the one or more processors; the one or more memories are used to store computer program code, the computer program code including computer instructions; when the computer instructions are executed on the processor, the electronic device causes the electronic device to perform the resource search method in any possible implementation of any of the above aspects.
[0024] Fourthly, embodiments of this application provide a computer storage medium including computer instructions that, when executed on an electronic device, cause a communication device to perform the resource search method in any of the possible implementations of any of the above aspects.
[0025] Fifthly, embodiments of this application provide a computer program product that, when run on a computer, causes the computer to execute the resource search method in any of the possible implementations of any of the above aspects. Attached Figure Description
[0026] Figure 1 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0027] Figure 2 A set of application scenario diagrams provided for embodiments of this application;
[0028] Figure 3 A schematic diagram of the software structure of an electronic device provided in an embodiment of this application;
[0029] Figure 4 A flowchart illustrating a resource conversion method provided in this application embodiment;
[0030] Figure 5 A flowchart illustrating a resource search method provided in this application embodiment;
[0031] Figure 6 A flowchart illustrating another resource conversion method provided in this application embodiment;
[0032] Figure 7 A flowchart illustrating another resource conversion method provided in this application embodiment;
[0033] Figure 8 A flowchart illustrating another resource conversion method provided in this application embodiment. Detailed Implementation
[0034] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " represents "or," for example, A / B can represent A or B; the word "and / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0035] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying relative importance or implicitly indicating the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of embodiments of this application, unless otherwise stated, "multiple" means two or more. The terms "middle," "left," "right," "upper," and "lower," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, and are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application.
[0036] The electronic device 100 involved in the embodiments of this application will be introduced first below.
[0037] See Figure 1 , Figure 1 A schematic diagram of the structure of an exemplary electronic device 100 provided in an embodiment of this application is shown.
[0038] Electronic device 100 may include processor 110, external memory interface 120, internal memory 121, universal serial bus (USB) interface 130, charging management module 140, power management module 141, battery 142, antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0039] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0040] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0041] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0042] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0043] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0044] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple I2C buses. The processor 110 can couple to the touch sensor 180K, charger, flash, camera 193, etc., through different I2C bus interfaces. For example, the processor 110 can couple to the touch sensor 180K through the I2C interface, enabling the processor 110 and the touch sensor 180K to communicate through the I2C bus interface, thereby realizing the touch function of the electronic device 100.
[0045] The I2S interface can be used for audio communication. In some embodiments, the processor 110 may include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to enable communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the I2S interface to enable the function of answering phone calls through a Bluetooth headset.
[0046] The PCM interface can also be used for audio communication, sampling, quantizing, and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via the PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface, enabling the function of answering phone calls through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0047] The UART interface is a universal serial data bus used for asynchronous communication. This bus can be a bidirectional communication bus. It converts the data to be transmitted between serial and parallel communication. In some embodiments, the UART interface is typically used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 via the UART interface to implement Bluetooth functionality. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the UART interface to enable music playback through Bluetooth headphones.
[0048] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI) and a display serial interface (DSI). In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to enable the electronic device 100 to capture images. The processor 110 and the display screen 194 communicate via the DSI interface to enable the electronic device 100 to display images.
[0049] The GPIO interface can be configured via software. It can be configured as a control signal or a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 to a camera 193, a display screen 194, a wireless communication module 160, an audio module 170, a sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0050] USB port 130 is a USB standard compliant interface, specifically a Mini USB port, Micro USB port, USB Type-C port, etc. USB port 130 can be used to connect a charger to charge electronic device 100, and can also be used for data transfer between electronic device 100 and peripheral devices. It can also be used to connect headphones for audio playback. This interface can also be used to connect other electronic devices, such as AR devices.
[0051] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0052] The charging management module 140 receives charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 receives charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 receives wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.
[0053] The power management module 141 connects the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, providing power to the processor 110, internal memory 121, external memory, display screen 194, camera 193, and wireless communication module 160, etc. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance). In some other embodiments, the power management module 141 may also be located within the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be located in the same device.
[0054] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0055] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.
[0056] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1. In some embodiments, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 may be housed in the same device.
[0057] The modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through an audio device (not limited to speaker 170A, receiver 170B, etc.) or displays images or videos through the display screen 194. In some embodiments, the modem processor may be a separate device. In other embodiments, the modem processor may be independent of the processor 110 and may be housed in the same device as the mobile communication module 150 or other functional modules.
[0058] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including UWB, wireless local area networks (WLAN) (such as wireless fidelity (WiFi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0059] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling electronic device 100 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).
[0060] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0061] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be made of liquid crystal display (LCD), or organic light-emitting diode (OLED), active-matrix organic light-emitting diode (AMOLED), flexible light-emitting diode (FLED), minimized, microLED, micro-OLED, quantum dot light-emitting diodes (QLED), and other materials. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.
[0062] In some embodiments of this application, the display screen 194 displays the interface content currently output by the system. For example, the interface content is the interface provided by an instant messaging application.
[0063] Electronic device 100 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.
[0064] The ISP (Image Signal Processor) is used to process data fed back from the camera 193. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, and the camera's photosensitive element transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. The ISP can also perform algorithmic optimization of image noise, brightness, and skin tone. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 193.
[0065] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1.
[0066] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.
[0067] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. Thus, electronic device 100 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0068] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0069] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0070] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0071] Electronic device 100 can implement audio functions, such as music playback and recording, through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.
[0072] The audio module 170 is used to convert digital audio information into analog audio signals for output, and also to convert analog audio input into digital audio signals. The audio module 170 can also be used for encoding and decoding audio signals. In some embodiments, the audio module 170 may be located in the processor 110, or some functional modules of the audio module 170 may be located in the processor 110.
[0073] The speaker 170A, also known as a "loudspeaker," is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or make hands-free calls through the speaker 170A.
[0074] The receiver 170B, also known as the "earpiece," is used to convert audio electrical signals into sound signals. When the electronic device 100 answers a telephone call or voice message, the receiver 170B can be brought close to the ear to listen to the voice.
[0075] Microphone 170C, also known as a "microphone" or "voice transducer," is used to convert sound signals into electrical signals. When making a phone call or sending a voice message, the user can speak by bringing their mouth close to microphone 170C, inputting the sound signal into microphone 170C. Electronic device 100 may have at least one microphone 170C. In some embodiments, electronic device 100 may have two microphones 170C, which, in addition to collecting sound signals, can also perform noise reduction. In other embodiments, electronic device 100 may also have three, four, or more microphones 170C, which can collect sound signals, reduce noise, identify the sound source, and perform directional recording, etc.
[0076] The 170D headphone jack is used to connect wired headphones. The 170D headphone jack can be a USB 130 interface or a 3.5mm Open Mobile Terminal Platform (OMTP) standard interface, a CTIA (Cellular Telecommunications Industry Association of the USA) standard interface.
[0077] Pressure sensor 180A is used to sense pressure signals and can convert the pressure signals into electrical signals. In some embodiments, pressure sensor 180A may be disposed on display screen 194. In some optional embodiments of this application, pressure sensor 180A may be used to capture the pressure value generated when a user's finger touches the display screen and transmit the pressure value to the processor so that the processor can identify which finger the user is using to input the user operation.
[0078] There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, and capacitive pressure sensors. A capacitive pressure sensor may include at least two parallel plates with conductive material. When force is applied to the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the pressure intensity based on the change in capacitance. When a touch operation is applied to the display screen 194, the electronic device 100 detects the intensity of the touch operation based on the pressure sensor 180A. The electronic device 100 can also calculate the touch position based on the detection signal from the pressure sensor 180A. In some embodiments, different touch positions can correspond to different operation commands. In some optional embodiments, the pressure sensor 180A can also calculate the number of touch points based on the detected signal and transmit the calculated value to the processor, allowing the processor to recognize whether the user inputs the operation using a single finger or multiple fingers.
[0079] The gyroscope sensor 180B can be used to determine the motion attitude of the electronic device 100. In some embodiments, the gyroscope sensor 180B can determine the angular velocity of the electronic device 100 around three axes (the X-axis, Y-axis, and Z-axis of the electronic device). The gyroscope sensor 180B can be used for image stabilization. For example, when the shutter is pressed, the gyroscope sensor 180B detects the angle of the shake of the electronic device 100, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to counteract the shake of the electronic device 100 by moving in the opposite direction, thus achieving image stabilization. The gyroscope sensor 180B can also be used in navigation and motion-sensing game scenarios.
[0080] The barometric pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates altitude using the air pressure value measured by the barometric pressure sensor 180C to assist in positioning and navigation.
[0081] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip cover. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover using the magnetic sensor 180D. Then, based on the detected opening and closing state of the cover or the flip cover, features such as automatic flip unlocking can be set.
[0082] Accelerometer 180E can detect the magnitude of acceleration of electronic device 100 in various directions (generally three axes). When electronic device 100 is stationary, it can detect the magnitude and direction of gravity. It can also be used to identify the posture of electronic device and applied to applications such as screen orientation switching and pedometers. In some optional embodiments of this application, accelerometer 180E can be used to capture the acceleration value generated when a user's finger touches the display screen (or the user's finger taps the rear edge of the back cover of electronic device 100) and transmit the acceleration value to the processor so that the processor can identify which finger the user used to input the operation.
[0083] A distance sensor 180F is used to measure distance. Electronic device 100 can measure distance via infrared or laser. In some embodiments, during a shooting scene, electronic device 100 can utilize the distance sensor 180F to measure distance for rapid focusing.
[0084] The proximity sensor 180G may include, for example, a light-emitting diode (LED) and a light detector, such as a photodiode. The LED may be an infrared LED. The electronic device 100 emits infrared light outward through the LED. The electronic device 100 uses the photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100. The electronic device 100 may use the proximity sensor 180G to detect when a user holds the electronic device 100 close to their ear for a phone call, so as to automatically turn off the display screen to save power. The proximity sensor 180G can also be used in holster mode and pocket mode for automatic unlocking and screen locking.
[0085] The ambient light sensor 180L is used to sense the brightness of ambient light. The electronic device 100 can adaptively adjust the brightness of the display screen 194 based on the sensed ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also work with the proximity sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.
[0086] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can utilize the characteristics of the collected fingerprints to achieve fingerprint unlocking, accessing application locks, taking photos with fingerprints, answering calls with fingerprints, etc.
[0087] Temperature sensor 180J is used to detect temperature. In some embodiments, electronic device 100 uses the temperature detected by temperature sensor 180J to execute a temperature handling strategy. For example, when the temperature reported by temperature sensor 180J exceeds a threshold, electronic device 100 performs thermal protection by reducing the performance of a processor located near temperature sensor 180J to reduce power consumption. In other embodiments, when the temperature is below another threshold, electronic device 100 heats battery 142 to prevent abnormal shutdown of electronic device 100 due to low temperature. In still other embodiments, when the temperature is below yet another threshold, electronic device 100 boosts the output voltage of battery 142 to prevent abnormal shutdown due to low temperature.
[0088] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touchscreen." Touch sensor 180K detects touch operations applied to or near it, such as actions by a user's hand, elbow, stylus, etc., touching display screen 194. The touch sensor transmits the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.
[0089] The bone conduction sensor 180M can acquire vibration signals. In some embodiments, the bone conduction sensor 180M can acquire vibration signals from the vibrating bone segments of the human vocal cords. The bone conduction sensor 180M can also contact the human pulse to receive blood pressure signals. In some embodiments, the bone conduction sensor 180M can also be incorporated into headphones to form bone conduction headphones. The audio module 170 can parse the voice signals from the vibrating bone segments of the vocal cords acquired by the bone conduction sensor 180M to realize voice functionality. The application processor can parse heart rate information from the blood pressure signals acquired by the bone conduction sensor 180M to realize heart rate detection functionality.
[0090] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Electronic device 100 can receive button input and generate key signal inputs related to user settings and function control of electronic device 100.
[0091] Motor 191 can generate vibration alerts. Motor 191 can be used for incoming call vibration alerts or for touch vibration feedback. For example, different vibration feedback effects can correspond to touch operations performed on different applications (such as taking photos, playing audio, etc.). Motor 191 can also correspond to different vibration feedback effects for touch operations performed on different areas of the display screen 194. Different application scenarios (such as time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also be customized.
[0092] Indicator 192 can be an indicator light, used to indicate charging status, power changes, or to indicate messages, missed calls, notifications, etc.
[0093] The SIM card interface 195 is used to connect a SIM card. The SIM card can be inserted into or removed from the SIM card interface 195 to make contact with or separate from the electronic device 100.
[0094] This application embodiment involves operations such as searching, switching, and running internationalized resources for applications. Internationalized resources include different application resources (including language resources, display resources, etc.) for the same application running in different countries and regions. Electronic device 100 can determine the application resources currently required for its application to run based on the user's current country or region; electronic device 100 can also determine the application resources currently required for its application to run based on the country or region selected by the user.
[0095] For example, each language environment in an application has a corresponding directory containing a language resource file. If an application supports running in both English and Chinese language environments, it must contain two language resource files, one for English and one for Chinese. The language resource file consists of multiple key-value pairs. The lookup path for a display element on each page of the application is the key, and the display format of each element is the value. The electronic device 100 locates the corresponding language resource file in the directory based on the current application's language environment or the system's language environment, and then uses a specific key to retrieve the corresponding value to display to the user in the specific business scenario.
[0096] In some scenarios, such as Figure 2As shown, the application's language resource files include a language A resource file (A.json) and a language B resource file (B.json). Each language resource file consists of multiple key-value pairs. For example, in language A, one key might be "string.origin" with the value "country"; another key might be "string.state" with the value "state"; and so on. Similarly, in language B, one key might be "string.origin" with the value "country"; another key might be "string.state" with the value "state"; and so on.
[0097] When the application resource required by the application of electronic device 100 is a language A resource file, the application framework reads and parses the language A resource file, electronic device 100 starts the application, runs the language A resource file, and displays the language of the application page as language A. For example... Figure 2 On the application page 201 of the electronic device 100 running language A resource files, "Country" and "Status" are displayed. When the application resource currently required by the application on the electronic device 100 is switched to a language B resource file, the application framework reads and parses the language B resource file, the electronic device 100 restarts the application, runs the language B resource file, and the language displayed on the application page of the electronic device 100 is language B, for example... Figure 2 In the context of application page 202, which includes the same display elements as application page 201, application page 202 of electronic device 100 running B language resource files displays "country" and "state".
[0098] Currently, in some possible implementations, when electronic device 100 wants to switch application resources, it needs to restart the application and parse the application resources to be switched. Electronic device 100 can read the attribute parameters set in the application's page nodes to obtain the corresponding page loading resource path; then, it loads the corresponding resource files according to this resource path, and loads them in a preset order, replacing the corresponding content with the internationalized content, thereby displaying the internationalized application page. Specifically,
[0099] Step 1: Electronic device 100 runs the first application. If it needs to display the first application page, electronic device 100 first determines the attribute parameters set in the page node of the first application page. These attribute parameters include one or more key values and indicate that electronic device 100 needs to load internationalization resource files. Based on the attribute parameters of the first application page, electronic device 100 determines the path of the internationalization resource file for the first application page.
[0100] Step 2: After determining the path of the internationalization resource file of the first application page, the electronic device 100 obtains the corresponding internationalization resource file (such as Chinese language resource file, English language resource file, etc.) according to the language environment of the first application page, and loads it in a preset order.
[0101] Step 3: After the electronic device 100 successfully loads the internationalization resource file, it parses the content stored in the internationalization resource file into a key-value pair and stores it using a public Map (a Map provides a method for storing elements; it stores elements in key-value pairs, disallows duplicate keys, but allows different keys to correspond to duplicate values). Here, the key corresponds to the resource path of the element displayed in the resource file, and the value is the internationalization content corresponding to the element displayed in the resource file. The public Map provides a mapping relationship where elements are stored in key-value pairs, enabling quick lookup of values based on keys. Key values in the public Map are unique and cannot be duplicated.
[0102] Step 4: Electronic device 100 retrieves the corresponding key and value values from the Map based on the attribute parameters of the first application page, determines the content to be displayed on the first application page, and then displays the first application page.
[0103] The above steps describe the process of the electronic device 100 calling internationalization resource files when running the first application. When the electronic device 100 calls a Chinese language resource file, the display language of the application interface of the first application is Chinese; when the electronic device 100 calls an English language resource file, the display language of the application interface of the first application is English. If the user wants to switch the application resources running the first application, for example, to change the display language of the application interface of the first application from Chinese to English, the electronic device 100 parses the application resource to be switched (the English language resource file) and executes steps one to four above again to achieve the switching of different application resources in the first application.
[0104] However, with this method, when the electronic device 100 switches application resources for the first application, it re-parses the resources, resulting in longer application startup time and impacting user experience. Furthermore, installing the first application requires packaging all application resources, leading to duplicate keys and a larger installation package, wasting time during download and installation. Additionally, if the electronic device 100's resources are limited, such as insufficient memory or processing power, it may be unable to parse internationalized resources, causing abnormal page display in the first application.
[0105] In some possible implementations, the electronic device 100 can obtain the internationalization resource files of the first application through a third-party server of the first application, process the internationalized UI elements through the third-party server, and then display the corresponding application page after receiving the processed output. Specifically,
[0106] Step 1: Electronic device 100 receives an internationalization resource request for the first application. Based on the internationalization resource request, electronic device 100 sends a request to the third-party server of the first application to obtain the internationalization resource file.
[0107] Step 2: The third-party server of the first application responds to the request and determines the page that electronic device 100 needs to display based on the internationalized resource file requested by electronic device 100. The third-party server of the first application processes the internationalized UI elements and provides the UI elements that need to be displayed to electronic device 100. Electronic device 100 displays the page that needs to be displayed based on the received UI elements.
[0108] Optionally, step two can also involve the electronic device 100 receiving the internationalization resource file of the first application, retrieving the corresponding key and value values from the internationalization resource file based on the attribute parameters of the page that the first application currently needs to display, and determining the content to be displayed on the page. The electronic device 100 then processes the internationalized UI elements and displays the page that needs to be displayed.
[0109] This reduces the size of the first application's installation package, resolving the issue of wasted time during download and installation. However, electronic device 100 needs to make network requests to obtain corresponding internationalized resources, which cannot be processed offline. Furthermore, relying on the capabilities of other devices via network or Bluetooth increases the overall running time, resulting in a longer display time for the first application.
[0110] Based on the above two methods, this application embodiment also provides a method for processing internationalized resource files, which can solve the problem that internationalized resource files need to be parsed every time the application starts or switches application resource files, resulting in long internationalization time.
[0111] In this embodiment of the application, the electronic device 100 runs a first application. The internationalization resource file of the first application is a resource file after key-value pair splitting. The electronic device 100 can split the internationalization resource file into key-value pairs during the installation of the first application; it can also split the internationalization resource file into key-value pairs during the packaging and compilation of the first application to generate the installation package of the first application; or it can obtain the internationalization resource file after key-value pair splitting from other devices; this application does not limit this.
[0112] Electronic device 100 runs a first application and determines the lookup path key value of the display element of the page to be displayed. If the current running environment of the first application is a first running environment, electronic device 100 looks up the value corresponding to the key value in a first value file. The electronic device displays the page to be displayed based on the value value of the display element of the first page. If the current running environment of the first application is a second running environment, electronic device 100 looks up the value corresponding to the key value in a second value file. The electronic device displays the page to be displayed based on the value value of the display element of the first page. In this embodiment, by directly loading the internationalization resource key and value, the time for parsing internationalization resources can be reduced each time the application starts or the application language is switched.
[0113] The following is a software structure block diagram of the electronic device 100 according to an embodiment of this application.
[0114] like Figure 3 As shown, the layered architecture divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system libraries, and the hardware abstraction layer (HAL). Figure 3 (Not illustrated in the text), and the kernel layer.
[0115] The application layer can include a series of application packages.
[0116] like Figure 3As shown, the application package can include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, games, shopping, travel, and instant messaging (such as SMS). Additionally, the application package may also include system applications such as the home screen (desktop), the negative one screen, control center, and notification center.
[0117] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0118] like Figure 3 As shown, the application framework layer may include an input manager, window manager, content provider, view system, phone manager, resource manager, notification manager, display manager, activity manager, internationalization module, etc. For ease of explanation, Figure 3 In this example, the application framework layer includes an input manager, content provider, notification manager, view system, resource manager, and internationalization module. It should be noted that any two modules among the input manager, content provider, notification manager, view system, resource manager, and internationalization module can call each other.
[0119] The input manager is used to receive instructions or requests reported by lower layers such as the kernel layer and hardware abstraction layer.
[0120] Content providers store and retrieve data, making that data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.
[0121] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0122] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, application resource files (such as JSON files), and so on.
[0123] In this embodiment, the application resource file includes multiple resource files for different operating environments. For example, the resource file for a Chinese environment is a Chinese language resource file, and the resource file for an English environment is an English language resource file. Each resource file consists of multiple key-value pairs, "key"-"value". The lookup path for each display element on each page of the application is the "key", and the display format of each display element is the "value". Based on the operating environment set by the current application, the resource manager provides the corresponding application resource file to the application. The application retrieves the corresponding value through a specific key in a specific business scenario to display the corresponding application page.
[0124] The internationalization module is used to convert application resource files, separating key-value pairs and converting them into key and value files. Since the business scenario of an application is fixed, the display elements required by an application are the same in each runtime environment; only the value values corresponding to the display elements differ in different resource files. In this embodiment, the internationalization module separates multiple resource files into key-value pairs, saving the keys from multiple resource files into a single file and removing duplicate keys. That is, the internationalization module converts n resource files into one key file and n value files, with each of the n value files corresponding one-to-one with the n resource files, and each value file containing the value from one of the resource files. This reduces redundant storage of key values across multiple resource files and reduces the size of the application resource files.
[0125] The internationalization module can also be used to parse, search, and index application resource files. This embodiment reduces the time spent parsing internationalization resources each time the application starts or the application language is switched by loading the split internationalization resource keys and values.
[0126] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of completed downloads or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.
[0127] A window manager is used to manage window programs. The window manager can obtain the screen size, determine if a status bar exists, lock the screen, and capture the screen, etc. In this application, the window manager is used to display a window including one or more shortcut controls when the electronic device 100 meets preset triggering conditions.
[0128] The Activity Manager is used to manage the activities running in the system, including information on processes, applications, services, and tasks.
[0129] The display manager is used to transmit display content to the kernel layer.
[0130] The phone manager is used to provide communication functions for electronic device 100. For example, it manages call status (including connection and disconnection).
[0131] The Android Runtime consists of core libraries and a virtual machine. The Android runtime is responsible for scheduling and managing the Android system.
[0132] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.
[0133] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0134] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0135] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.
[0136] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.
[0137] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0138] A 2D graphics engine is a graphics engine for 2D drawing.
[0139] The Hardware Abstraction Layer (HAL) serves as the interface between operating system software and hardware components, providing a platform for interaction between upper-layer software and lower-layer hardware. The HAL abstracts the underlying hardware into software containing corresponding hardware interfaces. By accessing the HAL, settings can be configured for the underlying hardware devices; for example, enabling or disabling relevant hardware components can be done within the HAL. In some embodiments, the core architecture of the HAL layer is constructed using at least one of C++ or C++.
[0140] The kernel layer is the layer between hardware and software. The kernel layer includes at least the display driver, camera driver, audio driver, sensor driver, touch chip driver, and input system. For ease of explanation, Figure 3 In this example, the kernel layer includes the input system, touch chip driver, display driver, and storage driver. The display driver and storage driver can be jointly configured within the driver module.
[0141] It is understood that the structure illustrated in this application does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0142] Based on the software structure diagram of the electronic device 100 described above, the following describes the steps of a method for converting internationalized resource files provided in this application, as follows: Figure 4 As shown, it may include:
[0143] Step S401: Electronic device 100 downloads the first application.
[0144] Download the first application from Electronic Device 100. This first application is an internationally supported application, meaning that its application resources include internationally relevant resources.
[0145] Specifically, when electronic device 100 receives a user's operation to download the first application, in response to the operation, electronic device 100 can download the first application through the application market and obtain the apk file of the first application.
[0146] Step S402: Electronic device 100 detects that the installation package of the first application includes internationalization resource files.
[0147] After obtaining the installation package of the first application, the electronic device 100 installs the first application through the installation module. During the installation process, the installation module of the electronic device 100 detects that the installation package (apk file) of the first application includes internationalization resource files.
[0148] Specifically, the electronic device 100 detects that the installation package of the first application contains internationalization resource files using certain search rules. These search rules can include, for example, a specified file extension, a specified file path, or the file content containing a preset mapping relationship. For instance, if the user specifies the file extension ".json", and the installation package of the first application contains files with that extension, then the electronic device 100 determines that the installation package of the first application contains internationalization resource files; that is, files with that extension are internationalization resource files.
[0149] Step S403: The installation module of electronic device 100 calls the internationalization conversion interface and sends a conversion request for internationalization resource files to the internationalization module.
[0150] Step S404: Electronic device 100 reads the internationalization resource file, which stores data in a key-value pair format.
[0151] In response to a conversion request for an internationalized resource file, the internationalization module of the electronic device 100 reads the internationalized resource file from the resource manager.
[0152] The internationalization resource file includes multiple resource files, such as Chinese language resource files and English language resource files. These resource files store data using key-value pairs. Since the business scenario of the same application is fixed, the display elements that an application needs to display are the same in each runtime environment; only the value corresponding to the display element differs in different resource files.
[0153] Step S405: Electronic device 100 converts the internationalization resource file and performs key-value pair separation.
[0154] The internationalization module of electronic device 100 converts internationalization resource files. It separates multiple resource files within the internationalization resource file into key-value pairs, saving the keys from multiple resource files into a single file and removing duplicate keys. Specifically, the internationalization module converts n resource files into one key file and n value files, with each of the n value files corresponding one-to-one with the n resource files. Each value file includes the value from one of the resource files. This reduces redundant storage of key values across multiple resource files and decreases the size of the internationalization resource file.
[0155] For example, the internationalized resource file before conversion includes a Chinese language resource file (json file) and an English language resource file (json file), and the converted internationalized resource file includes a key.bin file, a value.bin file corresponding to the Chinese language resource file, and a value.bin file corresponding to the English language resource file. The key.bin file includes the key values of the Chinese language resource file and the English language resource file.
[0156] In some embodiments, the internationalization module of the electronic device 100 splits n resource files into key-value key-value pairs, which is split into a key file and n value files, which is an exemplary case. To facilitate file management, lookup and indexing, n value files may be merged or split into one or more files, and one key file may also be split into multiple files.
[0157] Optionally, taking the Chinese language resource file as an example, the following exemplarily shows part of the content of a Chinese language resource file before conversion, and the Chinese language resource file stores data by using a key-value pair “key” - “value”. This Chinese language resource file includes:
[0158]
[0159]
[0160] The multiple groups of key-value pairs include “address. HangZhou” (key) - “HangZhou” (value), “address. ShangHai” (key) - “ShangHai” (value), “Good” (key) - “good” (value), “Date. Monday” (key) - “Monday” (value), etc. Similarly to the Chinese language resource file, the key values of the other language resource files and the Chinese language resource file are the same, and the corresponding values are different. For example, an English language resource file includes:
[0161]
[0162] This section introduces two concepts: child nodes and sibling nodes. A child node is a relative concept; a node at one level below the current node is considered a child node. For example, the nodes ShangHai and HangZhou mentioned above can be considered child nodes of the node address. A sibling node, on the other hand, is a node at the same level. For instance, ShangHai and HangZhou can be considered sibling nodes, as can nodes like address, Good, Unhealth, Normal, and Date.
[0163] In some embodiments, the internationalization module of the electronic device 100 converts multiple resource files in the application resource files into corresponding structures, i.e., the separation of "key"-"value" pairs. Based on the Chinese language resource files and English language resource files shown above, the following is an exemplary partial content of a converted key.bin file. This key.bin file includes relevant information about the keyNode nodes in the Chinese and English language resource files. This key.bin file includes:
[0164] address HangZhou ShangHai Good Unhealth Norma lairQuality Date MondayTuesday Wednesday Thursday Friday Saturday Sunday
[0165] As can be seen, the key.bin file includes the keyNode data from the Chinese and English language resource files shown above.
[0166] For example, based on the Chinese language resource file shown above, the following is an example of a portion of the content of the A-value.bin file corresponding to the converted Chinese language resource file. This A-value.bin file includes the value of `value`. For example, this A-value.bin file includes:
[0167] Air quality monitoring in Hangzhou and Shanghai: Good, Poor, Fair - Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
[0168] As can be seen, the A-value.bin file includes the value data from the Chinese language resource file shown above.
[0169] For example, based on the Chinese language resource file shown above, the following is an example of a portion of the B-value.bin file corresponding to the converted English language resource file. This B-value.bin file includes the value of `value`. For example, this B-value.bin file includes:
[0170] HangZhou ShangHai Good Unhealth Normal airQuality Monday TuesdayWednesday Thursday Friday Saturday Sunday
[0171] As can be seen, the B-value.bin file includes the value data from the English language resource file shown above.
[0172] Among them, electronic device 100 can obtain the corresponding value from the corresponding value.bin file based on the key.bin file.
[0173] Optionally, the key.bin file and the value.bin file have a mapping relationship. The electronic device 100 indexes based on the mapping relationship between the key.bin file and the value.bin file to determine the value corresponding to each key. The indexing method of the electronic device 100 for the key.bin file and the value.bin file is related to the preset data structure.
[0174] The following example illustrates a data structure. It should be noted that this does not constitute a limitation on the data structures of the embodiments of this application.
[0175] Taking the key.bin file shown above as an example, the data structure of each node in the key.bin file can include the key value, the type of the next node, the index of the corresponding child node or the corresponding value, and the node offset. Among them, the type of the next node indicates whether the next node is a child node of the current node; the node offset is the position offset of the next node relative to the current node, that is, it indicates the position of the next node in the key.bin file.
[0176] For example, the data structure of the three nodes address, HangZhou, and ShangHai in the key.bin file includes:
[0177] Line 0: address 1 1 -1
[0178] Line 1: ShangHai 0 2 2
[0179] Line 2 HangZhou 0 1 3
[0180] Starting from line 0, where `address` is the value of `key`; the type of the next node is 1, indicating that the next node is a child node of the current node; the index of the corresponding child node is 1, indicating that the child node is in line 1; the offset of the sibling node is -1. Thus, the index reaches line 1, where `ShangHai` is the value of `key`; the type of the next node is 0, indicating that the next node is a node at the same level as the current node; 2 refers to the index of the corresponding value in the `value.bin` file; the node offset is 2, indicating that the next node is in line 2. Thus, the index reaches line 2, which will not be elaborated further.
[0181] Correspondingly, taking the A-value.bin file shown above as an example, each node in the A-value.bin file can include a data structure that includes the index of the value in the string and the length of the value. The index of the value in the string determines the starting position of the value.
[0182] For example, the data structures for the two values, Hangzhou and Shanghai, in the A-value.bin file include:
[0183] Line 0: Hangzhou, Shanghai... (value string)
[0184] Line 1 0 6
[0185] Line 2, 6, 6
[0186] Taking the node ShangHai as an example, the index of the value corresponding to ShangHai is 2, so the index is in the 2nd row. 6 refers to the index of the value and the length of the value. That is, the value corresponding to the key is offset by 6 bytes from the 6th byte.
[0187] In some embodiments, the internationalization module of the electronic device 100 converts multiple resource files in the application resource file into corresponding structures. Since the internationalization resource file generally only needs the final value result, the last level in the application resource file is mainly cached here. This can flatten the data structure of the resource file and improve the data lookup efficiency of the resource file.
[0188] Based on the Chinese and English language resource files shown above, the following is an example of a partial content of a converted key.bin file. This key.bin file includes information about the keyNode nodes in both the Chinese and English language resource files. This key.bin file includes:
[0189] address.HangZhou address.ShangHai Good Unhealth Normal airQualityDate.Monday Date.Tuesday Date.Wednesday Date.Thursday Date.FridayDate.Saturday Date.Sunday
[0190] As can be seen, the key.bin file in this embodiment includes the keyNode data from the Chinese and English language resource files shown above. It only stores the nodes at the last level of the resource files, and flattens the parent nodes above the last level (such as the address and date nodes), converting the data structure in the key.bin file from a two-level structure to a single-level structure. Furthermore, since the address and date nodes are not the last level in the resource files and do not have corresponding values, their absence from the converted key.bin file will not affect data retrieval.
[0191] For example, based on the Chinese language resource files and English language resource files shown above, the A-value.bin files and B-value.bin files corresponding to the converted Chinese language resource files and English language resource files can be referred to the A-value.bin files and B-value.bin files shown in the above embodiments, which will not be repeated here.
[0192] Among them, electronic device 100 can obtain the corresponding value from the corresponding value.bin file based on the key.bin file.
[0193] Optionally, the key.bin file and the value.bin file have a mapping relationship. The electronic device 100 indexes based on the mapping relationship between the key.bin file and the value.bin file to determine the value corresponding to each key. The indexing method of the electronic device 100 for the key.bin file and the value.bin file is related to the preset data structure.
[0194] The following example illustrates a data structure. It should be noted that this does not constitute a limitation on the data structures of the embodiments of this application.
[0195] Taking the key.bin file shown above as an example, the data structure of each node in the key.bin file can include the index of the key in the string, the length of the key, the position of the corresponding value in value.bin, and the position of the next node in the key.bin file. Among them, the index of the key in the string can determine the starting position of the key value.
[0196] For example, the data structure of the two nodes HangZhou and ShangHai in the key.bin file includes:
[0197] Line 0: HangZhouShangHai……(key value string)
[0198] Line 1: 0 8 0 2
[0199] Line 2: 8 8 1 3
[0200] Starting from line 1, the 0 and 8 in line 1 determine the position of the key value in the string, that is, offsetting 8 bytes from the 0th character, the key value is HangZhou; the corresponding value in value.bin is position 0; the next node is position 2, which is line 2. Thus, the index has reached line 2. In line 2, the 8 and 8 determine the position of the key value in the string, that is, offsetting 8 bytes from the 8th character, the key value is ShangHai; the corresponding value in value.bin is position 1; the next node is position 3, which is line 3. Thus, the index has reached line 3, which will not be elaborated further.
[0201] Optionally, the index position (referring to the line number) of each key value in the key.bin file can be calculated by hashing, that is, hashing the key value to obtain the corresponding index position in the key.bin file.
[0202] Correspondingly, taking the A-value.bin file shown above as an example, one data structure for each node in the A-value.bin file can include the index of the value in the string and the length of the value. The index of the value in the string determines the starting position of the value. For a detailed description of this, please refer to the relevant description of one data structure for each node in the A-value.bin file mentioned above; it will not be repeated here.
[0203] The above example using the key.bin file illustrates two different data structures. It should be noted that the bin files (including key.bin and value.bin files) obtained from different data structures have different versions. Different versions of bin files can be converted between each other using a version conversion tool.
[0204] Step S406: Electronic device 100 completes the conversion of internationalized resource files, and the installation of the first application is completed.
[0205] Thus, when the electronic device 100 is running the first application and calls the corresponding internationalized resource file in the selected operating environment, it calls the converted resource file.
[0206] In some embodiments, after the electronic device 100 completes the conversion of the internationalization resource file, it can delete the internationalization resource file before conversion to save resources; alternatively, it can retain the internationalization resource file before conversion to adapt to subsequent data structure version conversions, eliminating the need to download the internationalization resource file before conversion again for the latest version conversion during version conversion. Optionally, the electronic device 100 can decide whether to delete the internationalization resource file before conversion based on its own memory resources. If the storage resources of the electronic device 100 are scarce, it will delete it; otherwise, it will retain it.
[0207] In this embodiment, by parsing and converting internationalization resources throughout the installation package during the installation of the first application and storing them as keys and values, the memory pressure during application resource file switching and startup can be reduced. This embodiment establishes a key-value lookup mapping relationship and flattens the resource file structure, which can accelerate the search for internationalization target values and reduce the time spent parsing internationalization resources each time the first application starts or during application resource file switching.
[0208] Steps S401 to S406 above describe the process by which electronic device 100 converts the internationalization resource files in the installation package of the first application during the installation of the first application.
[0209] After the electronic device 100 has installed the first application based on steps S401 to S406, it runs the first application. The electronic device 100 then searches for the corresponding internationalization resource files based on the selected operating environment. The following... Figure 5 This illustrates the specific process for finding internationalized resource files, such as... Figure 5 As shown, it includes:
[0210] Step S501: Electronic device 100 runs the first application.
[0211] The electronic device 100 runs a first application. The configuration information in the first application includes the current running environment of the first application. Based on the currently set running environment of the first application, the electronic device 100 calls the corresponding application resources to run the first application. In some embodiments, the user can select or switch the running environment of the first application.
[0212] Step S502: The first application of the electronic device 100 sends an internationalization resource request to the internationalization module. The internationalization resource request includes the key value of the display element of the interface to be displayed of the first application.
[0213] Electronic device 100 runs a first application and needs to load display elements for the page to be displayed. Based on the current operating environment of electronic device 100 (e.g., Chinese operating environment, English operating environment, etc.), the first application of electronic device 100 sends a corresponding resource request to the internationalization module to request the required internationalization resources. This internationalization resource request includes the key resources of the display elements to be searched. This key resource can be a single key value or multiple key values of the display elements of the page to be displayed.
[0214] In some embodiments, after the internationalization module of the electronic device 100 receives the internationalization resource request of the first application, the electronic device 100 checks whether this is the first time the first application is being run. This first run could mean the first time the electronic device 100 runs the first application after installation; it could also mean the first time the electronic device 100 runs the first application after an update; or it could mean the first time the electronic device 100 runs the first application after a system update. If yes, the electronic device 100 executes steps S503 to S507; otherwise, the electronic device 100 directly executes step S507.
[0215] Step S503: The internationalization module of electronic device 100 sends a version verification request to the resource manager based on the received internationalization resource request.
[0216] The internationalization module of electronic device 100 reads the configuration information of the first application to determine the current operating environment of the first application, that is, to determine the internationalization resource file that needs to be called. After receiving the internationalization resource request, the internationalization module of electronic device 100 sends a version verification request to the resource manager to verify whether the version of the internationalization resource file to be called matches the target version.
[0217] Optionally, the target version is the latest converted internationalization resource file version in the first application. Since the version of the internationalization resource file requested by the first application may differ from the version of the converted internationalization file—for example, if the first application performs an application update after converting the internationalization resource file, and this update adds several new resource files—then when the internationalization resource file requested by the first application is one of those updated resource files, the version of that resource file will differ from the version of the converted internationalization resource file. Therefore, the internationalization module of electronic device 100 needs to send a version verification request to the resource manager.
[0218] Optionally, the target version is the version of the international resource file preset in electronic device 100. Since the version of the international resource file requested by the first application may differ from the preset version in electronic device 100—for example, if electronic device 100 updates its system and updates the version of the adapted international resource file to the target version—then when the first application requests an international resource file, the version of that resource file will be different from the target version. Therefore, the internationalization module of electronic device 100 needs to send a version verification request to the resource manager.
[0219] Step S504: The resource manager of electronic device 100 verifies whether the version of the internationalization resource file required for the internationalization resource request matches the target version.
[0220] If there is a mismatch, step S505: The resource manager of electronic device 100 provides the required internationalization resource file to the internationalization module and instructs the internationalization module of electronic device 100 to convert the required internationalization resource file.
[0221] Step S506: The internationalization module of the electronic device 100 converts the required internationalization resource file into the target version.
[0222] The conversion method can be referred to the relevant description of step S405 above, and will not be repeated here.
[0223] If a match is found, step S507: The resource manager of electronic device 100 provides the required internationalization resource file to the internationalization module. The version of the required internationalization resource file is the target version.
[0224] Steps S503 to S507 above illustrate the implementation principle of version verification by electronic device 100. It is not limited to the above method. In some embodiments, after receiving an internationalization resource request, the internationalization module of electronic device 100 sends a version verification request to the resource manager to verify whether the version of the internationalization resource file in the current resource manager matches the target version.
[0225] If a mismatch is found, the internationalization module of electronic device 100 converts the mismatched internationalization resource file in the resource manager to the target version. If the version of the internationalization resource file in the resource manager matches the target version, the internationalization module of electronic device 100 reads the configuration information of the first application to determine the current operating environment of the first application, i.e., to determine the internationalization resource file that needs to be called. Then, the internationalization module of electronic device 100 obtains the required internationalization resource file from the resource manager.
[0226] Step S508: The internationalization module of electronic device 100 determines the value of the display element of the page to be displayed in the first application based on the internationalization resource request and the obtained internationalization resource file.
[0227] The internationalization resource request includes key resources for the display elements of the page to be displayed. Electronic device 100 determines the storage location of the key.bin file of the page to be displayed, compares the corresponding stored value (the key value in the key.bin file) with the input value (key resource) according to specified rules, until a match is found. Electronic device 100 then locates the position of the input value (key resource) in the key.bin file and determines the index of the corresponding value in the value.bin file. Based on this index, electronic device 100 finds the internationalization result value corresponding to each input value (key resource) in the value.bin file.
[0228] There is a mapping rule between the key.bin file and the value.bin file. This mapping rule is related to the data structure of the key.bin file and the value.bin file. The data structure of the key.bin file and the value.bin file can be referred to the description in step S405 above, which will not be repeated here.
[0229] Step S509: The internationalization module of the electronic device 100 provides the first application with the value corresponding to the display element of the page to be displayed in the first application.
[0230] The first application displays the page to be displayed based on this value.
[0231] When a user wants to switch the application's running resources, such as switching the display language from Chinese to English, the resource file called by the electronic device 100 is changed from a Chinese language resource file to an English language resource file. The electronic device 100 can repeat the above steps S502 to S509 to call the required resource file.
[0232] Steps S501 to S508 above describe the specific process by which electronic device 100 searches for internationalization resource files. Electronic device 100 reduces the pressure on internationalization memory caching by directly loading the internationalization resource key and value. Furthermore, for devices with limited memory, the corresponding resources can be stored in a cache area with relatively lower speed and performance, reducing application operating costs. Moreover, when multiple instances are running, it is not necessary to cache internationalization resources for multiple applications simultaneously; caching can be performed only for the currently running application. Switching applications only requires reloading the resource files, which can greatly reduce the memory pressure on application caching.
[0233] In some implementations, the electronic device 100 downloads a first application from an application market and obtains its installation package (APK file). The internationalization resource file in this installation package is a key-value pair file, consisting of one key file and n value files. After the electronic device 100 installs the first application based on this installation package, it runs the first application. The electronic device 100 searches for the corresponding internationalization resource file based on the selected operating environment, directly loads the internationalization resource key and value, and executes the steps shown in steps S501 to S508 above, which will not be repeated here.
[0234] In some implementations, the electronic device 100 can convert internationalized resource files during the application compilation stage, thereby reducing the application installation package size without increasing the application installation time.
[0235] Specifically, before step S401 above, before the electronic device 100 downloads the first application, the first application is compiled and packaged using a packaging and compilation module to generate the apk file of the first application.
[0236] The compilation and packaging process includes:
[0237] 1. Package resource files. Resource files include Resource files (files in the res folder of the project, including JSON files), Assets files, AndroidManifest.xml files, Android base libraries (Android.jar files), etc. Electronic device 100 packages the resource files to generate R.java file.
[0238] 2. Compile the project source code. The files containing the project source code include source code files (R.java file) and library files (.jar files). Compile the electronic device 100 project source code to generate the corresponding class files.
[0239] 3. Convert the class file to generate the classes.dex file.
[0240] Fourth, package the packaged resource files (R.java file), packaged class files (dex file), etc., to generate the installation package (apk file) of the first application.
[0241] During the compilation and packaging of the first application using the packaging and compilation module, the electronic device 100 converts the internationalization resource files. This reduces the storage of duplicate keys, thereby reducing the size of the application installation package. Optionally, if the electronic device 100 detects that the internationalization resource files are too large during the compilation and packaging process, it converts the internationalization resource files. Optionally, during the compilation and packaging process, the electronic device 100 outputs a prompt message, and upon receiving a user confirmation command, it converts the internationalization resource files. Figure 6 As shown,
[0242] Step S601: The first application receives an instruction to package or run the application.
[0243] The first application calls the compilation tool, passing in the path to the internationalization resource file, and converts the internationalization resource file.
[0244] Step S602: Electronic device 100 calls the internationalization conversion interface through the packaging and compilation module and sends a conversion request for internationalization resource files to the internationalization module. The conversion request includes the path of the internationalization resource files.
[0245] Step S603: Based on the conversion request, the internationalization module of the electronic device 100 reads the internationalization resource file from the resource manager. The internationalization resource file stores data in a key-value pair pattern.
[0246] Step S604: Electronic device 100 converts internationalized resource files and performs key-value pair separation.
[0247] The conversion method can be referred to the relevant description of step S405 above, and will not be repeated here.
[0248] Step S605: Conversion successful. The internationalization module of electronic device 100 saves the converted internationalization resource file to the file explorer.
[0249] Step S606: The resource manager of electronic device 100 transmits the resource storage path of the converted internationalized resource file to the packaging and compilation module through the internationalization module.
[0250] Step S607: Based on the resource storage path, the packaging and compilation module compiles the converted internationalization resource files, packages the compiled files into the runtime file or installation package of the first application, and completes the packaging and compilation of the first application.
[0251] In this way, the conversion of internationalization resource files is completed during the packaging and compilation stage. Since the converted internationalization resource files use a key-value pair for storage, the storage of duplicate keys is reduced, thereby reducing the size of the application installation package and improving the efficiency of installing the first application. During subsequent operation of electronic device 100 or other electronic devices, the first application can directly call the converted internationalization resource files. Furthermore, moving the resource lookup process to the compilation or packaging stage not only reduces the time spent on initial operation and switching internationalization resource files, but also reduces the memory pressure during internationalization resource file parsing, decreasing the probability of system crashes or application anomalies due to insufficient resource space.
[0252] In some implementations, the electronic device 100 converts the hierarchical structure of internationalized resource files. This can be done by preserving keywords to specify key / value mappings for resources at a particular level; or by using a specified API (Application Programming Interface) to specify key mappings for a particular level. Thus, by providing conversion for resource files at a specified level, it supports the retrieval of specified resource objects while maintaining key-value separation and storage.
[0253] As can be seen, the transformation of resource files at a specified level affects the caching of key values, but not the caching of value values. For example, consider the following resource file definition:
[0254]
[0255] The resource file consists of two levels. The first level includes the nodes "strings" and "style". The second level below the first level includes the nodes "name", "sex", "cache", "width", and "height". The nodes in the second level are child nodes of the nodes in the first level.
[0256] Optionally, the electronic device 100 can set the corresponding resource caching level through a specific API, such as SetCacheLevel. If the second level is selected for caching, the parent nodes of levels above the second level (e.g., the first level) will be cached in a flattened manner, while nodes at the second level and below will be cached hierarchically. If the first level is selected for caching, both nodes at the first and second levels will be cached. For example, taking the resource file mentioned above as an example, if the electronic device 100 sets the corresponding resource caching level to the first level using SetCacheLevel, the corresponding key.bin file may include:
[0257] Strings name sex cache style width height
[0258] If electronic device 100 sets the corresponding resource cache level to the second level via SetCacheLevel, then the corresponding key.bin file may include:
[0259] strings.name strings.sex strings.cache style.width style.height
[0260] Optionally, the electronic device 100 can cache values at the current level based on a specific attribute, such as `cache`. For example, taking the resource file mentioned above, if the `cache` value under the `string` node is `true`, and the `style` node does not have this attribute, then the `string` node will be cached using a flattened cache, while the `style` node will be cached using a hierarchical structure cache. The corresponding `key.bin` file can include:
[0261] strings.name strings.sex strings.cache stylewidth height
[0262] The corresponding resource conversion process is as follows: Figure 7 As shown:
[0263] Step S701: Electronic device 100 calls the internationalization conversion interface through the packaging and compilation module and sends a conversion request for internationalization resource files to the internationalization module. The conversion request includes the path of the internationalization resource files.
[0264] Step S702: Based on the conversion request, the internationalization module of the electronic device 100 reads the internationalization resource file from the resource manager. The internationalization resource file stores data in a key-value pair pattern.
[0265] Step S703: Electronic device 100 converts the internationalization resource file and separates key-value pairs. Only the keys at the specified level in the internationalization resource file are cached in the resource manager.
[0266] The internationalization module of electronic device 100 converts internationalization resource files. It separates multiple resource files within the internationalization resource files into key-value pairs, saves the keys from multiple resource files into a single file, and removes duplicate keys.
[0267] For key caching, the electronic device 100 caches the key of the node in the specified level according to the preset resource caching level API or preset attributes. If the node in the specified level also contains child nodes, the key of the corresponding child node is cached separately, and the corresponding mapping relationship between the child node and the parent node is established.
[0268] Electronic device 100 performs flattened caching of keys above a specified level. For cache nodes and child nodes of cache nodes, hierarchical caching is performed in different files, and a mapping relationship is established through the corresponding structure. For example, the offset positions of child node parent node and sibling node are recorded to save the structure of the corresponding child node.
[0269] In some embodiments, if there is no preset attribute hierarchy or no preset resource caching hierarchy, the last level is cached by default.
[0270] Based on this caching method, when indexing a key value, the internationalization module searches the mapping relationship at each level until the corresponding level is found. It then combines the corresponding child nodes into an object and returns it to the developer. If the key cannot be found even at the last level, a failure result is returned. For example, if the first search is for `string.name` and it is not found, the module checks if the mapping position corresponding to `string` exists and then compares the results to retrieve the corresponding child node.
[0271] Step S703 describes the process of caching the key at a specified level and generating the key.bin file; the description of caching the value can be found in the relevant description of step S405 above, and will not be repeated here.
[0272] Step S704: The resource manager of electronic device 100 transmits the resource storage path of the converted internationalized resource file to the packaging and compilation module through the internationalization module.
[0273] Step S705: The packaging and compilation module compiles the converted internationalization resource files and packages the compiled files into the runtime file or installation package of the first application.
[0274] This application embodiment supports multi-level resource file caching and allows caching of resource files at specified levels, enabling better customization to meet user needs. Thus, based on key-value split storage, it supports retrieval of resource files at specified levels. Furthermore, this application embodiment employs offline compilation of resource files, allowing for pre-estimation of the resource space occupied by internationalization resources. When resource space is insufficient, the corresponding resource file can be omitted, avoiding excessive memory pressure and the risk of system crashes. Simultaneously, by directly loading converted files into the second-level cache, runtime memory pressure can be reduced.
[0275] In some implementations, the electronic device 100 obtains the internationalization resource files of the first application from a third-party server of the first application. Based on this, the electronic device 100 can download the internationalization resource files of the application according to different regions, reducing the cost of file download or transmission. That is, when the first application wants to find the required internationalization resource files, it can obtain them from the third-party server of the first application. For example... Figure 8 As shown, Figure 8 The process of finding internationalized resource files in the first application of electronic device 100 is shown.
[0276] Step S801: The first application of the electronic device 100 sends an internationalization resource request to the internationalization module. The internationalization resource request includes the key resources of the display elements of the interface to be displayed of the first application.
[0277] After electronic device 100 downloads and installs the first application, it runs the first application and sends an internationalization resource request to the internationalization module.
[0278] In some embodiments, if the first application downloaded by the electronic device 100 is a first application for a specified region, then the installation package of the first application includes an internationalization resource file for that specified region. This internationalization resource file may be a key-value pair that has been converted during the installation process or during the packaging and compilation process.
[0279] Step S802: Based on the internationalization resource request, the internationalization module of the electronic device 100 detects that the required internationalization resource file does not exist in the resource manager.
[0280] Step S803: Electronic device 100 requests the required internationalization resource files from the third-party server of the first application based on the communication module.
[0281] Step S804: Electronic device 100 obtains the required internationalized resource files after conversion based on the communication module.
[0282] In some embodiments, the third-party server of the first application receives a request from the electronic device 100, performs key-value split storage on the internationalization resource files required by the electronic device 100, and then provides them to the electronic device 100.
[0283] In some embodiments, the third-party server of the first application receives a request from the electronic device 100 and provides the electronic device 100 with the internationalization resource files required by the electronic device 100. The electronic device 100 obtains the internationalization resource files and performs a key-value split storage conversion. The specific conversion method can be referred to the relevant description of step S405 above, and will not be repeated here.
[0284] Step S805: The internationalization module of electronic device 100 determines the display element value of the page to be displayed in the first application based on the internationalization resource request and the converted required internationalization resource file.
[0285] Step S806: The internationalization module of the electronic device 100 provides the first application with the value corresponding to the display element of the page to be displayed in the first application.
[0286] In some embodiments, after step S804 and before step S805, the internationalization module of the electronic device 100 can also perform version verification on the converted required internationalization resource file. For a detailed description of the version verification, please refer to the relevant descriptions of steps S503 to S506 above, which will not be repeated here.
[0287] In this embodiment, downloading internationalization resource files for the application based on different regions can reduce the consumption of file downloads or transfers. When the application is running on a resource-constrained device, the space occupied by the internationalization resource can be determined before loading, and only the necessary internationalization resource files can be downloaded, thereby resolving scenarios where excessive internationalization resource consumption leads to application or system malfunctions.
[0288] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.
[0289] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A resource retrieval method, characterized in that, The method includes: An electronic device acquires a key file, a first value file, and a second value file. The key file includes the keys of a first resource file and a second resource file. The first value file includes the values of the first resource file, and the second value file includes the values of the second resource file. The key file and the first value file have a first mapping relationship, and the key file and the second value file have a second mapping relationship. The first resource file and the second resource file store data in a key-value pair pattern. The first resource file provides a first operating environment, and the second resource file provides a second operating environment. The electronic device is running a first application, and the current operating environment of the first application is the first operating environment. The electronic device determines a first key of a display element on the first page of the first application, the first key being contained in the key file; The electronic device searches for the first value corresponding to the first key in the first value file based on the first operating environment. The electronic device displays the first page according to the first value of the display element of the first page; When the electronic device receives a resource switching request, the resource switching request is used to switch the first operating environment to the second operating environment; In response to the resource switching request, the electronic device searches for the second value corresponding to the first key in the second value file based on the second operating environment; The electronic device displays the first page based on the second value of the display element of the first page.
2. The method according to claim 1, characterized in that, Before the electronic device runs the first application, the method further includes: The electronic device installs the first application based on the installation package of the first application, and the installation package of the first application includes the first resource file and the second resource file; The electronic device converts the first resource file and the second resource file into the key file, the first value file, and the second value file.
3. The method according to claim 2, characterized in that, The electronic device, based on the first operating environment, searches for the first value corresponding to the first key in the first value file, including: The electronic device finds the location of the first key in the key file, and then obtains the index value of the value corresponding to the first key in the first value file based on the first mapping relationship; The electronic device finds the first value in the first value file based on the index value.
4. The method according to claim 1, characterized in that, Before the electronic device runs the first application, the method further includes: The electronic device uses a packaging and compilation tool to convert the first resource file and the second resource file into the key file, the first value file, and the second value file; The electronic device generates an installation package for the first application, which includes the key file, the first value file, and the second value file.
5. The method according to claim 1, characterized in that, Before the electronic device runs the first application, the method further includes: The electronic device obtains the installation package of the first application, which includes the key file, the first value file, and the second value file.
6. The method according to claim 1, characterized in that, The electronic device, based on the first operating environment, searches for the first value corresponding to the first key in the first value file, including: The electronic device obtains the first value file from the server of the first application based on the first operating environment; The electronic device searches for the first value corresponding to the first key in the first value file.
7. The method according to any one of claims 1-6, characterized in that, The data structure hierarchy of the first resource file is the first level, and the data structure hierarchy of the key file is the second level, wherein the value of the second level is less than the value of the first level.
8. The method according to any one of claims 1-6, characterized in that, The data structure of each key in the key file includes: the index of the key in the string, the length of the key, the position of the corresponding value in value.bin, and the index position of the next key node in the key file.
9. A resource conversion method, characterized in that, The method includes: The electronic device uses a packaging and compilation tool to convert a first resource file and a second resource file into a key file, a first value file, and a second value file. The first resource file and the second resource file store data in a key-value pair pattern. The first resource file provides a first runtime environment, and the second resource file provides a second runtime environment. The key file includes the keys of the first resource file and the second resource file. The first value file includes the values of the first resource file, and the second value file includes the values of the second resource file. The key file and the first value file have a first mapping relationship, and the key file and the second value file have a second mapping relationship. The electronic device generates an installation package for a first application, which includes the key file, the first value file, and the second value file.
10. The method according to claim 9, characterized in that, After the electronic device generates the installation package for the first application, it also includes: The electronic device installs the first application based on the installation package of the first application; The electronic device runs the first application, and the current operating environment of the first application is the first operating environment; The electronic device determines the display format of the display elements of the page to be displayed in the first application based on the key file and the first value file, and then displays the page to be displayed. When the electronic device receives a resource switching request, the resource switching request is used to switch the first operating environment to the second operating environment; In response to the resource switching request, the electronic device determines the display format of the display elements of the page to be displayed in the first application based on the key file and the second value file, and displays the page to be displayed.
11. The method according to claim 10, characterized in that, The electronic device determines the display format of the display elements of the page to be displayed in the first application based on the key file and the first value file, and displays the page to be displayed, including: The electronic device determines the first key of the display element of the page to be displayed in the first application; The electronic device finds the location of the first key in the key file, and then obtains the index value of the value corresponding to the first key in the first value file based on the first mapping relationship; The electronic device finds the first value in the first value file based on the index value; The electronic device displays the page to be displayed based on the first value.
12. The method according to any one of claims 9-11, characterized in that, The data structure hierarchy of the first resource file is the first level, and the data structure hierarchy of the key file is the second level, wherein the value of the second level is less than the value of the first level.
13. The method according to any one of claims 9-11, characterized in that, The data structure of each key in the key file includes: the index of the key in the string, the length of the key, the position of the corresponding value in value.bin, and the index position of the next key node in the key file.
14. An electronic device, characterized in that, include: One or more processors, one or more memories; the one or more memories are respectively coupled to the one or more processors; the one or more memories are used to store computer program code, the computer program code including computer instructions; when the computer instructions are executed on the processor, the electronic device causes the electronic device to perform the method as described in any one of claims 1-13.
15. A computer-readable medium, characterized in that, For storing one or more programs, wherein the one or more programs are configured to be executed by one or more processors, the one or more programs including instructions for performing the method as described in any one of claims 1-13.
Citation Information
Patent Citations
Processing method and device of page internalization, computer and storage medium
CN108228179A
Method and device for displaying text in page, storage medium and electronic equipment
CN112988300A
