Multilingual file management method, device and medium

By obtaining configuration files to parse multi-language files and using standard key-value arrays to update data, the problem of multi-language file management being time-consuming, labor-intensive and error-prone is solved, achieving automated management and improved accuracy.

CN119940377BActive Publication Date: 2025-09-23BEST EPOCH TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411999169.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-09-23
Estimated Expiration
2044-12-31

AI Technical Summary

Technical Problem

In the existing technology, multilingual file management is time-consuming, labor-intensive, and error-prone, and lacks efficient and accurate automated management methods.

Method used

By obtaining the preset configuration file, reading and parsing the multilingual files, and using the standard key-value pair array to update the initial data, the target language entries can be automatically imported and deleted in batches. The multilingual files are then exported as target translation tables, using specific character escapes and regular expressions to ensure data accuracy.

Benefits of technology

It realizes efficient, accurate and automated management of multilingual files, and improves the accuracy and ease of operation of multilingual file management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119940377B_ABST
    Figure CN119940377B_ABST
Patent Text Reader

Abstract

The present invention provides a multilingual file management method, device, and medium, relating to the field of software development technology. The method comprises: obtaining a preset configuration file; translating target language terms from a translation table to be imported into a multilingual file based on the preset configuration file; batch-deleting several terms from the multilingual file; and exporting the multilingual file into a target translation table. This invention implements automated multilingual management, improving the efficiency and accuracy of multilingual file management.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a multi-language file management method, device and medium. Background Art

[0002] With the advancement of globalization, applications on different platforms need to support multiple languages ​​to meet the language needs of users in different countries and regions. Application internationalization is achieved through multilingual files in various languages ​​within project engineering, and the formats of multilingual files vary across different platforms. Multilingual files contain a large number of translations of terms in specific formats. Managing multilingual files involves importing translations of terms from translation tables into multilingual files, deleting certain terms from multilingual files, and exporting translations from multilingual files into translation tables. Efficient and accurate management of multilingual files is crucial. The traditional method of manually copying, pasting, and checking multilingual files is not only time-consuming and labor-intensive, but also extremely error-prone. Summary of the Invention

[0003] In a first aspect, the present invention provides a multilingual file management method, the method comprising: obtaining a preset configuration file; reading and parsing the multilingual file to obtain initial data; importing the target language entries in a translation table to be imported into the multilingual file, including: reading the translation table to be imported based on the preset configuration file to obtain a standard key-value pair array; updating the initial data using the standard key-value pair array to obtain target data; and writing the target data into the multilingual file;

[0004] The initial data includes: an initial dictionary, batch deleting a number of entries in the multilingual file, including: determining a key value array of the entries to be deleted according to the preset configuration file, traversing the key value array of the entries to be deleted, obtaining the key value of each entry to be deleted, and removing the data corresponding to the key value in the initial dictionary;

[0005] The initial data includes: an initial tree structure object; batch deleting a plurality of entries in a multilingual file, including: determining a key value array of the entries to be deleted according to the preset configuration file; traversing the key value array to be deleted to obtain a key value of each entry to be deleted; finding a node array to be deleted in the initial tree object according to the key value; and then deleting the nodes in the node array from the initial tree structure object;

[0006] Exporting the multilingual files into a target translation table includes: reading all the multilingual files and parsing them into their respective initial data according to the preset configuration file; merging and removing duplicate key values ​​of the initial data of all languages ​​and removing commented key values ​​to obtain the target key value array; then, extracting target translation values ​​corresponding to target key values ​​from the respective initial data according to the target key value array to obtain the respective target translation value arrays; and exporting the target key value array and all the target translation value arrays into a target translation table by column using an Excel processing tool according to the configuration file.

[0007] In one embodiment, the method of reading the translation table to be imported based on the preset configuration file to obtain a standard key-value pair array includes: determining the column where the term key value is located and the column where the translation value of the target language is located from the translation table to be imported according to the preset configuration file; using a table data processing tool to read the column where the term key value is located to obtain a term key value array; reading the column where the translation value of each language term is located to obtain an array of translation values ​​of each language term; matching the elements in the key value array with the elements in the translation value array according to the same index position to obtain the standard key-value pair array.

[0008] In one embodiment, before matching the elements in the key value array with the elements in the translation value array according to the same index position, the method further includes: performing escape processing on specific characters for each element in the key value array and each element in the translation value array.

[0009] In one embodiment, the initial data includes: an initial dictionary, and the reading and parsing of a multilingual file to obtain the initial data includes: traversing the multilingual file line by line, splicing the lines together to obtain a target string; setting an index value, whose initial value is 0; using a preset regular expression to cyclically match the target string, if a match is successful once, taking out the matched substring, and extracting key values ​​and translation value data or annotation data from the substring, and forming initial key-value pairs with the entry key value and translation value data, index value or preset annotation key value and annotation data, and index value. The preset regular expression includes: entry, single-line comment, and multi-line comment extraction regular expressions; each of the initial key-value pairs constitutes the initial dictionary.

[0010] In one embodiment, the initial data includes an initial dictionary, and the reading and parsing of the multilingual file to obtain the initial data includes: converting the multilingual file into a preset format file using a preset format conversion command in a preset operating system, and then parsing the preset format file to obtain the initial dictionary.

[0011] In one embodiment, the initial file includes: an initial tree structure object, and the reading and parsing of the multilingual file to obtain the initial data includes: using a preset format parser in a preset tool library to parse the multilingual file to obtain the initial tree structure object.

