Multi-language file management method and device and medium
By obtaining preset configuration files, reading multilingual files and parsing them, the automated management of multilingual files is solved, and the problem of multilingual file management in the existing technology is time-consuming, labor-intensive and error-prone, and the accuracy and efficiency of management are improved.
Patent Information
- Application Number
- CN202411999169.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2044-12-31
AI Technical Summary
In the prior art, there are methods of manual copying, pasting and verification of multilingual file management, which is time-consuming and labor-intensive and prone to errors, making it difficult to achieve efficient and accurate multilingual file management.
By obtaining preset configuration files, reading multilingual files and parsing them, we can automatically import the target language entries to be imported into the translation table into the multilingual file, batch delete several entries in the multilingual file, and exporting the multilingual file into the target translation table.
It realizes the automated management of multilingual files, greatly improving the accuracy and efficiency of multilingual file management, making it easy to operate and strong applicability.
Smart Images

Figure CN119940377A_ABST
Abstract
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 development of globalization, applications on different platforms need to support multiple languages to meet the language needs of users in different countries and regions. The internationalization of applications is achieved through multilingual files in various languages in the project, and the formats of multilingual files on different platforms are also inconsistent. Multilingual files include a large number of entry translations in specific formats. The management of multilingual files is to import the entry translations in the translation table into the multilingual file, delete some entries in the multilingual file, export the translations in the multilingual file into the translation table, etc. How to manage multilingual files efficiently and accurately is particularly important. The traditional way is to modify multilingual files by manual copying, pasting, and checking. This method is not only very time-consuming and labor-intensive, but also very prone to errors. Summary of the invention
[0003] In a first aspect, the present invention provides a multi-language file management method, the method comprising: obtaining a preset configuration file; reading and parsing the multi-language file to obtain initial data; importing the target language entry in the translation table to be imported into the multi-language file, including: reading the translation table to be imported based on the preset configuration file to obtain a standard key-value pair array; using the standard key-value pair array to update the initial data to obtain target data; writing the target data into the multi-language file;
[0004] The initial data includes: an initial dictionary, batch deleting several entries in the multilingual file, including: determining a key value array of the entry to be deleted according to the preset configuration file, traversing the key value array of the entry 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 several entries in a multi-language file, including: 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 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 multi-language files into a target translation table includes: reading all the multi-language 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 their respective target translation value arrays; and exporting the target key value array and all the target translation value arrays by column into a target translation table 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 the term in each language is located to obtain an array of translation values of the term in each language; 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 process further includes: performing escape processing on specific characters on 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 the 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 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, and the preset regular expression includes: entry, single-line comment, 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 a 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.
[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; an initial index is set, and its value is M; according to the i-th standard key value, the corresponding initial translation value is searched from 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, the i-th standard translation value is used to replace the corresponding initial translation value in the initial dictionary; the updated initial dictionary is determined as the target dictionary.
[0013] In one embodiment, 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 is composed of the i-th standard key value and the i-th standard translation value; according to the i-th standard key value, a corresponding node array is determined from the initial tree structure object, and the corresponding node array includes 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 target data is written into the multilingual file, the target data including the target dictionary, including: the target dictionary includes P target key-value pairs, each key-value pair is sorted in the target dictionary in ascending order according to the index value of the key-value pair, and the target key-value pair array to be written is determined. 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;
[0016] Traverse the target key-value pair array to be written, judge the kth key value according to the 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 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, the writing the target data into the multi-language file, the target data including the target tree structure object, comprises: 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 multi-language file management method described in 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 multi-language file management method described in the first aspect.
[0020] The multilingual file management method, device and medium provided in the embodiments of the present invention can accurately and efficiently realize the automatic import of translations of target language entries in a translation table to be imported into a multilingual file, batch deletion of several entries in a multilingual file and export of a multilingual file as a target translation table according to a preset configuration file, thereby realizing the automatic management of multilingual files and greatly improving the accuracy of multilingual file management.
[0021] The multilingual file management method, device and medium provided by the present invention realize multilingual automatic management accurately and efficiently according to the configuration file. This solution is not only easy to operate and has strong applicability, 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 multi-language file management method provided by an embodiment of the present invention is shown;
[0024] Figure 2 A second flow chart of the multi-language file management method provided by an embodiment of the present invention is shown;
[0025] Figure 3 A third flow chart of the multi-language file management method provided by an embodiment of the present invention is shown;
[0026] Figure 4 A fourth flow chart of the multi-language file management method provided by an embodiment of the present invention is shown;
[0027] Figure 5 A fifth flow chart of the multi-language file management method provided by an embodiment of the present invention is shown;
[0028] Figure 6 A sixth flow chart of the multi-language file management method provided by an embodiment of the present invention is shown;
[0029] Figure 7 A seventh flow chart of the multilingual file management method provided by an embodiment of the present invention is shown;
[0030] Figure 8 An eighth flow chart of the multilingual file management method provided by an embodiment of the present invention is shown;
[0031] Fig. 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 in the embodiments of the present invention. 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 shown in the drawings 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 drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are 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 adding the possibility of 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 (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present invention belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present invention.
[0039] Example 1
[0040] Because different platforms have different multi-language file formats, the parsing, updating methods, and writing methods of multi-language files are also different. Taking the multi-language management of iOS and Android platforms as an example, the embodiment of the present application provides a multi-language file management method, which includes:
[0041] Import the target language entries in the translation table to be imported into the multilingual file, delete several entries in the multilingual file in batches, and export the translation of the multilingual file entries into a target translation table.
[0042] For details, see Figure 1 The step of importing the target language in the translation table to be imported into the multilingual file includes steps S110 to S150.
[0043] Step S110, obtaining a preset configuration file.
[0044] It can be understood that the preset configuration file is a json file, which can be parsed into a dictionary for configuration input of multilingual file management. The preset configuration file includes the type of multilingual platform, the folder path where the multilingual files are located, the path of the translation table to be imported, the mapping relationship between the translation language title and the corresponding multilingual file name in the translation table to be imported, the row where the translation language title is located in 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 translation terms are located in the translation table to be imported, the key value array of the term to be deleted, the preset string prefix of the key value annotated in the multilingual file, the path of the target translation table where the multilingual file is exported, etc.
[0045] Step S120, reading and parsing the multi-language file to obtain initial data.
[0046] In one implementation, 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 strings obtained by the traversal is connected together using an empty string as a connector to form a target string to be matched.
[0049] Step S122, setting an index value, whose initial value is 0. It can be understood that the index value is used to record the order of the successfully matched substrings later.
[0050] Step S123, use 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, add 1 to the index value, and extract the key value and translation value data or annotation data from the substring. The entry key value and translation value data, index value or preset annotation key value and annotation data, index value form an initial key-value pair. The preset regular expression includes: entry, single-line comment, multi-line comment extraction regular expressions.
[0051] In this embodiment, the target string is matched by extracting regular expressions through entries, single-line comments and multi-line comments. If the match is successful, the substring that matches successfully is extracted. For extracting entries, the key value and translation value obtained by the regular expression grouping capture do not contain unescaped double quotation marks, and the extraction of the entry is considered successful. The substring that matches successfully is then deleted from the target string, and the relative order of the substring that matches successfully is recorded by index increment, and the key value, translation value and index value are 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 matches 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, 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 multi-language file format is wrong.
[0053] In this embodiment, the named grouping regular expression used to extract the terms is expressed as follows using Python language:
[0054] r'^\s*"(?P <key>.*?[^\\](\\\\)*|(\\\\)*)"\s*=\s*"(?P <value>.*? [^\\](\\\\)*|(\\\\)*)"\s*;\s*', the regular expression can not only match the target string to obtain the term substring, but also further capture the key value and translation value of the term according to the named capture grouping. The key grouping captures the key value of the term, and the value grouping captures the translation value of the term. The named grouping 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 plus 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 a number of arbitrary characters in non-greedy mode plus an even number (including 0) of escape characters. 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 quotes after the entry key value, plus a number of spaces, plus an equal sign, plus a number of spaces, and then double quotes before the entry 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 in non-greedy mode plus an even number (including 0) of escape characters. 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 plus a number of spaces, a semicolon, and then a number of spaces.
[0060] In iOS multi-language files, the key value and translation value of an entry cannot contain unescaped double quotes. The above entry extraction regular expression does not detect whether the key value and translation value of the entry include unescaped double quotes. The following regular expression is used to further determine whether the key value and translation value contain unescaped double quotes. The regular expression for detecting the function of containing unescaped double quotes is expressed as follows in Python: 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 to match the target string includes: if the match is successful, first add 1 to the index value, delete the matched comment substring from the target string, concatenate the preset comment key value prefix in the configuration file with the index value as the comment key value, use the matched comment substring as the translation value, and then add the comment key value, comment translation value, and index value to the initial dictionary in the form of ({key value:{"key":key value,"value":comment value,"index":index value}}) to form a key-value pair. The single-line comment extraction regular expression is expressed in Python as follows: r'^\s* / / [^\n]*? \n'. Among them, ^\s* / / : matches the beginning of the string, indicating that the starting position of the string is composed of several spaces plus / / ; [^\n]*? \n': matches the composition of the comment, indicating that it is composed of several non-newline characters plus a newline character in non-greedy mode.
[0064] The regular expression used to extract multi-line comments to match the target string includes: if the match is successful, first add 1 to the index value, delete the matched comment substring from the target string, concatenate the preset comment key value prefix in the configuration file with the index value as the comment key value, use the matched comment substring as the translation value, and then form a key-value pair of the comment key value, the comment translation value, and the index value in the form of ({key value:{"key":key value,"value":comment value,"index":index value}}) and add it to the initial dictionary. The regular expression for extracting multi-line comments is expressed in Python as follows: r'^\s* / \*.*? \* / \s*'. Among them, ^\s* / \*: matches the beginning of the string, indicating that the starting position of the string is composed of several spaces plus / *; .*?: matches the content of the multi-line comment, indicating any number of characters in non-greedy mode; \* / \s*: matches the part after the multi-line comment, indicating that it is composed of * / plus several spaces.
[0065] Step S124: the initial key-value pairs constitute the initial dictionary.
[0066] It can be understood that if all the regular expressions for term extraction, single-line comments, and multi-line comments fail to match, it is further determined whether the target string to be matched is an empty string or only consists of spaces. If so, it means that the multi-language file is parsed. If not, it indicates that the multi-language file format is wrong (for example, the first 20 characters of the target string to be matched are printed, and all characters less than 20 are printed). If the multi-language file is parsed and there is no format error, the initial data obtained is the initial dictionary. Otherwise, the specific content of the error is prompted.
[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, the shell command plutil provided by the macOS system can also be used to parse the multi-language file into a json file. The command is: 'plutil-convert json-sro json file multi-language file', and then the json file is parsed into an initial dictionary. It should be noted that this method does not support the recognition of comments in multi-language files, that is, the converted json file does not contain the content of single-line comments and multi-line comments of multi-language 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 the multi-language files of the Android platform are in XML format. lxml is a Python library for processing XML and HTML. etree is the core module of lxml, which provides a rich set of APIs to process XML and HTML documents, and you can also choose whether to delete comments during parsing. Use etree to parse the Android multi-language files into an initial tree structure object as the initial data using the XML parser without deleting 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 the correct reading of the term key value of the translation table to be imported and the translation value of the term in each language.
[0079] Step S132, using 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 tabular data. The key values of the entries can be read by column according to the column where the key values of the entries are located and the row range where the translations of the entries are located to obtain an array of the key values of the entries.
[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] It can be understood that the preset configuration file has a description of the row where the language title is located in the translation table to be imported, and a mapping Map between each language title and the corresponding multilingual file name. Read the row where the language title is located, and obtain the content C of the corresponding cell in each column of the row. If the key value of the Map contains the content C, it means that this column is a column where the target language translation is located, and the mapping value corresponding to the content C in the Map is the multilingual file name corresponding to the target language. According to the column where the target language translation is located and the row range where the term translation is located obtained in the configuration file, the translation value of the term is read by column to obtain the target language translation value array.
[0083] Step S134, 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.
[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 process further includes: performing escape processing on specific characters on each element in the key value array and each element in the translation value array.
[0086] In a specific implementation, for the iOS platform, the unescaped double quotes in the elements of the key value and translation value array are escaped (because the iOS platform does not allow unescaped double quotes in the key value and translation value in the multi-language file, which is a multi-language file format error). Both the key value and the translation value are replaced by a regular expression, which is expressed in Python 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 plus 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 result of the match, 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 an odd number, the captured substring is returned directly. If the number of escape characters is an even number, a string consisting of the escape characters concatenated with the captured substring is returned.
[0087] In a specific implementation, for the Android platform, the unescaped single quotes in the elements of the key value and translation value array are escaped (because the Android platform does not allow unescaped single quotes in the key value and translation value in the multi-language file, which is a multi-language file format error). Regular expressions are used to perform substring replacement processing on both the key value and the translation value, which is expressed in Python 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 result of the match, 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 an odd number, the captured substring is returned directly. If the number of escape characters is an even number, a string consisting of the escape characters concatenated with the captured substring is returned.
[0088] Step S140: using 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 files corresponding to the target language can be determined, and the initial data obtained by parsing the multilingual files 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 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. Please refer to Figure 4 , step S140 includes: steps S141 to S144.
[0091] In this embodiment, for the iOS platform, the initial data is an initial dictionary, and the standard key-value pair array is traversed to obtain each standard key-value pair, and 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 composed 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 of which is composed of a key value and a translation value corresponding to the key 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 according to the standard key value at position i, 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 added to the initial dictionary in the form of a key-value pair {key value: {"key": key value, "value": translation value, "index": index value}}).
[0096] Step S143: if the corresponding initial translation value is not empty, the i-th standard translation value is used to replace the corresponding initial translation value in the initial dictionary.
[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 is composed of the i-th standard key value and the i-th standard translation value. Figure 5 , step S140 includes: steps S145~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 empty, and the target translation value corresponding to the target key value at position i is not empty, then the corresponding initial translation value is obtained from the initial tree structure object according to the target key value at position i, 1≤i≤N. Use the findAll method of the root object, according to the tag name "string" and the attribute name equal to the target key value at position i as conditions, find all nodes that meet the conditions, and form a node array, as shown below: XMLItems = root.findall('string[@name="{}"]'.format(excelKey)), 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-1st 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, it is determined 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 the nodes in the node array except the last node 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, the node label is set to "string", the value of the node attribute name is the target key value, the node content value is the target translation value corresponding to the target key value, the node tail is a line break, and the node is inserted as a child node from the tail into 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 sorts the key-value pairs in the target dictionary in ascending order according to the index value it carries, and determines the target key-value pair array to be written. 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; traverse the target key-value pair array to be written, judge the k-th key value according to the preset rules, and 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 k-th key value and the k-th translation value into a 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 k-th translation value 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 elements. 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 the translation value are concatenated according to the format rules of the entries in the project to form a string (the concatenated string format in iOS: "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 multi-language file, the target data including 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.
[0109] It can be understood that 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 of the multilingual file in the target language.
[0110] The multi-language file management method further includes: deleting several 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, obtaining 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, reading and parsing 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 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. If the translation value corresponding to the key value of the entry 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 entry data is the target data.
[0117] See also 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 a 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, searching for the 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.
[0123] In this embodiment, for each entry key value to be deleted, the lxml core module etree is used to query all nodes in the initial tree structure object 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 multilingual file entries into a target translation table. For details, please refer to Figure 8 The step 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 the respective initial data.
[0127] Step S840, merge the key values of the initial data of all languages to remove duplicates and remove the commented key values to obtain the target key value array, and then extract the target translation values corresponding to the target key values from the respective initial data according to the target key value array 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 multi-language file to obtain multiple target key value arrays; merge the multiple target key value arrays for deduplication processing, filter out the key values starting with the preset key value prefix in the configuration file, and obtain a target key value array, the target key value array includes the key values of all entries in the multi-language file; for each multi-language 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 label of the child node 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 content of the child node as the translation value to form a key-value pair. All key-value pairs form a dictionary, and then according to the method of extracting the target key value array and the target translation value array from the iOS initial dictionary, obtain the target key value array and the target translation value array from these dictionaries.
[0130] Step S850: According to the configuration file, the target key value array and all the target translation value arrays are exported column by column into a target translation table using an Excel processing tool.
[0131] The target key value array and the target translation value array are written into the Excel translation table. The method includes: for example, using a table processing tool including a pandas library, according to a configuration file, writing the target key value array into the column where the table key value is located, and writing each language title and its corresponding target translation value array into the column where the language translation value is located.
[0132] The multilingual file management method provided by the embodiment of the present invention accurately and efficiently realizes the automatic import of target language term translations in the translation table to be imported into the multilingual file, batch deletion of several terms in the multilingual file, and export of multilingual file term translations as the target translation table according to the preset configuration file, thereby realizing the automatic management of multilingual files 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 executed on the processor, the multi-language file management method provided in embodiment 1 is executed. Fig. 9 The electronic device 900 includes: a transceiver 901, a bus interface and a processor 902, wherein 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. Fig. 9 In the embodiment, the bus architecture may include any number of interconnected buses and bridges, specifically one or more processors represented by processor 902 and various circuits of memory represented by memory 903 are linked together. The bus architecture may also link together various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface. The transceiver 901 may be a plurality of components, namely, 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 may store data used by the processor 902 when performing operations. The electronic device 900 provided in an embodiment of the present invention may 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, on which a computer program is stored, and when the computer program is executed by a processor, the multi-language file management method provided in Example 1 is implemented. In this embodiment, the computer-readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc. The computer-readable storage medium provided in this embodiment can implement the multi-language file management method provided in Example 1, and to avoid repetition, it will not be repeated here.
[0138] In several embodiments provided in the present 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 architecture, 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 a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order 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 the flow chart, and the combination of boxes in the structure diagram and / or the flow chart, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0139] In addition, each functional module or unit 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 such an 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, and the computer software product is stored in a storage medium, including several instructions for 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: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0140] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered by the protection scope 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 multi-language file to obtain initial data; Importing the target language entry translation in the 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; using the standard key-value pair array to update the initial data to obtain target data; writing the target data into the multilingual file; The initial data includes: an initial dictionary, batch deleting several entries in the multilingual file, including: determining a key value array of the entry to be deleted according to the preset configuration file, traversing the key value array of the entry 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 several entries in a multi-language file, including: 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 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 multi-language files into a target translation table includes: reading all the multi-language 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 their respective target translation value arrays; and exporting the target key value array and all the target translation value arrays by column into a target translation table using an Excel processing tool according to the configuration file.
2. The multi-language 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: Determine 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; 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 multi-language 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 of specific characters on each element in the key value array and each element in the translation value array respectively.
4. The multi-language 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: Traversing the multilingual file line by line, 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 once, the substring obtained by the match is taken out, and key values and translation value data or annotation data are extracted from the substring. The entry key value and translation value data, index value or preset annotation key value and annotation data, index value are combined into an initial key-value pair. The preset regular expression includes: entry, single-line annotation, multi-line annotation extraction regular expressions; The initial key-value pairs constitute the initial dictionary.
5. The multi-language file management method according to claim 3, characterized in that: The initial data includes an initial dictionary. The reading and parsing of the multilingual file to obtain the initial data includes: After the multi-language file is converted 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 multi-language file management method according to claim 3, characterized in that: The initial file includes: an initial tree structure object, and the multi-language file is read and parsed to obtain initial data, including: The multi-language file is parsed using a preset format parser in a preset tool library to obtain the initial tree structure object.
7. The multi-language file management method according to claim 4 or 5, characterized in that: The target data includes: a target dictionary, and the method of using 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, 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 dictionary for a corresponding initial translation value; 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 is composed 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, wherein 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 the index value of each key-value pair, to determine the 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 the preset rules, determining whether the 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 into 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 invention comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is run on the processor, the multi-language file management method 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 multi-language 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
Text translation method and system based on multi-language entries
CN116522966A
Multi-language configuration management method, electronic equipment and storage medium
CN116739005A
String extraction and translation service
US20210165855A1
Cited By
Multi-language implementation method and system for relay protection device
CN121070508A