A method, apparatus, device and medium for removing multi-language resources

By parsing and merging the language resource files of internationalized Android apps, redundant language items are identified and removed, solving the problem of multilingual resource redundancy, optimizing resource file size, and ensuring the normal operation of app functions.

CN114661678BActive Publication Date: 2025-10-17BIGO TECH PTE LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210206442.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-02
Publication Date
2025-10-17
Estimated Expiration
2042-03-02

AI Technical Summary

Technical Problem

In existing technologies, internationalized Android apps suffer from the problem of redundant multilingual resources, resulting in increasingly larger app sizes. Furthermore, the mapping between English and other languages ​​is not always consistent during feature development, exacerbating resource redundancy.

Method used

By parsing language resource files, candidate language items with identical language content are identified and retained. The target language item is selected and the unselected candidate language items are removed. DOM parsing and string matching techniques are used to merge language resource files to reduce redundancy.

Benefits of technology

This effectively reduced the redundancy of multilingual resources, optimized resource file sizes, and ensured the normal operation of the App.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114661678B_ABST
    Figure CN114661678B_ABST
Patent Text Reader

Abstract

The application discloses a method, device, equipment and medium for removing a multi-language resource. In the embodiment of the application, a device analyzes and acquires language content contained in each language item of each language resource file, and then selects each candidate language item with the same language content in each language resource file. Each candidate language item with the same language content is a redundant item of the multi-language resource. A target language item is selected from each candidate language item and reserved, and the unselected candidate language item is removed, thereby solving the redundancy problem of the multi-language resource.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, and in particular to a method and device for removing multi-language resources, equipment and medium. BACKGROUND

[0002] Currently, internationalized Android App will be pre-installed in the package body with multiple language resources, so that users living in different regions and using different languages can use the functions provided by the App without obstacles. With the continuous iteration and addition of product functions, the multi-language resources in the package body will be more and more, and the package body will also be larger and larger. The more languages pre-installed in the App, the more obvious this effect will be. At the same time, during the development of new functions of the App, the product side will first provide the default English language, which will be added to the resource file by the development side for translation into other languages. In this process, there is a non-one-to-one mapping relationship from English to other languages. For example, "Accept" may need to be translated into "accept" in different functional scenarios, or it may be translated into "confirm" to be more consistent with the current context. In different resource files, the real content value of each language corresponding to different language attribute keys may be exactly the same, which causes redundancy of multi-language resources. At the same time, in the current mode of parallel development of multiple functions of the client, the redundancy of multi-language resources will be more serious. SUMMARY

[0003] The embodiments of the present application provide a method, device, equipment and medium for removing multi-language resources to solve the problem of redundancy of multi-language resources in the prior art.

[0004] The embodiments of the present application provide a method for removing multi-language resources, which comprises:

[0005] For each language resource file, parse and obtain the language content contained in each language item of the language resource file;

[0006] Select each candidate language item in the language resource file whose language content is exactly the same;

[0007] Select a target language item from the candidate language items and keep it, and remove the candidate language items that are not selected.

[0008] On the other hand, the embodiments of the present application provide a device for removing multi-language resources, which comprises:

[0009] The obtaining module is configured to parse and obtain the language content contained in each language item of each language resource file;

[0010] The selecting module is configured to select, from the language resource files, candidate language items whose language contents are identical;

[0011] The removing module is configured to select target language items from the candidate language items and keep the target language items, and remove the candidate language items that are not selected.

[0012] In another aspect, an embodiment of the present application provides a device for removing multi-language resources, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are in communication with each other through the communication bus;

[0013] The memory is configured to store a computer program;

[0014] The processor is configured to execute the program stored in the memory, and implement the method steps of any one of the above aspects.

[0015] In another aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method steps of any one of the above aspects.