[0012] In one embodiment, the target data includes: a target dictionary, and the use of the standard key-value pair array to update the initial data to obtain the target data includes: the standard key-value pair array includes N standard key-value pairs, the initial dictionary includes M initial key-value pairs, and the i-th standard key-value pair is composed of the i-th standard key value and the i-th standard translation value; setting an initial index, whose value is M; according to the i-th standard key value, searching the initial dictionary for the corresponding initial translation value; if the corresponding initial translation value is empty, adding 1 to the index value, and adding the i-th standard key-value pair with the index value to the initial dictionary; if the corresponding initial translation value is not empty, replacing the corresponding initial translation value in the initial dictionary with the i-th standard translation value; the updated initial dictionary is determined as the target dictionary.

[0013] In one embodiment, the target data includes: a target tree structure object; and updating the initial data using the standard key-value pair includes: the standard key-value pair array includes N standard key-value pairs, the i-th standard key-value pair consists of the i-th standard key value and the i-th standard translation value; and determining a corresponding node array from the initial tree structure object according to the i-th standard key value, the corresponding node array including Q nodes;

[0014] If Q>1, delete the 1st to Q-1th nodes, and update the node content of the Qth node to the i-th standard translation value; if Q=1, update the node content of the Qth node to the i-th standard translation value; if Q=0, create a new node, set the node according to the i-th standard key-value pair, and insert the set node into the root node of the initial tree structure object; the updated initial tree structure object is determined as the target tree structure object.

[0015] In one embodiment, the step of writing the target data into the multilingual file, wherein the target data includes the target dictionary, includes: the target dictionary includes P target key-value pairs, and each key-value pair is sorted in ascending order according to the index value of the key-value pair, to determine an array of target key-value pairs to be written. The kth target key-value pair in the array of target key-value pairs to be written is composed of the kth target key value and the kth target translation value;

[0016] Traverse the target key-value pair array to be written, judge the kth key value according to preset rules, determine whether this key-value pair is a key-value pair of an entry or an annotation, if it is a key-value pair of an entry, splice the kth key value and the kth translation value into a character string to be written according to the rules of the entry, and write it into the multilingual file; if it is a key-value pair of an annotation, write the kth translation value into the multilingual file.

[0017] In one embodiment, writing the target data into the multi-language file, wherein the target data includes the target tree structure object, includes: using a tree structure object writing method in a preset tool library to write the target tree structure object into the multi-language file.

[0018] In a second aspect, the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program, and when the computer program runs on the processor, the multilingual file management method according to the first aspect is executed.

[0019] In a third aspect, the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the multilingual file management method described in the first aspect.

[0020] The multilingual file management method, device, and medium provided by the embodiments of the present invention accurately and efficiently implement the automatic import of target language terms in a translation table to be imported into a multilingual file, batch deletion of several terms in a multilingual file, and export of a multilingual file as a target translation table based on a preset configuration file, thereby realizing automated multilingual file management and greatly improving the accuracy of multilingual file management.

[0021] The multilingual file management method, device, and medium provided by the present invention accurately and efficiently implement multilingual automated management based on configuration files. This solution is not only simple to operate and highly applicable, but also greatly improves the accuracy and efficiency of multilingual file management. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solution of the present invention, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and should not be regarded as limiting the scope of protection of the present invention. In each of the drawings, similar components are numbered similarly.

[0023] Figure 1 A first flow chart of a multilingual file management method according to an embodiment of the present invention is shown;

[0024] Figure 2 A second flow chart of the multilingual file management method provided by an embodiment of the present invention is shown;

[0025] Figure 3 A third flow chart of the multilingual file management method provided by an embodiment of the present invention is shown;

[0026] Figure 4 A fourth flow chart of the multilingual file management method provided by an embodiment of the present invention is shown;

[0027] Figure 5 FIG4 shows a fifth flow chart of the multilingual file management method provided by an embodiment of the present invention;

[0028] Figure 6 A sixth flow chart of the multilingual file management method provided by an embodiment of the present invention is shown;

[0029] Figure 7 FIG2 shows a seventh flow chart of the multilingual file management method provided by an embodiment of the present invention;

[0030] Figure 8 FIG1 shows an eighth flow chart of the multilingual file management method provided by an embodiment of the present invention;

[0031] Figure 9 A schematic structural diagram of an electronic device provided by an embodiment of the present invention is shown.

[0032] Description of main component symbols:

[0033] 900 - electronic device; 901 - transceiver; 902 - processor; 903 - memory. DETAILED DESCRIPTION

[0034] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.

[0035] The components of the embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the figures is not intended to limit the scope of the claimed invention, but rather merely represents selected embodiments of the present invention. All other embodiments derived by those skilled in the art based on the embodiments of the present invention without inventive effort are intended to be within the scope of protection of the present invention.

[0036] Hereinafter, the terms "including", "having" and their cognates, which may be used in various embodiments of the present invention, are intended only to indicate specific features, numbers, steps, operations, elements, components or combinations of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or combinations of the foregoing items or the possibility of adding one or more features, numbers, steps, operations, elements, components or combinations of the foregoing items.

[0037] Furthermore, the terms “first,” “second,” “third,” etc., are merely used for distinguishing descriptions and are not to be understood as indicating or implying relative importance.

[0038] Unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by those skilled in the art to which the various embodiments of the present invention pertain. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meaning as in the context of the relevant technical field and will not be interpreted as having an idealized meaning or an overly formal meaning unless clearly defined in the various embodiments of the present invention.

[0039] Example 1

