CN-121166229-B - Language resource allocation and loading method, device, equipment and storage medium
Abstract
The application discloses a method, a device, equipment and a storage medium for configuring and loading language resources, which relate to the technical field of language loading, wherein the method for configuring and loading the language resources comprises the steps of obtaining a language configuration file, and generating a key name format mapping relation between an interface component library and a time processing library according to the language configuration file; receiving a language switching instruction, extracting a corresponding language code according to the language switching instruction, determining a target language resource file according to the mapping relation between the language code and the key name format, and loading the target language resource file. The application can improve the loading efficiency of language resources.
Inventors
- HUANG LIRONG
Assignees
- 深圳鼎信通达股份有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20251106
Claims (8)
- 1. A language resource allocation and loading method is characterized in that the method comprises the following steps: Acquiring a language configuration file, and generating a key name format mapping relation between an interface component library and a time processing library according to the language configuration file; Receiving a language switching instruction, and extracting a corresponding language code according to the language switching instruction; determining a target language resource file according to the mapping relation between the language code and the key name format; Loading the target language resource file; The step of generating the key name format mapping relation between the interface component library and the time processing library according to the language configuration file comprises the following steps: Analyzing the language configuration file to obtain a language list; traversing language codes of the language list; respectively converting the language codes into an interface component library key name format and a time processing library key name format according to a preset conversion rule; obtaining a key name format mapping relation according to the language code, the interface component library key name format and the time processing library key name format; Wherein, the step of loading the target language resource file comprises the following steps: Acquiring a first configuration resource corresponding to the interface component library and a second configuration resource corresponding to the time processing library according to the key name format mapping relation and the target language resource file; updating display text of the interface component library using the first configuration resource; Updating a date and time format of the time processing library using the second configuration resource; and updating the translation text in the target language resource file to a basic internationalization library.
- 2. The method of claim 1, wherein the step of converting the language code into an interface component library key name format and a time processing library key name format according to a preset conversion rule, respectively, comprises: Determining an interface component library key name format and a time processing library key name format according to a preset conversion rule; and converting the language codes into the interface component library key name format and the time processing library key name format respectively.
- 3. The method of claim 1, wherein the step of determining a target language resource file from the language code and key name format mapping relationship comprises: Obtaining a target language code according to the mapping relation between the language code and the key name format; constructing a complete path of the target language resource file according to the target language code and a preset file path rule; and downloading the target language resource file corresponding to the language code according to the complete path.
- 4. The method of claim 1, wherein after the step of loading the target language resource file, further comprising: monitoring whether the target language resource file is successfully loaded; if the loading is unsuccessful, acquiring a default language code and loading a default language resource file corresponding to the default language code.
- 5. The method of claim 1, wherein prior to the step of receiving a language switch instruction, further comprising: Determining a preloaded language code according to the system language environment or user history selection; loading corresponding language resource files in advance according to the pre-loaded language codes; And caching the language resource file into a local storage.
- 6. A language resource allocation and loading device, said device comprising: The processing module is used for acquiring a language configuration file, and generating a key name format mapping relation between an interface component library and a time processing library according to the language configuration file; The receiving module is used for receiving the language switching instruction and extracting a corresponding language code according to the language switching instruction; The determining module is used for determining a target language resource file according to the mapping relation between the language codes and the key name format; The loading module is used for loading the target language resource file; The generating the key name format mapping relation between the interface component library and the time processing library according to the language configuration file comprises the following steps: Analyzing the language configuration file to obtain a language list; traversing language codes of the language list; respectively converting the language codes into an interface component library key name format and a time processing library key name format according to a preset conversion rule; obtaining a key name format mapping relation according to the language code, the interface component library key name format and the time processing library key name format; wherein the loading the target language resource file comprises: Acquiring a first configuration resource corresponding to the interface component library and a second configuration resource corresponding to the time processing library according to the key name format mapping relation and the target language resource file; updating display text of the interface component library using the first configuration resource; Updating a date and time format of the time processing library using the second configuration resource; and updating the translation text in the target language resource file to a basic internationalization library.
- 7. A language resource allocation and loading device, characterized in that it comprises a memory, a processor and a computer program stored on said memory and executable on said processor, said computer program being configured to implement the steps of the language resource allocation and loading method according to any one of claims 1 to 5.
- 8. A storage medium, characterized in that the storage medium is a computer-readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, implements the language resource allocation and loading method according to any one of claims 1 to 5.
Description
Language resource allocation and loading method, device, equipment and storage medium Technical Field The present application relates to the field of language loading technologies, and in particular, to a method, an apparatus, a device, and a storage medium for configuring and loading a language resource. Background In the current Web application development based on a front-end framework such as Vue, realizing multilingual internationalization is a key for supporting globalization service. Currently, static integrated language resource files are generally relied on when an application is built, and are respectively configured through a basic internationalization library, a user interface component library and a time processing library. However, this approach has the significant disadvantage that the language resources are cured at compile time, resulting in the need to recompile and deploy the entire application when language support is added or modified in the production environment, resulting in inefficient loading of the language resources. Therefore, how to improve the loading efficiency of language resources is still a problem to be solved. The foregoing is provided merely for the purpose of facilitating understanding of the technical solutions of the present application and is not intended to represent an admission that the foregoing is prior art. Disclosure of Invention The application mainly aims to provide a method, a device, equipment and a storage medium for configuring and loading language resources, which aim to solve the technical problem of how to improve the loading efficiency of the language resources. In order to achieve the above object, the present application provides a method for configuring and loading language resources, the method comprising: Acquiring a language configuration file, and generating a key name format mapping relation between an interface component library and a time processing library according to the language configuration file; Receiving a language switching instruction, and extracting a corresponding language code according to the language switching instruction; determining a target language resource file according to the mapping relation between the language code and the key name format; And loading the target language resource file. In one embodiment, the step of generating the key name format mapping relationship between the interface component library and the time processing library according to the language configuration file includes: Analyzing the language configuration file to obtain a language list; traversing language codes of the language list; respectively converting the language codes into an interface component library key name format and a time processing library key name format according to a preset conversion rule; And obtaining a key name format mapping relation according to the language code, the interface component library key name format and the time processing library key name format. In an embodiment, the step of converting the language code into an interface component library key name format and a time processing library key name format according to a preset conversion rule includes: Determining an interface component library key name format and a time processing library key name format according to a preset conversion rule; and converting the language codes into the interface component library key name format and the time processing library key name format respectively. In one embodiment, the step of determining the target language resource file according to the mapping relationship between the language code and the key name format includes: Obtaining a target language code according to the mapping relation between the language code and the key name format; constructing a complete path of the target language resource file according to the target language code and a preset file path rule; and downloading the target language resource file corresponding to the language code according to the complete path. In one embodiment, the step of loading the target language resource file includes: Acquiring a first configuration resource corresponding to the interface component library and a second configuration resource corresponding to the time processing library according to the key name format mapping relation and the target language resource file; updating display text of the interface component library using the first configuration resource; Updating a date and time format of the time processing library using the second configuration resource; and updating the translation text in the target language resource file to a basic internationalization library. In one embodiment, after the step of loading the target language resource file, the method further includes: monitoring whether the target language resource file is successfully loaded; if the loading is unsuccessful, acquiring a default language code and loading a default language resource file co