[0016] An embodiment of the present application provides a method, device, equipment and medium for removing multi-language resources, and the method comprises the following steps: for each language resource file, language contents contained in each language item of the language resource file are parsed and acquired; from the language resource files, candidate language items whose language contents are identical are selected; target language items are selected from the candidate language items and kept, and the candidate language items that are not selected are removed.

[0017] In the embodiment of the present application, language contents contained in each language item of each language resource file are parsed and acquired, and then candidate language items whose language contents are identical are selected from the language resource files. The candidate language items whose language contents are identical are redundant items of the multi-language resources, target language items are selected from the candidate language items and kept, and the candidate language items that are not selected are removed. Thus, the problem of redundancy of the multi-language resources is solved. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.

[0019] Figure 1 A process diagram for removing multi-language resources is provided for the embodiments of the present application;

[0020] Figure 2 A merging diagram of various language resource files provided for the present application is shown in FIG. 1;

[0021] Figure 3 A detailed flowchart of removing the multi-language resource provided for the present application is shown in FIG. 2;

[0022] Figure 4 A retaining language item diagram provided for the present application is shown in FIG. 3;

[0023] Figure 5 A removing string diagram provided for the present application is shown in FIG. 4;

[0024] Figure 6 A replacing updated string diagram provided for the present application is shown in FIG. 5;

[0025] Figure 7 An apparatus structure diagram of removing the multi-language resource provided for the present application is shown in FIG. 6;

[0026] Figure 8 An apparatus structure diagram of removing the multi-language resource provided for the present application is shown in FIG. 6; DETAILED DESCRIPTION

[0027] The present application will be further described below in conjunction with the accompanying drawings. It is obvious that the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.

[0028] Figure 1 A process diagram of removing the multi-language resource provided for the embodiments of the present application is shown in FIG. 7, which includes the following steps:

[0029] S101: For each language resource file, parse and acquire the language content contained in each language item of the language resource file.

[0030] S102: Select each candidate language item with the same language content in the various language resource files.

[0031] S103: Select a target language item from the various candidate language items and retain, and remove the unselected candidate language items.

[0032] The method of removing the multi-language resource provided by the embodiments of the present application is applied to a device for removing the multi-language resource, which can be a PC, a tablet computer, a smart phone, or the like.

[0033] The device first finds the path of each language resource file, then acquires each language resource file according to the path of each language resource file, and further parses and acquires the language content contained in each language item of each language resource file.

[0034] Each language resource file includes a plurality of language items, each language item includes a language attribute and language content. The language content is the specific language content involved in the function of the APP, and the language attribute is a summary of the meaning expression of the language content. The language attribute is unique, and the language content corresponding to the same language attribute in different language resource files is the language expression of different languages.

[0035] For each language resource file, after obtaining the language content contained in each language item of the language resource file, each candidate language item with the same language content in the language resource file is selected.

[0036] Specifically, for the same language attribute, the language content corresponding to the language attribute in each language resource file is determined. Then it is judged whether there are two or more language attributes, and each language content corresponding to the two or more language attributes corresponds to the same, if so, the language item to which the two or more language attributes belong is the candidate language item with the same language content.

[0037] For the convenience of description, the language content and the language attribute are all letters for example. For example, the English language content corresponding to the language attribute A is m1, the Chinese language content is n1, and the Russian language content is p1. The English language content corresponding to the language attribute B is m2, the Chinese language content is n2, and the Russian language content is p2. If m1 and m2 are the same, n1 and n2 are the same, and p1 and p2 are the same, then the language item to which the language attribute A and the language attribute B belong is the two candidate language items with the same language content.

[0038] After selecting each candidate language item with the same language content in each language resource file, a target language item is selected from each candidate language item and retained, and the candidate language item not selected is removed. Because the determined candidate language item is the redundant item in the multi-language resource, one or several target language items are selected from each candidate language item and retained, and then the other candidate language items are removed. Thus, the redundancy of the language resource is reduced. Preferably, one target language item can be selected from each candidate language item and retained.