[0040] Because different platforms have different multilingual file formats, the parsing, updating, and writing methods of multilingual files are also different. Taking the multilingual management of iOS and Android platforms as an example, the embodiment of the present application provides a multilingual file management method, which includes:

[0041] Import the target language terms in the translation table to be imported into a multilingual file, batch delete several terms in a multilingual file, and export the translations of multilingual file terms into a target translation table.

[0042] For details, see Figure 1 Importing the target language in the translation table to be imported into the multilingual file includes: steps S110 to S150.

[0043] Step S110: Obtain a preset configuration file.

[0044] It can be understood that the preset configuration file is a JSON file that can be parsed into a dictionary for configuration input for multilingual file management. The preset configuration file includes the type of multilingual platform, the folder path where the multilingual files are located, the path to the translation table to be imported, the mapping relationship between the translation language titles in the translation table to be imported and the corresponding multilingual file names, the row where the translation language titles are located in the translation table to be imported, the column where the term key values ​​are located in the translation table to be imported, the row range where the translation terms are located in the translation table to be imported, the array of term key values ​​to be deleted, the preset string prefix for the key values ​​annotated in the multilingual file, the path to the target translation table where the multilingual file is exported, etc.

[0045] Step S120: read and parse the multi-language file to obtain initial data.

[0046] In one embodiment, for the iOS platform, the initial data includes: an initial dictionary, see Figure 2 , step S120 includes: steps S121 to S124.

[0047] Step S121 , traverse the multi-language file line by line, and concatenate the lines together to obtain a target character string.

[0048] In this embodiment, the multi-language file is traversed line by line, and each line of character strings obtained by the traversal is connected together using an empty character string as a connector to form a target character string to be matched.

[0049] Step S122: Set an index value, whose initial value is 0. It can be understood that the index value is used to record the order of successfully matched substrings later.

[0050] Step S123, using a preset regular expression to cyclically match the target string, if a match is successful once, take out the substring obtained by the match and delete it from the target string, increase the index value by 1, and extract the key value and translation value data or annotation data from the substring, and form an initial key-value pair with the entry key value and translation value data, index value or preset annotation key value and annotation data, and index value. The preset regular expression includes: entry, single-line comment, and multi-line comment extraction regular expressions.

[0051] In this embodiment, a regular expression is extracted and matched against a target string in a loop through the terms, single-line comments, and multi-line comments. If a match is successful, the substring that successfully matched is extracted. For the extracted terms, the key value and translation value obtained by grouping and capturing the regular expression must not contain unescaped double quotes to successfully extract the terms. The successfully matched substring is then deleted from the target string, and the relative order of the successfully matched substrings is recorded by incrementing the index. The key value, translation value, and index value are then combined to form an initial key-value pair.

[0052] Among them, using the term extraction naming group regular expression to match the target string includes: if the term extraction expression is matched successfully, the key value and translation value of the term are obtained according to the naming group, and then the regular expression is used to detect whether the key value and translation value contain unescaped double quotes. If neither the key value nor the translation value contains unescaped double quotes, first increase the index value by 1, and delete the matched term substring from the target string, and then form a key-value pair with the key value, translation value, and index value in the form of ({key value:{"key":key value,"value":translation value,"index":index value}}) and add it to the initial dictionary. If one of the key value and translation value contains unescaped double quotes, it will prompt that the multilingual file format is wrong.

[0053] In this embodiment, the named grouping regular expression used to extract the terms is expressed as follows using Python:

[0054] r'^\s*"(?P <key>.*?[^\\](\\\\)*|(\\\\)*)"\s*=\s*"(?P <value>.*?[^\\](\\\\)*|(\\\\)*)"\s*;\s*'. This regular expression can not only match the target string to obtain the term substring, but also further capture the key value and term translation value of the term based on the named capture group. The key group captures the key value of the term, and the value group captures the translation value of the term. The named group regular expression for term extraction is described as follows:

[0055] ^\s*": matches the beginning of the target string, indicating that the starting position of the target string consists of several spaces and double quotes.

[0056] (?P <key>.*? [^\\](\\\\)*|(\\\\)*): The named capture group key is used to capture the key value of the entry, indicating that the key value consists of several arbitrary characters in non-greedy mode plus an even number (including 0) of escape characters. It should be noted that the end of the key value must consist of an even number (including 0) of escape characters, otherwise the quotation marks after the key value will be escaped.

[0057] "\s*=\s*": Double quotation marks after the term key value, followed by several spaces, an equal sign, several spaces, and then double quotation marks before the term translation value.

[0058] (?P <value>.*? [^\\](\\\\)*|(\\\\)*): The named capture group value is used to capture the translation value of the term, indicating that the translation value consists of a number of arbitrary characters plus an even number (including 0) of escape characters in non-greedy mode. It should be noted that the end of the translation value must consist of an even number (including 0) of escape characters, otherwise the quotation marks after the translation value will be escaped.

[0059] "\s*;\s*:The double quotation marks after the term translation value are followed by several spaces, a semicolon, and several spaces.

[0060] In iOS multi-language files, the key and translation values ​​of a term cannot contain unescaped double quotes. The above term extraction regular expression does not detect whether the key and translation values ​​of the term include unescaped double quotes. The following regular expression is used to further determine whether the key and translation values ​​contain unescaped double quotes. The regular expression that detects the presence of unescaped double quotes is expressed in Python as follows: r'(^(\\\\)*")|([^\\](\\\\)*")'. If the match is successful, it means that the string to be matched contains unescaped double quotes. This regular expression is explained as follows:

