CN-121979500-A - Method and device for generating application program data packet, electronic equipment and storage medium
Abstract
The invention provides a method, a device, electronic equipment and a storage medium for generating an application program data packet, wherein the method comprises the steps of obtaining a first code of a target application program and at least one target language, wherein the first code uses the first language, the first language is different from the target language, obtaining a character string resource to be translated in the first code, translating the character string resource to be translated into the target language to obtain a target language translation result of the character string resource to be translated, updating the character string resource to be translated in the first code into the target language translation result to obtain the target code containing the target language translation result, and generating a program data packet of the target language of the target application program based on the target code. The method improves the readability and development efficiency of codes, simultaneously, the program data packet only contains character string resources to be translated of one target language, reduces the downloading cost of users, reduces the resource loading and analysis expenditure when the application program runs, and optimizes the performance loss.
Inventors
- Zhou Shitie
- BAO GUANXIA
- SU CANRONG
- CHEN MIAORONG
- CHEN JINHAI
Assignees
- 杭州网易云音乐科技有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251204
Claims (10)
- 1. A method for generating an application data packet, the method comprising: acquiring a first code of a target application program and at least one target language, wherein the first code uses a first language, and the first language is different from the target language; Acquiring a character string resource to be translated in the first code, translating the character string resource to be translated into the target language, and obtaining a target language translation result of the character string resource to be translated; updating the character string resource to be translated in the first code into the target language translation result to obtain a target code containing the target language translation result; And generating a program data packet of a target language of the target application program based on the target code.
- 2. The method of claim 1, wherein the step of obtaining at least one target language comprises: and acquiring a target language list from the construction configuration file of the target application program, and acquiring at least one target language in the target language list.
- 3. The method according to claim 1, wherein a build plug-in is provided in a build profile of the target application; the step of obtaining the character string resource to be translated in the first code comprises the following steps: analyzing the first code based on the construction plug-in, and generating a grammar structure tree corresponding to the first code, wherein the grammar structure tree comprises a plurality of nodes, wherein the nodes have a hierarchical relationship, and the nodes have corresponding node types and node attributes; and acquiring the character string resource to be translated in the first code from the grammar structure tree.
- 4. A method according to claim 3, wherein the step of obtaining the string resource to be translated in the first code from the syntax structure tree comprises: Traversing nodes of each level of the grammar structure tree through the construction plug-in, and identifying nodes of character string literal quantity types; determining a first node from the nodes of the character string literal quantity type, wherein the node attribute of the first node does not contain a path attribute; and extracting first code data stored in the first node to serve as character string resources to be translated in the first code.
- 5. The method according to claim 1, wherein a build plug-in is provided in a build profile of the target application; The step of translating the character string resource to be translated into the target language to obtain a target language translation result of the character string resource to be translated comprises the following steps: A preset translation interface is called through the construction plug-in, and a translation request is sent to a translation platform, wherein the translation request comprises the character string resource to be translated and the language identifier of the target language; receiving a request result returned by the translation platform, wherein the request result comprises a mapping dictionary, and the mapping dictionary records the corresponding relation between the character string resource to be translated and the target language translation result; and determining a target language translation result of the character string resource to be translated based on the corresponding relation.
- 6. The method of claim 3, wherein the step of updating the string resource to be translated in the first code to the target language translation result to obtain the target code containing the target language translation result comprises: updating the character string resources to be translated in the grammar structure tree into the target language translation result to obtain an updated grammar structure tree; And generating target codes containing the target language translation result based on the updated grammar structure tree.
- 7. The method of claim 1, wherein after the step of generating the program data package for the target language of the target application program, the method comprises: and generating an acquisition path of the program data packet of the target language, wherein the acquisition path comprises a language identifier of the target language.
- 8. An apparatus for generating an application data packet, the apparatus comprising: The system comprises a first acquisition module, a first processing module and a second processing module, wherein the first acquisition module is used for acquiring a first code of a target application program and at least one target language, and the first code uses a first language; the first translation module is used for acquiring the character string resources to be translated in the first code, translating the character string resources to be translated into the target language, and obtaining a target language translation result of the character string resources to be translated; the first updating module is used for updating the character string resources to be translated in the first code into the target language translation result to obtain target code containing the target language translation result; And the first generation module is used for generating a program data packet of a target language of the target application program based on the target code.
- 9. An electronic device comprising a processor and a memory, the memory storing computer-executable instructions executable by the processor, the processor executing the computer-executable instructions to implement the method of generating application data packets of any of claims 1-7.
- 10. A storage medium storing computer executable instructions which, when invoked and executed by a processor, cause the processor to implement the method of generating application data packets of any one of claims 1-7.
Description
Method and device for generating application program data packet, electronic equipment and storage medium Technical Field The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for generating an application data packet, an electronic device, and a storage medium. Background With the global promotion of internet applications, numerous application programs need to provide services to multi-country users. In the related technology, a key value mapping scheme is generally adopted to generate a data packet of a multi-language application program, abstract key values are used for replacing specific documents in a development stage, the same keys correspond to document contents in different languages, key values of the document contents in all languages are classified and stored in corresponding language resource files, all the language resource files are packaged into a release data packet of the application program during construction, and the language resource files in corresponding languages are searched and presented through keys in a running stage according to the language environment of a user. However, the scheme has a plurality of problems that the code contains more key values without business semantics, the readability and the development efficiency are reduced, meanwhile, the data volume of the release data packet of the application program is larger because the release data packet contains the whole language resource, the downloading cost of a user is increased, the application program needs to load and analyze the complete language resource file when running, and the corresponding document content needs to be searched through keys when rendering the document each time, so that the performance loss is easy to cause. Disclosure of Invention Accordingly, the present invention is directed to a method, an apparatus, an electronic device, and a storage medium for generating an application data packet, so as to improve the readability and development efficiency of application codes and reduce the cost of downloading an application by a user and the performance loss of the application during operation. The embodiment of the invention provides a device for generating an application program data packet, which comprises a first code for acquiring a target application program and at least one target language, wherein the first code uses the first language, the first language is different from the target language, character string resources to be translated in the first code are acquired, the character string resources to be translated are translated into the target language to obtain a target language translation result of the character string resources to be translated, the character string resources to be translated in the first code are updated to the target language translation result to obtain the target code containing the target language translation result, and the program data packet of the target language of the target application program is generated based on the target code. In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, where the memory stores computer executable instructions executable by the processor, and the processor executes the computer executable instructions to implement the method for generating an application data packet. In a fourth aspect, an embodiment of the present invention provides a storage medium storing computer executable instructions that, when invoked and executed by a processor, cause the processor to implement a method for generating an application data packet as described above. The embodiment of the invention has the following beneficial effects: The invention provides a method, a device, electronic equipment and a storage medium for generating an application program data packet, wherein the method comprises the steps of obtaining a first code of a target application program and at least one target language, wherein the first code uses the first language, the first language is different from the target language, obtaining a character string resource to be translated in the first code, translating the character string resource to be translated into the target language to obtain a target language translation result of the character string resource to be translated, updating the character string resource to be translated in the first code into the target language translation result to obtain the target code containing the target language translation result, and generating a program data packet of the target language of the target application program based on the target code. In the method, in the development stage of a target application program, a developer directly writes a program code by using a first language, a language corresponding to a multi-language version to be generated is determined in advance, the language is used as a target