[0039] In the embodiment of the present application, the device obtains the language content contained in each language item of each language resource file, and then selects each candidate language item with the same language content in each language resource file. Each candidate language item with the same language content is a redundant item in the multi-language resource, a target language item is selected from each candidate language item and retained, and the candidate language item not selected is removed. Thus, the problem of redundancy of multi-language resource is solved.

[0040] The language resource files directly obtained are generally language resource files in XML format. To facilitate the removal of multilingual resources, the application describes parsing and obtaining the language content contained in each language item of each language resource file, including:

[0041] DOM parsing is performed on each of the language resource files, and each language item of each language resource file after DOM parsing is converted into a data form of language attribute and corresponding language content.

[0042] For each language resource file, the language content contained in each language item of the language resource file is parsed and obtained. Specifically, the multilingual resource *.xml file is subjected to DOM parsing, and each multilingual item in each language resource file after DOM parsing is represented as a key:value data format. The key represents the language attribute in the multilingual item. The multilingual resource is referenced by this value in the source code and resource files, and this value is unique. The value is the language content, which represents the value in the multilingual item. It is the actual content of the multilingual item and may be repeated. The data format of key:value is to convert each language item of each language resource file after DOM parsing into a data format of language attributes and corresponding language content. Then, for each language resource file, the step of obtaining the language content contained in each language item of the language resource file is performed.

[0043] In order to further solve the problem of multilingual resource redundancy, the process of selecting a target language from the candidate language items in this application includes:

[0044] Obtaining language attributes corresponding to the language content contained in each candidate language item;

[0045] The candidate language item to which the language attribute containing the shortest character string belongs is taken as the target language item.

[0046] In this application, after selecting candidate language items with exactly the same language content from various language resource files, they are sorted according to the length of the language attribute strings, and the candidate language item with the language attribute containing the shortest string is selected as the target language item. That is, the target language item with the language attribute containing the shortest string is retained, and other candidate language items with language attributes containing relatively long strings are removed, thereby further solving the problem of multilingual resource redundancy.

[0047] In this application, in order to facilitate the selection of candidate language items with identical language content, the selection of candidate language items with identical language content in the language resource files includes:

[0048] Merge the various language resource files after DOM parsing based on language attributes;

[0049] Based on the merged language resource file, candidate language items with completely identical language contents are obtained; wherein the merged language resource file includes language attributes and language contents corresponding to the respective languages.

[0050] Figure 2 This is a diagram showing how to merge the various language resource files after DOM parsing based on language attributes. Figure 2 The first column is the language attribute, the second to fourth columns are the language content columns, where the second to third columns are language contents in three different languages. The first and second columns are a language resource file, the first and third columns are a language resource file, and the first and fourth columns are a language resource file. After merging the three language resource files based on the language attribute, we get Figure 2 The result shown is more convenient for obtaining candidate language items with exactly the same language content based on the merged language resource file. The merged language resource file contains each language attribute and the language content corresponding to each language.

[0051] After selecting and retaining the target language from the candidate language items and removing the unselected candidate language items, in order to ensure normal operation of the APP function, the method further includes:

[0052] Determine reference strings of source files and language resource files corresponding to the unselected candidate language items; and replace and update the reference strings according to the target language item.

[0053] After selecting and retaining the target language from each candidate language, and removing the unselected candidate language, the language attributes of the unselected candidate language do not exist in the language resource file. This will cause the specific content to be unable to be found when referencing multilingual resources through this value in the source code and resource files, resulting in functional errors. To solve the above problem, the reference strings of the source files and language resource files corresponding to the unselected candidate language are first determined; then the reference strings are replaced and updated according to the target language. The reference strings of the source files and language resource files corresponding to the unselected candidate language can be determined by string matching.

[0054] Specifically, determining reference strings of source files and language resource files corresponding to the unselected candidate language items; and replacing and updating the reference strings according to the target language item includes:

[0055] determining a reference superset item string and a reference non-superset item string of the source file and the language resource file corresponding to the unselected candidate language item;