[0061] (^(\\\\)*"), which means starting from the starting position, it consists of an even number (including 0) of escape characters and a double quote;

[0062] |([^\\](\\\\)*"), or a non-escape character, plus an even number (including 0) of escape characters, plus a double quote;

[0063] Using a single-line comment to extract a regular expression that matches a target string involves: if a match is successful, first incrementing the index by 1, deleting the matched comment substring from the target string, concatenating the pre-set comment key prefix in the configuration file with the index value as the comment key, using the matched comment substring as the translation value, and then adding the comment key, translation value, and index value to the initial dictionary in the form of ({key:{"key":key value,"value":comment value,"index":index value}}}}). The single-line comment extraction regular expression is expressed in Python as follows: r'^\s* / / [^\n]*?\n'. ^\s* / / matches the beginning of the string, indicating that the starting position of the string consists of a number of spaces followed by / / ; [^\n]*?\n' matches the entire comment, indicating that it consists of a number of non-newline characters followed by a newline character in non-greedy mode.

[0064] Using a regular expression to extract multi-line comments to match a target string involves: if a match is successful, first incrementing the index by 1, deleting the matched comment substring from the target string, concatenating the pre-set comment key prefix in the configuration file with the index value as the comment key, using the matched comment substring as the translation value, and then adding the comment key, translation value, and index value to the initial dictionary in the form of ({key:{"key":key value,"value":comment value,"index":index value}}}}). The regular expression for extracting multi-line comments in Python is as follows: r'^\s* / \*.*? \* / \s*'. ^\s* / \* matches the beginning of a string, indicating that the starting position of the string consists of a number of spaces followed by / *; .*? matches the contents of a multi-line comment, indicating any number of characters in non-greedy mode; and \* / \s* matches the end of a multi-line comment, indicating that it consists of * / followed by a number of spaces.

[0065] Step S124: the initial key-value pairs constitute the initial dictionary.

[0066] It is understood that if all the regular expressions for term extraction, single-line comments, and multi-line comments fail to match, the program will further determine whether the target string to be matched is an empty string or consists only of spaces. If so, the multilingual file is parsed successfully. If not, a prompt will be displayed indicating a multilingual file format error (for example, the first 20 characters of the target string to be matched are printed, and any characters less than 20 are printed in full). If the multilingual file is parsed successfully and no format errors occur, the initial data obtained is the initial dictionary. Otherwise, the specific details of the error are displayed.

[0067] In one embodiment, for the iOS platform, the initial data includes an initial dictionary, and the reading and parsing of the multilingual file to obtain the initial data includes: using a preset format conversion command in a preset operating system to convert the multilingual file into a preset format file, and then parsing the preset format file to obtain the initial dictionary.

[0068] In this embodiment, you can also use the macOS system's built-in shell command plutil to parse the multilingual file into a JSON file. The command is: 'plutil-convert json-sro json file multilingual file', and then parse this JSON file into an initial dictionary. It should be noted that this method does not support the recognition of comments in multilingual files, that is, the converted JSON file does not contain the content of single-line comments and multi-line comments in multilingual files.

[0069] In one embodiment, for the Android platform, the initial file includes: an initial tree structure object, and the reading and parsing of the multilingual file to obtain the initial data includes: using a preset format parser in a preset tool library to parse the multilingual file to obtain the initial tree structure object.

[0070] It should be noted that Android platform multi-language files are in XML format. lxml is a Python library for processing XML and HTML. etree is the core module of lxml. It provides a rich set of APIs for processing XML and HTML documents, and you can also choose whether to remove comments during parsing. Using etree, the XML parser parses Android multi-language files into an initial tree structure object without removing comments. The specific method is as follows:

[0071] parser=etree.XMLParser(remove_comments=false)

[0072] tree = etree.parse(multi-language file path, parser)

[0073] root = tree.getroot()

[0074] The root object above is the root node of the initial tree structure object obtained by parsing the Android multi-language file. If the root object is empty, it means that an error occurred in parsing the multi-language file.

[0075] Step S130 : reading the translation table to be imported based on the preset configuration file to obtain a standard key-value pair array.

[0076] In one embodiment, see Figure 3 , step S130 includes: steps S131 to S134.

[0077] Step S131 : determining the column where the entry key value is located and the column where the translation value of the target language is located from the translation table to be imported according to the preset configuration file.

[0078] In this embodiment, the path of the translation table to be imported, the column where the term key value is located in the translation table to be imported, the row range where the term translation is located in the translation table to be imported, the row where the language title is located, the mapping between the language title and the corresponding multilingual file name, the folder path where the multilingual file is located, etc. can be determined according to the preset configuration file. These can be configured to ensure that the term key value and the translation value of each language term in the translation table to be imported are correctly read.

[0079] Step S132: Use a table data processing tool to read the column where the entry key value is located to obtain an entry key value array.

[0080] In this embodiment, the table processing tool includes the pandas library, which is an open source Python data analysis library suitable for processing table data. It can read the key values ​​of entries by column according to the column where the key value of the entry is located and the row range where the entry translation is located to obtain an array of the key value of the entry.

[0081] Step S133, reading the column where the translation value of each language term is located, and obtaining an array of translation values ​​of each language term.

[0082] As you can understand, the preset configuration file contains a map that describes the rows in the translation table to be imported, and maps each language title to its corresponding multilingual file name. The row containing the language title is read, and the cell content C in each column of that row is retrieved. If the key value in the Map contains content C, it indicates that the column is a target language translation. The mapping value corresponding to content C in the Map is the multilingual file name corresponding to that target language. Based on the target language translation column and the range of rows containing the term translations retrieved from the configuration file, the translation values ​​for the term are read column by column to obtain an array of target language translation values.

[0083] Step S134 : Match the elements in the key-value array with the elements in the translation value array according to the same index position to obtain the standard key-value pair array.

[0084] In this embodiment, the key value array is traversed according to the index, the key value in the key value array and the translation value in the translation value array at the same index position are taken out, the key value that does not meet the requirements (for example, the key value does not meet the agreed requirements, the key value is empty, etc.) is ignored, and specific characters in the key value and the translation value are escaped, and the escaped key value and translation value are combined into a key-value pair and added to the standard key-value pair array.

[0085] In one embodiment, before matching the elements in the key value array with the elements in the translation value array according to the same index position, the method further includes: performing escape processing on specific characters for each element in the key value array and each element in the translation value array.

[0086] In a specific implementation, for the iOS platform, unescaped double quotes in the elements of the key and translation arrays are escaped (because the iOS platform does not allow unescaped double quotes in key and translation values ​​in multi-language files, which is a multi-language file format error). Regular expressions are used to perform substring replacement on both key and translation values. The Python language is expressed as follows: re.sub(r'(?P <value>(\\)*)"',dealwithQuotes,element),r'(?P <value>(\\)*)"' is the substring regular expression to be replaced, which means matching all substrings consisting of several escape characters and double quotes. value is the group that captures the escape characters. dealwithQuotes is the captured substring replacement function. The input parameter of this function is the matching result, and the return value of this function is the string that needs to be replaced by the matched substring. In the replacement function, the number of escape characters in the value capture group is judged. If the number of escape characters is odd, the captured substring is returned directly. If the number of escape characters is even, a string consisting of the escape characters and the captured substring is returned.

[0087] In a specific implementation, for the Android platform, unescaped single quotes in the elements of the key and translation arrays are escaped (because the Android platform does not allow unescaped single quotes in key and translation values ​​in multilingual files, which is a multilingual file format error). Regular expressions are used to perform substring replacement on both key and translation values. The Python language is expressed as follows: re.sub(r"(?P <value>(\\)*)'",dealwithSingleQuotes,element),r"(?P <value>(\\)*)'" is the substring regular expression to be replaced, which means matching all substrings consisting of several escape characters plus single quotes. value is the group that captures the escape characters. dealwithSingleQuotes is the captured substring replacement function. The input parameter of this function is the matching result, and the return value of this function is the string that the matched substring needs to be replaced with. In the replacement function, the number of escape characters in the value capture group is judged. If the number of escape characters is odd, the captured substring is returned directly. If the number of escape characters is even, a string consisting of the escape characters and the captured substring is returned.

[0088] Step S140: Use the standard key-value pair array to update the initial data to obtain target data.

[0089] It can be understood that according to the above steps, the standard key-value pair array of each target language and the initial data obtained by parsing the multilingual file corresponding to the target language can be determined, and the initial data obtained by parsing the multilingual file corresponding to the target language can be updated using the standard key-value pair array of the target language to obtain the updated target data after translation in each target language.

[0090] In one embodiment, the target data includes: a target dictionary, the standard key-value pair array includes N standard key-value pairs, the initial dictionary includes M initial key-value pairs, the i-th standard key-value pair consists of the i-th standard key value and the i-th standard translation value; an initial index is set, and its value is M. Figure 4 , step S140 includes: steps S141 to S144.

[0091] In this embodiment, for the iOS platform, the initial data is an initial dictionary. The standard key-value pair array is traversed to obtain each standard key-value pair. It is determined whether the initial translation value corresponding to the key value in the standard key-value pair in the initial data is empty. If so, the index value is increased by 1, and then the key-value pair consisting of the standard key value, standard translation value and index value is added to the initial data. If not, the standard translation value is used to update the initial translation value.

[0092] Step S141 : searching the initial dictionary for a corresponding initial translation value according to the i-th standard key value.

[0093] In this embodiment, the standard key-value pair array includes N standard key-value pairs, each consisting of a key value and a corresponding translation value. If the standard key value at position i is not empty, and the standard translation value corresponding to the standard key value at position i is not empty, then the corresponding initial translation value is obtained from the initial dictionary based on the standard key value at position i, where 1≤i≤N.

[0094] Step S142: If the corresponding initial translation value is empty, the index value is increased by 1, and the i-th standard key-value pair is added to the initial dictionary with the index value.

[0095] In this embodiment, it is determined whether the corresponding initial translation value is empty. If so, the index value is increased by 1, and the standard key value and the translation value and index value corresponding to the standard key value are combined into a key-value pair {key value: {"key": key value, "value": translation value, "index": index value}}) and added to the initial dictionary.

[0096] Step S143: If the corresponding initial translation value is not empty, the corresponding initial translation value in the initial dictionary is replaced with the i-th standard translation value.

[0097] It can be understood that when the initial translation value is inconsistent with the standard translation value corresponding to the standard key value, the initial translation value is updated with the standard translation value.

[0098] Step S144: The updated initial dictionary is determined as the target dictionary.

[0099] In one embodiment, the target data includes: a target tree structure object, the standard key-value pair array includes N standard key-value pairs, and the i-th standard key-value pair consists of the i-th standard key value and the i-th standard translation value. Figure 5 , step S140 includes: steps S145 to S147.

[0100] Step S145 : determining a corresponding node array from the initial tree structure object according to the i-th standard key value, wherein the corresponding node array includes Q nodes.