[0056] updating the reference superset item string and the reference non-superset item string according to the target language item, and restoring the updated reference superset item string according to the reference superset item string.

[0057] The reference string of the source file and the language resource file corresponding to the unselected candidate language item includes a reference superset item string and a reference non-superset item string. In the reference superset item string, the language attribute string in the unselected candidate language item is only a substring of the reference superset item string. The reference non-superset item string is the string of the language attribute itself in the unselected candidate language item.

[0058] When the reference string is updated according to the target language item, the reference superset item string is saved first, then the reference superset item string and the reference non-superset item string are updated according to the target language item, and finally the updated reference superset item string is restored according to the saved reference superset item string.

[0059] The reference superset item string is determined according to the pre-stored string reference rule. For example, the language attribute string in the unselected candidate language item is abc, the reference string abc of the source file and the language resource file corresponding to the unselected candidate language item is determined through string matching, but the determined abc may be a substring in the reference superset item string. If all the determined strings abc are updated, the reference superset item string will be incorrect. In order to avoid the above problem, it is necessary to accurately determine which is the substring in the reference superset item string. At this time, the reference superset item string of the source file and the language resource file corresponding to the unselected candidate language item is determined according to the pre-stored string reference rule. For example, the pre-stored string reference rule records that the reference superset item strings containing the string abc are abcd and abce. Then, according to abcd and abce, the string matching is performed to determine the reference superset item strings abcd and abce of the source file and the language resource file. For example, the language attribute string in the target language item is mn, and the strings abc of the source file and the language resource file corresponding to the unselected candidate language item are all updated to mn. abcd becomes mnd, and abce becomes mne. Then, mnd is updated to abcd, and mne is updated to abce.

[0060] The process of removing the multi-language resource is described in detail below. Figure 3To remove the detailed flowchart of multilingual resources, including the following steps:

[0061] S201: Find the path of the multilingual resource file to be compared. For live products, if the English, Chinese and Russian value values of two multilinguals are found to be the same, it is recognized that the multilingual item is repeated. In this application, this multilingual item can be flexibly and dynamically configured. It can be matched and searched according to the following regular rules:

[0062] DEFAULT_STRING_FILE_PATTERN = r'.* / values / string.*\.xml$' / / English;

[0063] CHINESE_STRING_FILE_PATTERN = r'.* / values-zh-rCN / string.*\.xml$' / / Simplified Chinese;

[0064] RUSSIA_STRING_FILE_PATTERN = r'.* / values-ru / string.*\.xml$' / / Russian.

[0065] S202: The searched multilingual resource *.xml file is parsed by DOM, and each multilingual is expressed as key:value data form. Key represents the language attribute in the multilingual item, and the value is unique in the source code and resource file. Value is the language content, which represents the value in the multilingual item, and may be repeated.

[0066] S203: The parsed data in key:value data is further converted into a two-dimensional matrix DataFrame form, which is convenient for subsequent efficient vectorization data processing. Each kind of multilingual in the first step is represented by a DataFrame, and the row represents a multilingual item and the list represents key and value.

[0067] S204: For each DataFrame, the value column is used as a standard to filter out the multilingual items with repeated values, and the result is represented in DataFrame form.

[0068] S205: The merged DataFrame of the filtered repeated multilingual items is merged according to the key column, and the result is represented in DataFrame form.

[0069] S206: For the merged DataFrame, organize each multi-language value into a list, and filter out the multi-language items with duplicate values based on this criterion. The result is represented in the form of a DataFrame. At this point, the data obtained is the completely duplicated multi-language items. For these duplicated multi-language items, only one item needs to be retained. For other duplicated items, they can be deleted at the definition and replaced at the reference.

[0070] S207: For the obtained DataFrame, arrange the values of each multi-language and the length of the key. The result is represented in the form of a DataFrame. We can simply consider that if a string is shorter in length, it will express a more general meaning. This can be used as a criterion for retaining and removing duplicated items in the subsequent steps.