[0101] In this embodiment, if the target key value at position i is not null and the target translation value corresponding to the target key value at position i is not null, the corresponding initial translation value is obtained from the initial tree structure object based on the target key value at position i, where 1≤i≤N. The findAll method of the root object is used, and based on the conditions that the tag name is "string" and the attribute name is equal to the target key value at position i, all nodes that meet the conditions are found and formed into a node array, as shown below: XMLItems = root.findall('string[@name="{}"]'.format(excelKey)), where XMLItems is a node array, root is the root node of the initial tree structure object, and excelKey is the target key value at position i.

[0102] Step S146, if Q>1, delete the 1st to Q-1th nodes, and update the node content of the Qth node to the i-th standard translation value; if Q=1, update the node content of the Qth node to the i-th standard translation value; if Q=0, create a new node, set the node according to the i-th standard key-value pair, and insert the set node into the root node of the initial tree structure object.

[0103] In this embodiment, a determination is made as to whether the length of the node array is greater than or equal to 1. If so, the last node in the node array is retained, and all nodes except the last node in the node array are deleted from the initial tree structure object. The content of the last node is updated using the translation value corresponding to the target key value. If not, a node is created, its label is set to "string", its attribute name is set to the target key value, its content is set to the target translation value corresponding to the target key value, and the node is terminated with a line break. This node is then inserted as a child node from the end of the root node of the initial tree structure object.

[0104] Step S147: The updated initial tree structure object is determined as the target tree structure object.

[0105] Step S150: writing the target data into the multi-language file.

[0106] In one embodiment, for the iOS platform, the target data is written into the multilingual file, and the target data includes the target dictionary, including: the target dictionary includes P target key-value pairs, and each key-value pair is sorted in ascending order according to the index value it carries, and the target key-value pair array to be written is determined. The k-th target key-value pair in the target key-value pair array to be written is composed of the k-th target key value and the k-th target translation value; the target key-value pair array to be written is traversed, and the k-th key value is judged according to the preset rules, and it is determined that this key-value pair is a key-value pair of an entry or an annotation. If it is a key-value pair of an entry, the k-th key value and the k-th translation value are spliced ​​into a string to be written according to the rules of the entry, and the string is written into the multilingual file. If it is a key-value pair of an annotation, the k-th translation value is written into the multilingual file.

[0107] In this embodiment, the key-value pairs in the target dictionary are sorted in ascending order according to the index values ​​in their values ​​to obtain a key-value pair array, and the key-value pair array is traversed to obtain the corresponding element. If the key value of the element starts with a preset string, the corresponding translation value is directly written into the multilingual file. Otherwise, the key value and translation value are concatenated according to the format rules of the entry in the project to form a string (the concatenated string format in iOS is: "entry key value" = "entry translation value";\n) and written into the multilingual file.

[0108] In one embodiment, for the Android platform, writing the target data into the multilingual file, where the target data includes the target tree structure object, includes: using a tree structure object writing method in a preset tool library to write the target tree structure object into the multilingual file.

[0109] As you can understand, the core module etree of the Python lxml library provides a write method that can write the target tree structure object into a multilingual file, as shown below: etree.ElementTree(root).write(filePath, pretty_print = True, xml_declaration = True, encoding = 'utf-8'), where root is the root node of the target tree structure object in the target language, and filePath is the path to the multilingual file in the target language.

[0110] The multi-language file management method further includes: deleting a number of entries in the multi-language file in batches. Figure 6 For the iOS platform, the batch deletion of several entries in the multi-language file includes: steps S610 to S630.

[0111] Step S610: Obtain a preset configuration file.

[0112] It should be noted that step S610 is consistent with step S110 and will not be described again here to avoid repetition.

[0113] Step S620: read and parse the multi-language file to obtain initial data.

[0114] It should be noted that step S620 is consistent with step S120 and will not be described again here to avoid repetition.

[0115] Step S630: determining the key value array of the to-be-deleted terms according to the preset configuration file, traversing the key value array of the to-be-deleted terms, obtaining the key value of each to-be-deleted term, and removing the data corresponding to the key value in the initial dictionary.

[0116] For iOS: traverse the key value array of the term to be deleted in the configuration file to obtain the key value of the term to be deleted. If the translation value corresponding to the key value of the term to be deleted in the initial dictionary is not empty, delete the data corresponding to this key value from the initial dictionary. The initial dictionary after deleting the data of the term to be deleted is the target data.

[0117] See Figure 7 For the Android platform, the batch deletion of several entries in the multi-language file includes: steps S710 to S740.

[0118] Step S710: Obtaining a preset configuration file. It should be noted that step S710 is consistent with step S110 and will not be described again to avoid repetition.

[0119] Step S720: read and parse the multi-language file to obtain initial data. It should be noted that step S720 is consistent with step S120 and will not be described again to avoid repetition.

[0120] Step S730: determining a key value array of entries to be deleted according to the preset configuration file, traversing the key value array to be deleted, and obtaining the key value of each entry to be deleted.

[0121] For the Android platform: traverse the key value array of the entry to be deleted in the configuration file to obtain the key value of the entry to be deleted.

[0122] Step S740: Find the node array to be deleted in the initial tree object according to the key value, and then delete the nodes in the node array from the initial tree structure object.

[0123] In this embodiment, for each key value of a term to be deleted, the lxml core module etree is used to query the initial tree structure object for all nodes that meet the conditions of the tag name "string" and the attribute name equal to the key value to be deleted, obtain the node array to be deleted, and then delete the nodes in the node array from the initial tree structure object. The initial tree structure object obtained after deleting the node array to be deleted is the target data. The multilingual file management method also includes: exporting the translation of the multilingual file terms into a target translation table. For details, please refer to Figure 8 The process of exporting the translation of multilingual document entries into a target translation table includes steps S810 to S850.

[0124] Step S810: Obtaining a preset configuration file. It should be noted that step S810 is consistent with step S110 and will not be described again to avoid repetition.

[0125] Step S820: read and parse the multi-language file to obtain initial data. It should be noted that step S820 is consistent with step S120 and will not be described again to avoid repetition.

[0126] Step S830: Read all multi-language files according to the preset configuration file and parse them into their respective initial data.

[0127] In step S840, the key values ​​of the initial data of all languages ​​are merged and deduplicated, and the commented key values ​​are removed to obtain the target key value array. Then, according to the target key value array, the target translation values ​​corresponding to the target key values ​​are extracted from the respective initial data to obtain the respective target translation value arrays.

[0128] For the iOS platform: Extract the key values ​​of the initial dictionary obtained by parsing each multilingual file to obtain multiple target key value arrays; merge the multiple target key value arrays to remove duplicates, and filter out key values ​​that begin with the key value prefix pre-annotated in the configuration file to obtain a target key value array. The target key value array includes the key values ​​of all entries in the multilingual files; For each multilingual file, obtain the translation value corresponding to the key value in the target key value array from the initial dictionary obtained by parsing it, and the multiple translation values ​​constitute the target translation value array;

[0129] For the Android platform: First, convert the initial tree structure object obtained by parsing each multilingual file into a dictionary: Traverse the child nodes of the root node of the initial tree structure object. For each child node, if the child node's label is "string", the child node has a name attribute, and the number of child nodes of the child node is 0, then use the name attribute as the key value and the child node's content as the translation value to form a key-value pair. All key-value pairs form a dictionary. Then, according to the method for extracting the target key value array and target translation value array from the iOS initial dictionary, obtain the target key value array and target translation value array from these dictionaries.

[0130] Step S850: Export the target key value array and all the target translation value arrays column by column into a target translation table using an Excel processing tool according to the configuration file.

[0131] Writing the target key value array and the target translation value array into an Excel translation table. The method includes, for example, using a spreadsheet processing tool including the pandas library, writing the target key value array to the table key value column and writing each language title and its corresponding target translation value array to the language translation value column according to a configuration file.

[0132] The multilingual file management method provided by the embodiment of the present invention accurately and efficiently implements the automatic import of target language term translations in a translation table to be imported into a multilingual file, batch deletion of several terms in a multilingual file, and export of multilingual file term translations into a target translation table based on a preset configuration file, thereby realizing automated multilingual file management and greatly improving the efficiency and accuracy of multilingual file management.

[0133] Example 2

[0134] In addition, an embodiment of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is run on the processor, the multilingual file management method provided in Example 1 is executed. Figure 9 The electronic device 900 includes: a transceiver 901, a bus interface and a processor 902. The processor 902 is used to read a preset configuration file and perform automatic management of multi-language files based on the configuration file.

[0135] In the embodiment of the present invention, the electronic device 900 further includes a memory 903. Figure 9 In the embodiment, the bus architecture may include any number of interconnected buses and bridges, specifically various circuits of one or more processors represented by the processor 902 and the memory represented by the memory 903, which are linked together. The bus architecture can also link together various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are all well known in the art and, therefore, will not be described further herein. The bus interface provides an interface. The transceiver 901 can be a plurality of components, i.e., including a transmitter and a receiver, providing a unit for communicating with various other devices on a transmission medium. The processor 902 is responsible for managing the bus architecture and general processing, and the memory 903 can store data used by the processor 902 when performing operations. The electronic device 900 provided in an embodiment of the present invention can execute the multi-language file management method provided in the above-mentioned method embodiment 1, and to avoid repetition, it will not be described here.

[0136] Example 3

[0137] In addition, an embodiment of the present invention provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the multilingual file management method provided in Example 1. In this embodiment, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk. The computer-readable storage medium provided in this embodiment can implement the multilingual file management method provided in Example 1. To avoid repetition, the details are not further described here.

[0138] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or flowchart, and the combination of boxes in the structure diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or can be implemented using a combination of dedicated hardware and computer instructions.

[0139] In addition, the functional modules or units in each embodiment of the present invention can be integrated together to form an independent part, or each module can exist separately, or two or more modules can be integrated to form an independent part. If the function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0140] The above description is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be covered by the scope of protection of the present invention.< / value> < / value> < / value> < / value> < / value> < / key> < / value> < / key>

Claims

1. A multi-language file management method, characterized in that: The method comprises: Get the preset configuration file; Read and parse the multilingual file to obtain initial data; Importing the target language entry translation in the translation table to be imported into the multilingual file includes: reading the translation table to be imported based on the preset configuration file to obtain a standard key-value pair array; updating the initial data using the standard key-value pair array to obtain target data; and writing the target data into the multilingual file; The initial data includes: an initial dictionary, batch deleting a number of entries in the multilingual file, including: determining a key value array of the entries to be deleted according to the preset configuration file, traversing the key value array of the entries to be deleted, obtaining the key value of each entry to be deleted, and removing the data corresponding to the key value in the initial dictionary; The initial data includes: an initial tree structure object; batch deleting a plurality of entries in a multilingual file, including: determining a key value array of the entries to be deleted according to the preset configuration file; traversing the key value array to be deleted to obtain a key value of each entry to be deleted; finding a node array to be deleted in the initial tree object according to the key value; and then deleting the nodes in the node array from the initial tree structure object; Exporting the multilingual files into a target translation table includes: reading all the multilingual files and parsing them into their respective initial data according to the preset configuration file; merging and removing duplicate key values ​​of the initial data of all languages ​​and removing commented key values ​​to obtain a target key value array; then, extracting target translation values ​​corresponding to target key values ​​from the respective initial data according to the target key value array to obtain their respective target translation value arrays; and exporting the target key value array and all the target translation value arrays into a target translation table by column using an Excel processing tool according to the configuration file.