[0071] S208: The first item of each duplicated item in the DataFrame is the retained item of each duplicated item, and the other items are the items to be deleted and replaced.

[0072] S209: Delete the obtained item to be deleted at its definition, and replace it with the retained item at its source file and resource file reference.

[0073] In this application, since there is a non-one-to-one mapping relationship between English and other languages by default, it is not advisable to simply compare whether the value of the English string is the same. Other multi-languages besides English need to be introduced for reference and comparison. Simplified Chinese and a language used by a Top user can be selected. Only when the selected reference languages are consistent, these multi-language items are considered to be duplicated. The selected reference languages can be freely configured. Taking Bigo Live as an example, English, simplified Chinese, and Russian are selected as reference languages.

[0074] In this application, the xml file defining the string resource is parsed by DOM. For each string resource, the corresponding Key and Value are obtained. The parsed string resource in a single language is formed into a two-dimensional matrix with key and value as columns and single string items as rows. By using the powerful data processing and analysis capabilities of Python Pandas, vectorized operations can be easily performed to quickly filter out the keys with the same value in three languages.

[0075] For the mutually repeated string resources, the removal strategy can be intuitively considered that the more the number of words of a phrase, the more detailed and specific the meaning expressed, and the fewer the number of words, the more abstract the meaning expressed, and the more scenarios can be generalized. Therefore, the mutual items can be sorted according to the length of their keys, and the multilingual with the shortest key length is retained, and the other repeated items are deleted. As shown in Figure 4 , the key OK in the mutually repeated string resources expresses the most general semantics, so the OK item is retained, and the other items are removed.

[0076] When replacing the string resources to be removed, the situation shown in Figure 5 may occur, in which R.string.community_datetime_one_day is the item to be replaced, and when searching for the target, the previous R.string.community_datetime_one_day_ago item will be searched first because it is a subset of the previous item, and partial replacement will be performed, resulting in compilation failure.

[0077] The solution is as shown in Figure 6 , first determine whether there is a superset item of the item to be removed in the line to be processed, if there is, record the redundant suffix part of the item except the item to be removed. Then replace all the removed content contained in the entire line content. Finally, restore the superset item that is mistakenly replaced.

[0078] Figure 7 The device structure diagram for removing multilingual resources provided by the present application includes:

[0079] The acquisition module 71 is configured to parse and acquire language content contained in each language item of each language resource file.

[0080] The selection module 72 is configured to select each candidate language item with the same language content in the language resource files.

[0081] The removal module 73 is configured to select and retain a target language item from the candidate language items, and remove the candidate language items that are not selected.

[0082] The removal module 73 is specifically configured to acquire language attributes corresponding to the language content contained in each candidate language item; and select the candidate language item to which the language attribute with the shortest contained string belongs as the target language item.

[0083] The acquisition module 71 is further configured to perform DOM parsing on the language resource files, and convert each language item in the language resource files after DOM parsing into data forms of language attributes and corresponding language contents.

[0084] The selection module 72 is specifically configured to merge the language resource files after DOM parsing based on language attributes; obtain candidate language items with identical language content based on the merged language resource files; wherein the merged language resource files contain the language attributes and the language content of the corresponding languages.

[0085] The device further comprises:

[0086] The replacement and update module 74 is configured to determine reference strings of the source files and language resource files corresponding to the unselected candidate language items, and replace and update the reference strings according to the target language item.

[0087] The replacement and update module 74 is specifically configured to determine the referenced superset item strings and the referenced non-superset item strings of the source files and language resource files corresponding to the unselected candidate language items; replace and update the referenced superset item strings and the referenced non-superset item strings according to the target language item; and restore the referenced superset item strings after replacement and update according to the referenced superset item strings.

[0088] The replacement and update module 74 is specifically configured to determine, based on pre-stored string reference rules, reference superset item strings of the source files and language resource files corresponding to the unselected candidate language items.