2. The multilingual file management method according to claim 1, characterized in that: The method of reading the translation table to be imported based on the preset configuration file to obtain a standard key-value pair array includes: Determining the column where the entry key value is located and the column where the translation value in the target language is located from the translation table to be imported according to the preset configuration file; Use a table data processing tool to read the column where the entry key value is located to obtain an entry key value array; Read the column where the translation value of each language entry is located to obtain the translation value array of each language entry; The elements in the key-value array are matched with the elements in the translation value array according to the same index position to obtain the standard key-value pair array.

3. The multilingual file management method according to claim 2, characterized in that: Before matching the elements in the key value array with the elements in the translation value array according to the same index position, the method further includes: performing escape processing on specific characters on each element in the key value array and each element in the translation value array.

4. The multilingual file management method according to claim 3, characterized in that: The initial data includes: an initial dictionary, and the multilingual file is read and parsed to obtain the initial data, including: Traversing the multilingual file line by line, and concatenating the lines together to obtain a target string; Set an index value, whose initial value is 0; A preset regular expression is used to cyclically match the target string. If a match succeeds, a substring obtained by the match is taken out, and key values ​​and translation value data or annotation data are extracted from the substring. The initial key-value pairs are composed of the term key value and translation value data, index value or the preset annotation key value and annotation data, and index value. The preset regular expression includes: term, single-line comment, and multi-line comment extraction regular expressions; The initial key-value pairs constitute the initial dictionary.

5. The multilingual file management method according to claim 3, characterized in that: The initial data includes an initial dictionary. The multilingual file is read and parsed to obtain the initial data, including: After converting the multilingual file into a file in a preset format using a preset format conversion command in a preset operating system, the preset format file is parsed to obtain the initial dictionary.

6. The multilingual file management method according to claim 3, characterized in that: The initial file includes: an initial tree structure object, which reads and parses the multi-language file to obtain initial data, including: The multilingual file is parsed using a preset format parser in a preset tool library to obtain the initial tree structure object.

7. The multilingual file management method according to claim 4 or 5, characterized in that: The target data includes: a target dictionary, and the method of updating the initial data with the standard key-value pair array to obtain the target data includes: The standard key-value pair array includes N standard key-value pairs, the initial dictionary includes M initial key-value pairs, the i-th standard key-value pair is composed of the i-th standard key value and the i-th standard translation value; an initial index is set, and its value is M; According to the i-th standard key value, searching the initial translation value corresponding to the initial dictionary; If the corresponding initial translation value is empty, the index value is increased by 1, and the i-th standard key-value pair is added to the initial dictionary with the index value; If the corresponding initial translation value is not empty, replacing the corresponding initial translation value in the initial dictionary with the i-th standard translation value; The updated initial dictionary is determined as the target dictionary.

8. The multi-language file management method according to claim 6, characterized in that: The target data includes: a target tree structure object, and the updating of the initial data using the standard key-value pair includes: The standard key-value pair array includes N standard key-value pairs, and the i-th standard key-value pair consists of the i-th standard key value and the i-th standard translation value; Determine a corresponding node array from the initial tree structure object according to the i-th standard key value, where the corresponding node array includes Q nodes; If Q>1, delete the 1st to Q-1th nodes, and update the node content of the Qth node to the i-th standard translation value; If Q=1, the node content of the Qth node is updated to the i-th standard translation value; If Q=0, a new node is created, and the node is set according to the i-th standard key-value pair, and the set node is inserted into the root node of the initial tree structure object; The updated initial tree structure object is determined as the target tree structure object.

9. The multi-language file management method according to claim 7, characterized in that: The step of writing the target data into the multi-language file, wherein the target data includes the target dictionary, includes: The target dictionary includes P target key-value pairs, and each key-value pair is sorted in ascending order according to its index value to determine a target key-value pair array to be written; the kth target key-value pair in the target key-value pair array to be written is composed of the kth target key value and the kth target translation value; Traversing the target key-value pair array to be written, judging the kth key value according to preset rules, determining whether this key-value pair is a key-value pair of an entry or an annotation, and if it is a key-value pair of an entry, concatenating the kth key value and the kth translation value into a string to be written according to the rules of the entry, and writing the string into the multilingual file; If it is a commented key-value pair, the kth translation value is written to the multilingual file.

10. The multi-language file management method according to claim 8, characterized in that: The step of writing the target data into the multi-language file, wherein the target data includes the target tree structure object, includes: The target tree structure object is written into the multi-language file using a tree structure object writing method in a preset tool library.

11. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is run on the processor, the method for managing multilingual files according to any one of claims 1 to 10 is executed.

12. 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 multilingual file management method according to any one of claims 1 to 10 is implemented.

Citation Information

Patent Citations

  • Language conversion method and device applied to code character string

    CN113139390A

  • Multi-language configuration method and device, computer equipment and storage medium

    CN115827138A