[0089] The present application also provides a device for removing multilingual resources, such as Figure 8 As shown, it includes: a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802, and the memory 803 communicate with each other through the communication bus 804;

[0090] The memory 803 stores a computer program. When the program is executed by the processor 801, the processor 801 performs the following steps:

[0091] For each language resource file, parse and obtain the language content contained in each language item in the language resource file; select candidate language items with exactly the same language content in the language resource files; select and retain the target language item from the candidate language items, and remove the unselected candidate language items.

[0092] The device for removing multi-language resources provided in the embodiments of the present application can be used to execute the method for removing multi-language resources, and has corresponding functions and advantages.

[0093] The embodiments of the present application further provide a computer storage readable storage medium, which stores a computer program executable by the device for removing multi-language resources, and when the program runs on the device for removing multi-language resources, the device for removing multi-language resources is caused to execute the steps of:

[0094] For each language resource file, language content contained in each language item of the language resource file is parsed and acquired; each candidate language item with the same language content in the each language resource file is selected; a target language item is selected from the each candidate language item and reserved, and the unselected candidate language item is removed.

[0095] The computer storage readable storage medium provided in the embodiments of the present application further stores a computer program executable by the device for removing multi-language resources, and when the program runs on the device for removing multi-language resources, the device for removing multi-language resources can be used to execute the interface calling time sequence detection method provided in any of the above embodiments, and has corresponding functions and advantages.

Claims

1. A method for removing multilingual resources, characterized in that: The method comprises: For each language resource file, parse and obtain the language content contained in each language item of the language resource file; Selecting candidate language items with identical language content in the language resource files; Selecting and retaining a target language item from the candidate language items, and removing unselected candidate language items; The method further comprises: Determining the referenced superset item character strings and referenced non-superset item character strings of the source files and language resource files corresponding to the unselected candidate language items; The reference superset item character string and the reference non-superset item character string are replaced and updated according to the target language item, and the reference superset item character string after the replacement and update is restored according to the reference superset item character string.

2. The method according to claim 1, wherein The selecting a target language item from the candidate language items includes: Obtaining language attributes corresponding to the language content contained in each candidate language item; The candidate language item to which the language attribute containing the shortest character string belongs is taken as the target language item.

3. The method according to claim 2, wherein The step of parsing and obtaining the language content contained in each language item of each language resource file includes: DOM parsing is performed on each of the language resource files, and each language item of each language resource file after DOM parsing is converted into a data form of language attribute and corresponding language content.

4. The method according to claim 3, wherein The candidate language items with the same language content in the selected language resource files include: Merge the various language resource files after DOM parsing based on language attributes; Based on the merged language resource file, candidate language items with completely identical language contents are obtained; wherein the merged language resource file includes language attributes and language contents corresponding to the respective languages.

5. The method according to claim 1, wherein Determining the reference superset item character strings of the source files and language resource files corresponding to the unselected candidate language items includes: According to the pre-stored string reference rule, the reference superset item strings of the source files and language resource files corresponding to the unselected candidate language items are determined.

6. A device for removing multilingual resources, characterized in that: The device comprises: An acquisition module, configured to parse and acquire the language content contained in each language item of each language resource file; A selection module, configured to select candidate language items having the same language content from the language resource files; a removal module, configured to select and retain a target language item from the candidate language items, and remove unselected candidate language items; The device further comprises: The replacement and update module is configured to determine reference superset item strings and reference non-superset item strings of the source files and language resource files corresponding to the unselected candidate language items; replace and update the reference superset item strings and the reference non-superset item strings according to the target language item; and restore the reference superset item strings after replacement and update according to the reference superset item strings.

7. A device for removing multilingual resources, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method steps described in any one of claims 1 to 5 when executing a program stored in a memory.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Multi-language supporting webpage processing method, webpage loading method and systems

    CN102693322A