File processing method and device, electronic equipment, storage medium and product
By performing consistency checks and deduplication on multilingual resource files, the problems of inconsistent key structures and redundant keys are solved, enabling standardized management and efficient maintenance of resource files.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 北京中关村科金技术有限公司
- Filing Date
- 2025-12-26
- Publication Date
- 2026-05-01
AI Technical Summary
The maintenance of existing multilingual resource files suffers from inconsistent key structures, redundant keys, and invalid keys, resulting in low maintenance efficiency and a lack of intelligent identification and processing mechanisms.
By performing consistency checks on the baseline language resource files and the target language resource files, identifying the set of difference keys, and identifying redundant keys for deduplication when the set of difference keys is empty, and combining the reference information of the source code files to determine the set of invalid keys, an automated processing flow is provided.
It improves the maintenance efficiency of multilingual resource files, reduces omissions and misjudgments in manual operations, and ensures the consistency of key structure and the standardized management of resource files.
Smart Images

Figure CN121958221A_ABST
Abstract
Description
Document processing methods, apparatus, electronic devices, storage media and products Technical Field
[0001] This disclosure relates to the field of document processing technology, and in particular to a document processing method, apparatus, electronic device, storage medium, and product. Background Technology
[0002] During the internationalization development of software, it is necessary to provide text display in the corresponding languages for users in different regions. Therefore, multiple language resource files (such as Chinese, English, Japanese, etc.) will be configured. Usually, one language resource file is set as the base language resource file, and the rest are used as target language resource files.
[0003] The maintenance of existing multilingual resource files mainly relies on manual operation, which presents several technical challenges. First, the key structures of resource files in different languages are prone to inconsistencies, leading to abnormal display of internationalized text. Second, resource files often contain redundant keys with different keys but the same corresponding values, which not only increases the storage size of resource files but also raises subsequent maintenance costs. Third, as projects iterate, some resource file keys may no longer be referenced after source code adjustments, resulting in invalid keys. The long-term accumulation of these invalid keys will further increase the size of resource files, reduce resource loading efficiency, and lead to low maintenance efficiency of multilingual resource files. Summary of the Invention
[0004] This disclosure provides a document processing method, apparatus, electronic device, storage medium, and product to solve problems in the related art.
[0005] A first aspect of this disclosure provides a file processing method, comprising: acquiring multiple language resource files, including a base language resource file and a target language resource file; performing a consistency check on the keys in the base language resource file and the keys in the target language resource file to obtain a set of differing keys between the base language resource file and the target language resource file; in response to the length of the differing key set being zero, identifying redundant keys with the same value in the base language resource file and the target language resource file, and performing deduplication processing on the base language resource file and the target language resource file based on the redundant keys; scanning the source code file, and determining a set of invalid keys that are not referenced based on the reference information of the keys in the deduplicated base language resource file and / or the target language resource file in the source code file, wherein the invalid key set is used to prompt the user to process the deduplicated base language resource file and / or the target language resource file.
[0006] In one embodiment, a consistency check is performed on the keys in the base language resource file and the keys in the target language resource file to obtain a set of differences between the base language resource file and the target language resource file. This includes: extracting the keys in the base language resource file and the keys in the target language resource file to obtain a first key set and a second key set; determining the set of differences between the base language resource file and the target language resource file based on the different keys in the first key set and the second key set. The set of differences is used to prompt the user to correct the base language resource file and / or the target language resource file.
[0007] In one embodiment, after performing a consistency check on the keys in the base language resource file and the keys in the target language resource file to obtain a set of differences between the base language resource file and the target language resource file, the method provided in this disclosure further includes: in response to the length of the set of differences being zero, adjusting the order of the keys in the target language resource file according to the order of the keys in the base language resource file, so that the order of the keys in the target language resource file is the same as the order of the keys in the base language resource file.
[0008] In one embodiment, in response to the length of the difference key set being zero, determining redundant keys with the same value in the base language resource file and the target language resource file includes: in response to the length of the difference key set being zero, filtering out keys with the same value from the base language resource file to obtain at least one candidate key group, each candidate key group including at least two candidate keys; querying the value corresponding to each candidate key in the same candidate key group in the target language resource file; and in response to the fact that the values corresponding to each candidate key in the same candidate key group are all the same, determining that the candidate keys in the candidate key group are redundant keys with the same value in the base language resource file and the target language resource file.
[0009] In one embodiment, scanning the source code file and determining a set of invalid keys that are not referenced based on the reference information of keys in the deduplicated base language resource file and / or target language resource file in the source code file includes: scanning the source code file and determining a third key set based on the reference information of keys in the deduplicated base language resource file and / or target language resource file in the source code file; and determining a set of invalid keys that are not referenced based on the first key set and the third key set.
[0010] In one embodiment, after scanning the source code file and determining invalid keys that are not referenced based on the reference information of keys in the deduplicated base language resource file and / or target language resource file in the source code file, the method provided in this disclosure further includes: scanning the source code file to identify code snippets that call internationalization functions; and inserting dependency import statements at a preset position in the source code file in response to the fact that the source code file containing the code snippets does not contain dependency import statements required for internationalization functions.
[0011] A second aspect of this disclosure provides a file processing apparatus, comprising: an acquisition unit for acquiring multiple language resource files, including a base language resource file and a target language resource file; a verification unit for performing consistency verification on keys in the base language resource file and keys in the target language resource file to obtain a set of differing keys between the base language resource file and the target language resource file; a processing unit for determining redundant keys with the same value in the base language resource file and the target language resource file in response to the length of the differing key set being zero, and performing deduplication processing on the base language resource file and the target language resource file based on the redundant keys; and a determination unit for scanning source code files and determining a set of invalid keys that are not referenced based on the reference information of keys in the deduplicated base language resource file and / or the target language resource file in the source code file, the invalid key set being used to prompt the user to process the deduplicated base language resource file and / or the target language resource file.
[0012] A third aspect of this disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the methods described in the first aspect of this disclosure.
[0013] A fourth aspect of this disclosure provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to perform the methods described in the first aspect of this disclosure.
[0014] A fifth aspect of this disclosure provides a computer program product including a computer program that, when executed by a processor, implements the methods described in the first aspect of this disclosure.
[0015] In summary, this disclosure proposes a file processing method, which includes: acquiring multiple language resource files, including a base language resource file and a target language resource file; performing consistency verification on the keys in the base language resource file and the keys in the target language resource file to obtain a set of differing keys between the base language resource file and the target language resource file; in response to the length of the differing key set being zero, identifying redundant keys with the same value in the base language resource file and the target language resource file, and performing deduplication processing on the base language resource file and the target language resource file based on the redundant keys; scanning the source code file, and based on the reference status of the keys in the deduplicated base language resource file and / or the target language resource file in the source code file, determining a set of invalid keys that are not referenced, the invalid key set being used to prompt the user to process the deduplicated base language resource file and / or the target language resource file.
[0016] According to the solution provided in this disclosure, by acquiring multiple language resource files, including baseline language resource files and target language resource files, the keys of the two types of files are first checked for consistency to obtain a set of differing keys. This accurately locates inconsistencies in the key structure, avoiding the tedious manual comparison of keys one by one. When the length of the differing key set is zero, redundant keys with different keys but the same value are further identified and deduplicated, saving the manual maintenance of multiple synonym keys. Finally, the source code files are scanned, and the references of the keys in the deduplicated resource files are combined to determine the set of invalid keys, providing a basis for users to clean up useless data and avoiding meaningless maintenance of invalid keys. Through this series of automated verification, deduplication, and identification operations, the traditional manual multilingual resource file maintenance mode is replaced, reducing omissions, misjudgments, and repetitive work caused by manual operations, thereby improving the maintenance efficiency of multilingual resource files.
[0017] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0019] Figure 1 is a flowchart illustrating a file processing method according to an embodiment of this disclosure; Figure 2 is a flowchart illustrating a method for verifying key corruption according to an embodiment of this disclosure; Figure 3 is a flowchart illustrating a method for verifying line count corruption according to an embodiment of this disclosure; Figure 4 is a flowchart illustrating a method for verifying duplicate fields according to an embodiment of this disclosure; Figure 5 is a flowchart illustrating a method for verifying useless fields according to an embodiment of this disclosure; Figure 6 is a flowchart illustrating a method for verifying reference errors according to an embodiment of this disclosure; Figure 7 is a flowchart illustrating yet another file processing method according to an embodiment of this disclosure; Figure 8 is a flowchart illustrating a file processing method provided by an application example of this disclosure. Figure 9 is a flowchart illustrating another file processing method provided by the application example of this disclosure; Figure 10 is a schematic diagram illustrating a key error verification result provided by the application example of this disclosure; Figure 11 is a schematic diagram illustrating a row count error verification result provided by the application example of this disclosure; Figure 12 is a schematic diagram illustrating a duplicate field verification result provided by the application example of this disclosure; Figure 13 is a schematic diagram illustrating a useless field verification result provided by the application example of this disclosure; Figure 14 is a schematic diagram illustrating a reference error verification result provided by the application example of this disclosure; Figure 15 is a structural schematic diagram of a file processing device provided by an embodiment of this disclosure; Figure 16 is a hardware composition structural schematic diagram of an electronic device provided by an embodiment of this disclosure. Detailed Implementation
[0020] Embodiments of this disclosure are described in detail below. Examples of these embodiments are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this disclosure, and should not be construed as limiting this disclosure.
[0021] The vast majority of existing internationalization projects rely on manual searching and comparison of differences between multiple language resource files, such as inconsistent keys or line counts, followed by manual modification. This approach lacks the ability to automatically identify duplicate and useless fields, and cannot perform batch, secure deduplication or deletion of these fields. It relies on the find-and-replace methods of the Integrated Development Environment (IDE), which compromises both efficiency and security. Some files lack dependencies for internationalized Application Programming Interface (API) objects, making batch and automatic injection impossible, leading to errors during project startup or runtime. This requires testers and developers to manually check and fix each issue one by one.
[0022] The above solution has the following drawbacks: manual verification is inefficient and prone to errors; it lacks an intelligent mechanism for identifying duplicate / useless fields; it cannot detect field reference errors in the code; the file reconstruction process requires full manual intervention; and it lacks dynamic cross-file association detection capabilities.
[0023] To address the shortcomings of related technologies, this disclosure obtains multiple language resource files, including a base language resource file and a target language resource file. First, it performs a consistency check on the keys of both types of files to obtain a set of differing keys. This accurately locates inconsistencies in key structures, avoiding the tedious manual comparison of keys one by one. When the length of the differing key set is zero, it further identifies redundant keys in the two types of files that have different keys but the same value and performs deduplication, saving the manual maintenance of multiple synonym keys. Finally, it scans the source code files and, based on the references of the keys in the deduplicated resource files, determines the set of invalid keys, providing a basis for users to clean up useless data and avoiding meaningless maintenance of invalid keys. Through this series of automated verification, deduplication, and identification operations, it replaces the traditional manual multilingual resource file maintenance mode, reducing omissions, misjudgments, and repetitive work caused by manual operations, thereby improving the efficiency of multilingual resource file maintenance.
[0024] The present disclosure will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0025] The file processing method provided in this disclosure can be applied to software internationalization development and maintenance scenarios, such as multilingual front-end projects, cross-language back-end systems, and global application (APP) development. The execution subject of the method can be a computer device, such as a server or terminal computer, or a code inspection tool or IDE plugin equipped with automated scripts.
[0026] As shown in Figure 1, Figure 1 is a schematic flowchart of a file processing method provided by an embodiment of this disclosure. The file processing method provided by this embodiment includes the following steps: Step 101, obtaining multiple language resource files, which include a base language resource file and a target language resource file; in one embodiment, the multiple language resource files refer to structured files used to store different language presentation texts in a software internationalization project, storing data in the form of key-value pairs. Among them, the base language resource file is a preset reference standard file, usually the project's default language, such as a Chinese resource file, used to unify the structure and content of other language files; the target language resource file is other language files that need to be verified and adjusted with reference to the base file, such as English and Japanese resource files, and common formats are JavaScript Object Notation (JSON), Extensible Markup Language (XML), etc.
[0027] In one embodiment, the key is a unified resource identifier in the multilingual resource file, which is a unique index connecting the source code file and the resource file. The value is the specific display text corresponding to the key in the multilingual resource file. The value corresponding to the same key is different in different language resource files. For example, "user_name" in the Chinese file corresponds to "username" and "user_name" in the English file corresponds to "User Name".
[0028] In one embodiment, there is typically one base language resource file, and there may be one, two, or more target language resource files.
[0029] In one embodiment, file reading technology is used to load all multilingual resource files in a preset directory, parse the contents of the multilingual resource files into a processable data structure, such as a SON object, and distinguish between the base language resource files and the target language resource files.
[0030] In one embodiment, a resource file storage directory, such as . / src / i18n / lang, can be pre-configured. File operation APIs, such as Node.js's fs.readdirSync and fs.readFileSync, can be used to traverse all files in the directory that conform to the .json format, specifying zh.json as the base language resource file and the rest as target language resource files.
[0031] In one embodiment, all resource file paths and base file identifiers can be listed in the project configuration file i18n.config.js. After the script reads the configuration file, the base language resource files and target language resource files are loaded according to the paths.
[0032] Step 102: Perform consistency verification on the keys in the base language resource file and the keys in the target language resource file to obtain the set of differences between the base language resource file and the target language resource file. In one embodiment, the set of differences refers to the set of keys that exist only in one of the base language resource file and the target language resource file. For example, if the base language resource file has a key "age" but the target language resource file does not have this key, then "age" is included in the set of differences.
[0033] In one embodiment, keys from the base language resource files can be extracted to form set A, and keys from the target language resource files can be extracted to form set B. The difference between A and B is calculated, i.e., the keys that exist in the base language resource files but not in the target language resource files, and the difference between B and A is calculated, i.e., the keys that exist in the target language resource files but not in the base language resource files. If there are multiple target resource files, the above operation is repeated for all target language resource files. The difference keys between the base language resource files and each target language resource file are summarized to form the final difference key set, and the file corresponding to each key is labeled.
[0034] In one embodiment, it is also possible to first traverse all keys in the base language resource file and check whether each key exists in each target language resource file. If it does not exist, it is added to the difference key set. Then, it is possible to traverse all keys in each target language resource file and check whether each key exists in the base language resource file. If it does not exist, it is added to the difference key set.
[0035] Step 103: In response to the fact that the length of the difference key set is zero, redundant keys with the same value in the base language resource file and the target language resource file are identified, and deduplication is performed on the base language resource file and the target language resource file based on the redundant keys. In one embodiment, a redundant key refers to a key group with different key names, but whose corresponding values are completely consistent in the base language resource file and all target language resource files. For example, in the base language resource file, "minute1":"minute" and "minute2":"minute", while in the English file, "minute1":"Minute" and "minute2":"Minute", "minute1" and "minute2" are redundant keys.
[0036] In one embodiment, it is first determined whether the set of difference keys is empty, that is, whether the key structures are completely identical. If it is empty, key groups with different keys but identical values are selected. Then, one target key in the key group is retained, the remaining redundant keys are deleted, and all language resource files are updated synchronously.
[0037] In one embodiment, keys with the same value can be selected from the base language resource file to form a candidate key group (e.g., [{key: "minute1", value: "minute"}, {key: "minute2", value: "minute"}]). Each target language resource file is traversed to check whether the value corresponding to each key in the candidate key group is completely consistent. If all target language resource files meet the requirement, the candidate key group is determined to be a redundant key.
[0038] In one embodiment, all key-value pairs in the baseline language resource file can be extracted first to construct a value-key list mapping table, such as {"minute": ["minute1", "minute2"]}). Then, the same operation can be performed on each target language resource file to construct a value-key list mapping table for the corresponding language. Finally, the mapping tables of all language resource files are compared. If the key list corresponding to a certain value is completely consistent in all languages and the number of keys is not less than 2, then the key list is determined to be a redundant key.
[0039] In one embodiment, deduplication of the base language resource file and the target language resource file can be achieved by retaining the earliest appearing key among the redundant keys, deleting the remaining keys, traversing all language resource files, and deleting the corresponding redundant keys.
[0040] In one embodiment, deduplication of the base language resource file and the target language resource file can also be achieved by predefining key naming rules, such as prioritizing short names and keys that conform to business semantics, selecting keys that conform to the rules from the redundant key group as retained keys, and deleting the remaining keys.
[0041] Step 104: Scan the source code file. Based on the reference information of keys in the deduplicated base language resource file and / or target language resource file in the source code file, determine the set of invalid keys that are not referenced. The set of invalid keys is used to prompt the user to process the deduplicated base language resource file and / or target language resource file.
[0042] In one embodiment, source code files refer to the core business code files of a software project. They are the main entities that call multi-language resource files, including front-end page files (.vue, .jsx), script files (.js, .ts), etc., and are usually stored in the project's src directory.
[0043] In one embodiment, the invalid key set refers to the set of keys in the deduplicated multilingual resource file that are not referenced by the source code file.
[0044] In one embodiment, taking a front-end internationalization project based on Node.js, using the Vue framework and the vue-i18n internationalization plugin as an example, the base language resource file (zh.json) and the target language resource files (en.json, ja.json) are stored in the project's / src / i18n / lang directory.
[0045] In one embodiment, internationalization call regular expressions can be defined to match call statements in the i18n.t("key") format in the source code file; all .vue and .js files under the src directory of the project can be recursively traversed, and all called keys, i.e. the set of used keys, can be extracted by regular expression matching; the set of invalid keys can be obtained by forming the difference between the full set of keys and the set of used keys based on the keys of the deduplicated base language resource file.
[0046] This application aims to address the low maintenance efficiency caused by inconsistent key structures, redundant data accumulation, and invalid data residue in the maintenance of multilingual resource files. It achieves standardized management of resource files through systematic processing. First, it acquires multiple language resource files, including a baseline language resource file and a target language resource file. The baseline language resource file serves as the reference standard, while the target language resource file is the object to be verified and adjusted. Then, it verifies the consistency of keys in the baseline and target language resource files, filtering out differing keys that exist only in one side and forming a set of differing keys. When the set of differing keys is empty (i.e., the key structures are completely identical), it further identifies redundant keys in the baseline and target language resource files that differ in key but have the same corresponding value, and performs deduplication processing on both types of resource files based on these redundant keys. Finally, by scanning the source code files and combining the reference information of keys in the deduplicated resource files within the source code, it determines a set of invalid keys that are not referenced. This set of invalid keys is used to prompt the user to perform targeted processing on the deduplicated resource files.
[0047] By standardizing the multilingual resource file processing flow, the consistency of key structure of resource files in different languages is ensured, the occupation of resource files by redundant and invalid data is reduced, and the maintenance efficiency of multilingual resource files is improved. At the same time, the design of determining invalid keys based on source code references avoids the blind cleaning of invalid data.
[0048] In one embodiment, a consistency check is performed on the keys in the baseline language resource file and the keys in the target language resource file to obtain a set of differing keys between the baseline language resource file and the target language resource file. This includes: extracting the keys from the baseline language resource file and the keys from the target language resource file to obtain a first key set and a second key set. In one embodiment, the first key set refers to a set or data group consisting of all keys extracted from the baseline language resource file, used to compare whether the keys in the target language resource file completely match. The second key set refers to a set or data group consisting of all keys extracted from a single target language resource file.
[0049] In one embodiment, the base language resource file and the target language resource file in JSON format can be read using fs.readFileSync, parsed into JavaScript objects using JSON.parse, and then all keys of the objects can be directly extracted using the Object.keys() method to generate a first key set and a second key set.
[0050] In one embodiment, the base language resource file and the target language resource file in XML format can be parsed using tools such as xml2js, the parsed nodes can be traversed, the key attribute values of the nodes can be extracted, and a first key set and a second key set can be generated.
[0051] Based on the different keys in the first key set and the second key set, determine the difference key set between the base language resource file and the target language resource file. The difference key set is used to prompt the user to correct the base language resource file and / or the target language resource file.
[0052] In one embodiment, different keys refer to keys that exist only in the first key set or only in the second key set, excluding keys that exist in both sets simultaneously; the difference key set is a set composed of the aforementioned different keys, including keys that exist in the base language resource file but not in the target language resource file, as well as keys that exist in the target language resource file but not in the base language resource file, with the corresponding language resource file identifier attached.
[0053] In one embodiment, the _.difference method of the lodash tool library can be used to obtain the unique keys of the base language resource file and the target language resource file respectively, and then merge the unique keys of the base language resource file and the target language resource file to obtain a set of difference keys.
[0054] In one embodiment, a file parsing tool reads the contents of the baseline language resource file and the target language resource file, extracting all keys from the key-value pair structures of the two types of files to form a first key set and a second key set. A set comparison algorithm is used to screen for differences between the first key set and the second key set. Specifically, each key in the first key set is traversed to determine if it exists in the second key set, and keys that do not exist are marked as baseline-specific difference keys. Simultaneously, each key in the second key set is traversed to determine if it exists in the first key set, and keys that do not exist are marked as target-specific difference keys. Finally, the two types of unique keys are combined to form a difference key set. The difference key set is used to prompt the user to add missing keys to the baseline language resource file or delete redundant keys to the target language resource file, thus completing the key structure correction.
[0055] By extracting the key set and accurately comparing the difference keys, the key structure differences between the benchmark and target language resource files can be quickly located, ensuring the comprehensiveness and accuracy of the difference key recognition. The difference key set can provide users with clear correction guidance, avoiding omissions or misoperations during the correction process.
[0056] In one embodiment, as shown in Figure 2, which is a flowchart illustrating a method for verifying key misalignment according to an embodiment of this disclosure, the method includes: loading multilingual files zh.json and en.json into memory using a file read / write program; obtaining all keys from these two files and converting them into arrays zhKeys and enKeys; calculating the difference between the two arrays, diffKeys; outputting the diffKeys information to the console and prompting the user; then determining whether the length of the difference diffKeys is 0; if it is 0, the process ends; if it is not 0, the user manually corrects the field misalignment problem. During this process, the user may need to modify Chinese and other language files simultaneously. After the correction is completed, the process returns to loading the multilingual files and re-executes the process.
[0057] In one embodiment, after performing a consistency check on the keys in the base language resource file and the keys in the target language resource file to obtain a set of differing keys between the base language resource file and the target language resource file, the file processing method further includes: in response to the length of the differing key set being zero, adjusting the order of the keys in the target language resource file according to the order of the keys in the base language resource file, so that the order of the keys in the target language resource file is the same as the order of the keys in the base language resource file.
[0058] In one embodiment, the length of the difference key set being zero indicates that, after consistency verification, the base language resource file and the target language resource file do not contain keys belonging to only one of the files, and the key sets of the two files are completely identical.
[0059] In one embodiment, the order of keys in the base language resource file refers to the natural order of key-value pairs within the base language resource file. This order is typically determined by rules such as business logic and module classification, for example, sorted by basic information, business functions, and prompt text. The order of keys in the target language resource file refers to the order of key-value pairs within the target language resource file before adjustment. Before adjustment, the order may differ from that of the base language resource file. The same key order means that the order of all keys in the target language resource file is completely consistent with the key order of the base language resource file, and the value corresponding to the key retains the text content of its respective language.
[0060] In one embodiment, taking the aforementioned Vue internationalization project in the Node.js environment as an example, the base language resource file is zh.json, which contains Chinese characters and follows the business specification order of keys. The target language resource file is en.json, which contains English characters and has disordered keys. The key order array of the base language resource file and the key-value pair mapping relationship of the target language resource file are extracted respectively. According to the key order array of the base language resource file, the key-value pairs of the target language resource file are rearranged to generate new target language resource file content. The new target language resource file content is written into the original en.json, so that the order of keys in the target language resource file is the same as the order of keys in the base language resource file.
[0061] In one embodiment, an empty ordered object can be created, and the corresponding key-value pairs can be retrieved from the target language resource file in the order of the keys in the base language resource file and inserted into the new object. Finally, the new object is converted into a JSON string and written to the target language resource file.
[0062] In one embodiment, the key-value pairs of the target language resource file can be converted into an array in [key, value] format, then the array can be reordered according to the base key order array, and finally converted back into a JSON object to obtain a target language resource file with the same key order as the base language resource file.
[0063] In one embodiment, after completing the key consistency check and confirming that the length of the differing key set is zero, the complete content of the baseline language resource file is first read, and the natural order of its internal key-value pairs is parsed to generate an ordered baseline key order list. Subsequently, the key-value pair data of the target language resource file is read, and a mapping table between keys and corresponding values is constructed to ensure that value information is not lost. Based on the baseline key order list, the key-value pair structure of the target language resource file is reorganized. According to the order of the keys in the list, the corresponding key-value pairs are extracted from the mapping table and rearranged to generate new target language resource file content. The values corresponding to each key retain their original language text; only the order of the keys is adjusted. Finally, the key order alignment between the target language resource file and the baseline language resource file is completed.
[0064] By using target key reorganization guided by the base key order, the key structure order of multilingual resource files can be accurately unified, improving the readability and standardization of resource files; and avoiding the problem of low efficiency in manual maintenance caused by disordered key order.
[0065] For example, to correct line number errors, a file I / O program loads the JSON file into memory and converts it into a JSON object. Using zh.json as a base, it iterates through zh.json sequentially, checking if the key in the current line of other languages, such as en.json, matches the key in the current line of zh.json. If they match, it moves to the next line; otherwise, it finds the key in en.json and moves the found line to the current line, until the last line of zh.json is reached, thus correcting the line number error in en.json. Other target language resource files are processed similarly. Because the length of the aforementioned set of differencing keys is zero, it ensures that there are no differences between keys in any resource file, preventing situations where keys cannot be found.
[0066] In one embodiment, as shown in Figure 3, which is a flowchart illustrating a method for verifying line count disorder provided by this embodiment, all resource files are first loaded into memory and converted into JSON objects for traversal. Then, each line is traversed sequentially based on zh.json. Subsequently, the nth line is traversed and its key is recorded as k. Then, it is determined whether the key of the nth line in en.json is equal to k. If it is equal, the traversal continues to the next line. If it is not equal, the line with the key equal to k in en.json is found and moved to the nth line. After completion, it is determined whether n is the last line of zh.json. If not, the traversal continues to the next line. If it is, the process ends.
[0067] In one embodiment, in response to the length of the difference key set being zero, determining redundant keys with the same value in the base language resource file and the target language resource file includes: in response to the length of the difference key set being zero, filtering out keys with the same value from the base language resource file to obtain at least one candidate key group, each candidate key group including at least two candidate keys; in one embodiment, the candidate key group is a key group with the same value but different key names filtered from the base language resource file, and the number of keys in the candidate key group is at least 2.
[0068] In one embodiment, an empty object can be created as a mapping container for the value-key list. The key-value pairs of the base language resource file are traversed, and the keys corresponding to the same value are stored in the same array. Finally, key groups with an array length of not less than 2 are selected as candidate key groups.
[0069] In one embodiment, all values in the baseline file can be extracted and deduplicated. Each unique value is traversed, and all keys corresponding to that value are selected. If the number of keys is not less than 2, they are selected as candidate key groups.
[0070] In the target language resource file, the value corresponding to each candidate key in the same candidate key group is queried; in one embodiment, the target language resource file is read and parsed into an object, and each candidate key is traversed to obtain the value corresponding to the candidate key.
[0071] In response to the values corresponding to each candidate key in the same candidate key group being the same, it is determined that the candidate key in the candidate key group is a redundant key with the same value in the reference language resource file and the target language resource file.
[0072] In one embodiment, the values corresponding to the candidate keys being the same means that for all keys within the same candidate key group, the values of the corresponding "value" in each target language resource file are exactly the same. For example, in the reference language resource file, the values of "minute1" and "minute2" are both "minute", and in the English file, the values of both are "Minute".
[0073] In one embodiment, the values of the candidate key group in a single target language resource file can be de-duplicated. If the length of the array after de-duplication is 1, it means that the values of the candidate keys in this target language resource file are the same. Traverse all target language resource files, and if all are satisfied, it is determined as a redundant key.
[0074] In one embodiment, it is also possible to use the value corresponding to the first key in the candidate key group as a reference, traverse the values corresponding to other keys, and compare one by one whether they are consistent with the value corresponding to the first key. If all are consistent, then this target language resource file meets the condition, and if all target language resource files meet the condition, it is determined as a redundant key.
[0075] In one embodiment, on the premise that the length of the difference key set is zero, first traverse the key-value pairs of the reference language resource file, construct a value-key mapping table, group the keys with the same value into a group, and determine the candidate key group. Read the content of all target language resource files. For each candidate key in each candidate key group, query the specific value corresponding to it in each target language resource file through key matching, and record the value information of each candidate key in different target files. If the values of all candidate keys in the same candidate key group corresponding to each target language resource file are exactly the same, then it is determined that this candidate key is a redundant key; if there is a situation where the candidate key values are inconsistent in any target file, then this group of candidate keys is excluded.
[0076] Exemplarily, check for duplicate fields. Duplicate fields refer to fields where the keys are different but the values are the same. Use a file reading and writing program to load the json file into memory and convert it into a json object. Taking zh.json as the benchmark, traverse zh.json to find all keys with the same value and store them in the pre-query duplicate array preRepeatKeys. preRepeatKeys is a two-dimensional array. The first dimension represents all duplicate values, and the second dimension is the keys included in each duplicate value. Then traverse these keys in preRepeatKeys and query the value of these keys in other resource files such as en.json. If the values queried in en.json are also duplicate, then these keys can be determined to be duplicate fields in the true sense and stored in repeatKeys. For example: In the Chinese zh.json, there are two fields: "key1": "point", "key2": "point", and their values are both the Chinese character "point" in Chinese, so they are determined to be pre-query duplicate fields. However, in English, their values are different: "key1": "score", "key2": "minute". Score represents a score, while minute represents a minute. Therefore, ultimately key1 and key2 are not fields with duplicate values. Only keys with duplicate values in all multilingual resource files are true duplicate fields and are completely useless. You can directly use tools for automated deduplication and only retain one field. When performing field deduplication, the entire project can be refactored. Use methods such as reading and writing programs, strings, and regular expressions to unify the places in the project where these duplicate keys are referenced and remove duplicate references.
[0077] In one embodiment, as shown in FIG. 4, FIG. 4 is a schematic flowchart of a method for verifying duplicate fields provided by an embodiment of the present disclosure. First, load all resource files into memory and convert json into an array for traversal. Then, find all duplicate keys with equal values in zh.json and record them in the two-dimensional array PreRepeatKeys. Subsequently, traverse the keys in the PreRepeatKeys array, and then traverse the next set of duplicate keys. Then, determine whether the values corresponding to these duplicate keys in en.json are also equal. If they are not equal, continue to traverse the next set of duplicate keys. If they are equal, mark these truly duplicate fields and record them in the final duplicate array RepeatKeys. Then, refactor the references to these duplicate keys in the project so that they all reference the first key. After completion, end.
[0078] In one embodiment, scanning the source code file and determining a set of invalid keys that are not referenced, based on the reference information of keys in the deduplicated base language resource file and / or target language resource file within the source code file, includes: scanning the source code file and determining a third key set based on the reference information of keys in the deduplicated base language resource file and / or target language resource file within the source code file. In one embodiment, the third key set refers to the set of keys from the actually invoked multilingual resource files extracted by scanning the source code file. The keys in this set all come from the deduplicated base language resource file or target language resource file, reflecting the actual reference information of the multilingual keys in the source code.
[0079] In one embodiment, the specified directory is recursively traversed through the file operation API to filter out target file types such as .vue files, .js files, and .ts files. The contents of each file are read one by one, and regular expressions that match internationalization calls are defined to extract keys from the file contents to obtain a third key set.
[0080] In one embodiment, a list of directories to be scanned can be defined in a configuration file. After the script reads the configuration, it only traverses the specified directories, which improves scanning efficiency. Alternatively, specified directories can be excluded during recursive traversal to avoid scanning irrelevant files and improve scanning efficiency.
[0081] Based on the first key set and the third key set, determine the set of invalid keys that are not referenced.
[0082] In one embodiment, the set of invalid keys that are not referenced refers to the set of keys that exist in the first set of keys after deduplication but not in the third set of keys. These keys exist in the base language resource file or the target language resource file, but are never called in the source code and are redundant data with no business value.
[0083] In one embodiment, based on the first key set and the third key set, the two key sets are converted into a Set data structure, and the has method of Set is used to quickly determine whether the key exists and identify the set of invalid keys that are not referenced.
[0084] In one embodiment, each key in the first key set can be traversed first, and each key can be checked to see if it exists in the third key set. If it does not exist, it can be added to the invalid key set.
[0085] In one embodiment, firstly, the range of source code files to be scanned is determined. A file traversal tool recursively traverses all business code files in the project's source code directory. A regular expression matching algorithm scans the content of each file, identifying code statements that call multi-language resource keys and extracting the corresponding key identifiers from these statements. Combining the key information from the deduplicated base language resource files and target language resource files, the extracted key identifiers are validated, and invalid identifiers not belonging to either type of resource file are removed, ultimately forming a third key set (source code reference key set). Subsequently, based on the aforementioned first key set, a set difference algorithm is used to compare the first key set with the third key set, filtering out keys that exist in the first key set but not in the third key set. These keys are the unreferenced invalid keys, forming an invalid key set.
[0086] By accurately scanning the source code to extract reference keys and combining this with the specific implementation of the first key set comparison, invalid keys that are not actually called in the resource file can be accurately identified, avoiding the omission or misjudgment of invalid keys; based on the existing first key set comparison design, the invalid key identification process is simplified and the detection efficiency is improved.
[0087] For example, to validate useless fields, first convert all keys in zh.json into a string array allKeys. Use a file reader, such as Node.js's FileReader method, to recursively read all .vue and .js files under the project's src directory. After reading the content of a file, immediately iterate through allKeys and use string lookup methods, such as JavaScript's String.include method, to find the keys used in the file content and store them in a Map object named usedKeyMap. Since map objects inherently have deduplication properties, the keys in usedKeyMap will not be duplicated. After collecting all duplicate keys, convert them into an array usedKeys. Finally, use an array difference algorithm to find the difference between allKeys and usedKeys, obtaining an array set of useless fields, uselessKeys. It is important to note that these useless fields and references cannot be directly deleted like duplicate fields, because they may be reserved fields that are not currently used. Therefore, simply prompt the user and let them choose whether to delete them.
[0088] In one embodiment, as shown in Figure 5, which is a flowchart of a method for verifying useless fields provided by this embodiment, the process first traverses all files (.vue, .js, etc.) under the src directory of the project and reads the content of each file. Then, it traverses all keys in zh.json within each file and checks whether the file content contains these keys. After that, it determines whether the file content contains the key. If it does not contain the key, it traverses the next key. If it does contain the key, it adds the key to the used key collection usedKeyMap and removes duplicates. After traversing all files, it finds the difference between the used key and all keys and stores it in the useless key collection usedKeys. Then, it outputs the uselessKeys to the user, allowing the user to decide whether to delete these useless keys. Finally, the process ends.
[0089] In one embodiment, after scanning the source code file and determining the references of keys in the deduplicated base language resource file and / or target language resource file in the source code file, and identifying invalid keys that are not referenced, the file processing method further includes: scanning the source code file to identify code snippets that call internationalization functions; in one embodiment, the code snippets for internationalization functions refer to code statements in the source code that call multilingual internationalization capabilities, and obtain multilingual text snippets through internationalization interfaces such as i18n.t("key") and this.$t("key").
[0090] In one embodiment, for different internationalization framework calling formats, a dedicated regular expression can be defined to traverse the file content. If the corresponding expression is matched, it is determined that the file contains a code snippet that calls the internationalization function.
[0091] In one embodiment, custom internationalization call keywords / function names can also be defined in the configuration file. After the script reads the configuration, it identifies the code snippets corresponding to the internationalization functions through string matching or regular expression matching.
[0092] In response to the fact that the source code file containing the code snippet does not contain the dependency import statements required for internationalization, the dependency import statements are inserted at a preset location in the source code file.
[0093] In one embodiment, the dependency import statement required for internationalization functionality refers to the code statement that imports internationalization tools / frameworks, such as vue-i18n and react-i18next, into the current source code file, such as import { useI18n} from 'vue-i18n' or import i18n from '@ / i18n'. This is a prerequisite for the source code to call internationalization functionality.
[0094] In one embodiment, the preset position refers to a fixed position in the source code file that is agreed upon for inserting import statements, usually at the top of the file, before all business code and after comments, in accordance with coding standards.
[0095] In one embodiment, a matching string for internationalization dependency import statements can be defined, the file content can be read, and it can be determined whether the string is contained. If it is not contained, it is determined that the source code file containing the code snippet does not contain the dependency import statements required for internationalization. Alternatively, a fuzzy matching regular expression can be defined to ignore format differences such as spaces and newlines, and verify whether the source code file contains the core import logic. If it is not contained, it is determined that the source code file containing the code snippet does not contain the dependency import statements required for internationalization.
[0096] In one embodiment, when reading file content, dependency import statements can be inserted at the very top of the file, or they can be inserted after the comment and before the business code by matching the end position of the comment using regular expressions.
[0097] In one embodiment, after determining the invalid key set, the aforementioned source code scanning scope is continued, and a syntax parsing tool is used to scan each source code file to identify code fragments that call internationalization functions. Specifically, the target code fragment is located by matching internationalization interface call keywords, such as "i18n.t" and "$t". For source code files containing target code fragments, the import statement area at the top of the file is further parsed, and a string matching algorithm is used to detect whether there are dependency import statements required for internationalization functions, such as "import i18n from '@ / i18n'". If the file does not contain such dependency import statements, the position after the top comment area of the file and before the business code is determined as the preset insertion position. The standardized dependency import statement is inserted at this position using a file writing tool, ensuring the syntactic correctness of the import statement and its compatibility with the existing code in the file during the insertion process.
[0098] By accurately identifying internationalized call code snippets and automatically completing dependency import statements, errors in internationalization functionality caused by missing dependency imports can be avoided, thus improving code runnability.
[0099] For example, this involves verifying reference errors, checking for missing internationalization references in an internationalized project, and fixing them. In a typical Vue project, vue-i18n is used as the internationalization framework. This framework uses the `t` method of `i18n` to display internationalized text, such as `i18n.t("minute")` which displays "minute". Since manual event tracking and automatic event tracking using third-party plugins cannot guarantee 100% import of the `i18n` object into the `.vue` or `.js` files, many `i18n` object errors will occur, causing the project to malfunction. The solution of this invention is to use a file reading API, such as Node.js's `FileReader`, to recursively read all `.vue` and `.js` files under the project's `src` directory. Regular expressions are used to search for JavaScript blocks within the files. If `i18n` is not imported in the detected content, a file writing API, such as Node.js's `FileWriter`, is used to insert `import i18n from '@ / i18n'` into the correct code position (using regular expressions to find the line containing the import statement), thus completing the fix.
[0100] In one embodiment, as shown in Figure 6, which is a flowchart illustrating a method for verifying reference errors provided in this embodiment, the method first traverses all files (.vue, .js, etc.) under the src directory of the project and reads the content of each file. For the vue file, regular expressions are used to match its... <script>标签内的js代码,对js文件则直接读取内容;之后判断这些js内容是否已引用国际化依赖,若未引用,则找出import引入区所在行数并加入依赖引入代码,如import i18n from ...,完成后流程结束。
[0101] 在一实施例中,如图7所示,图7为本公开实施例提供的又一种文件处理方法的流程示意图,首先执行校验key错乱,该过程可以由用户手动修复,接着执行校验行数错乱,该过程由工具自动修复,然后执行校验重复字段,该过程由工具自动去重,再执行校验无用字段,该过程可以由用户选择性删除,最后执行校验引用错误,该过程由工具自动修复。
[0102] 综上,本公开提供的方案:通过获取包含基准语言资源文件与目标语言资源文件的多种语言资源文件,先对两类文件的键进行一致性校验并得到差异键集合,可精准定位键结构的不一致问题,避免人工逐一比对键的繁琐;当差异键集合长度为零时,进一步识别两类文件中键不同但值相同的冗余键并完成去重,节省了人工重复维护多个同义键的操作;最后扫描源代码文件,结合去重后资源文件的键在代码中的引用情况确定无效键集合,为用户清理无用数据提供依据,避免了对无效键的无意义维护。通过以上一系列自动化的校验、去重与识别操作,替代了传统依赖人工的多语言资源文件维护模式,减少了人工操作的遗漏、误判与重复劳动,从而提升了多语言资源文件的维护效率。
[0103] 下面以一应用示例对本公开提供的文件处理方法做进一步说明:如图8所示,图8为本公开应用示例提供的一种文件处理方法的流程示意图。本公开应用示例提供的文件处理方法,包括以下步骤:步骤801,获取多种语言资源文件,多种语言资源文件包括基准语言资源文件和目标语言资源文件;步骤802,提取基准语言资源文件中的键与目标语言资源文件中的键,得到第一键集合和第二键集合;步骤803,根据第一键集合与第二键集合中不同的键,确定基准语言资源文件与目标语言资源文件的差异键集合,差异键集合用于提示用户修正基准语言资源文件和 / 或目标语言资源文件;步骤804,响应于差异键集合的长度为零,根据基准语言资源文件中键的顺序,调整目标语言资源文件中键的顺序,以使目标语言资源文件中键的顺序与基准语言资源文件中键的顺序相同;步骤805,响应于差异键集合的长度为零,从基准语言资源文件中筛选出值相同的键,得到至少一个候选键组,每个候选键组包括至少两个候选键;步骤806,在目标语言资源文件中查询同一候选键组中每个候选键对应的值;步骤807,响应于同一候选键组中每个候选键对应的值均相同,确定候选键组中候选键为在基准语言资源文件与目标语言资源文件中具有相同值的冗余键,并基于冗余键,对基准语言资源文件与目标语言资源文件进行去重处理;步骤808,扫描源代码文件,基于去重处理后的基准语言资源文件和 / 或目标语言资源文件中的键在源代码文件中的引用情况,确定第三键集合;步骤809,基于第一键集合和第三键集合,确定未被引用的无效键集合,无效键集合用于提示用户对去重处理后的基准语言资源文件和 / 或目标语言资源文件进行处理;步骤810,扫描源代码文件,识别调用国际化功能的代码片段;步骤811,响应于代码片段所在源代码文件中不包含国际化功能所需的依赖导入语句,在源代码文件的预设位置插入依赖导入语句。
[0104] 示例性的,使用NodeJs实现前述文件处理方法,封装成了js方法,编写了js脚本,在一个刚完成国际化中英文改造的项目中执行脚本进行尝试,全流程执行代码如图9所示,图9为本公开应用示例提供的又一种文件处理方法的流程示意图。
[0105] 1.按照前述文件处理流程,先校验key错乱问题,执行结果如图10所示,检测到19个key错乱问题,逐行输出并提示给用户,包含行号,key两列,用户需要在zh.json,en.json中手动进行修复;2.校验行数错乱,执行结果如图11所示,3.校验重复字段,执行结果如图12所示,4.校验无用字段执行结果如图13所示,5.校验引用错误执行结果如图14所示。
[0106] 为了实现本公开实施例提供的文件处理方法,本公开实施例还提供一种文件处理装置,如图15所示。图15为本公开实施例提供的一种文件处理装置的结构示意图,文件处理装置1500,包括:获取单元1501,用于获取多种语言资源文件,多种语言资源文件包括基准语言资源文件和目标语言资源文件;校验单元1502,用于对基准语言资源文件中的键与目标语言资源文件中的键进行一致性校验,得到基准语言资源文件与目标语言资源文件的差异键集合;处理单元1503,用于响应于差异键集合的长度为零,确定在基准语言资源文件与目标语言资源文件中具有相同值的冗余键,并基于冗余键,对基准语言资源文件与目标语言资源文件进行去重处理;确定单元1504,用于扫描源代码文件,基于去重处理后的基准语言资源文件和 / 或目标语言资源文件中的键在源代码文件中的引用情况,确定未被引用的无效键集合,无效键集合用于提示用户对去重处理后的基准语言资源文件和 / 或目标语言资源文件进行处理。
[0107] 在一实施例中,校验单元1502,具体用于:提取基准语言资源文件中的键与目标语言资源文件中的键,得到第一键集合和第二键集合;根据第一键集合与第二键集合中不同的键,确定基准语言资源文件与目标语言资源文件的差异键集合,差异键集合用于提示用户修正基准语言资源文件和 / 或目标语言资源文件。
[0108] 在一实施例中,文件处理装置1500还包括调整单元,调整单元用于:响应于差异键集合的长度为零,根据基准语言资源文件中键的顺序,调整目标语言资源文件中键的顺序,以使目标语言资源文件中键的顺序与基准语言资源文件中键的顺序相同。
[0109] 在一实施例中,处理单元1503,具体用于:响应于差异键集合的长度为零,从基准语言资源文件中筛选出值相同的键,得到至少一个候选键组,每个候选键组包括至少两个候选键;在目标语言资源文件中查询同一候选键组中每个候选键对应的值;响应于同一候选键组中每个候选键对应的值均相同,确定候选键组中候选键为在基准语言资源文件与目标语言资源文件中具有相同值的冗余键。
[0110] 在一实施例中,确定单元1504,具体用于:扫描源代码文件,基于去重处理后的基准语言资源文件和 / 或目标语言资源文件中的键在源代码文件中的引用情况,确定第三键集合;基于第一键集合和第三键集合,确定未被引用的无效键集合。
[0111] 在一实施例中,文件处理装置1500还包括插入单元,插入单元用于:扫描源代码文件,识别调用国际化功能的代码片段;响应于代码片段所在源代码文件中不包含国际化功能所需的依赖导入语句,在源代码文件的预设位置插入依赖导入语句。
[0112] 需要说明的是:上述实施例提供的文件处理装置在进行文件处理时,仅以上述各程序模块的划分进行举例说明,实际应用中,可以根据需要而将上述处理分配由不同的程序模块完成,即将文件处理装置的内部结构划分成不同的程序模块,以完成以上描述的全部或者部分处理。另外,上述实施例提供的文件处理装置与本公开实施例提供文件处理方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
[0113] 图16为本公开实施例提供的电子设备的硬件组成结构示意图,如图16所示,电子设备1600包括至少一个处理器1602;以及与至少一个处理器1602通信连接的存储器1601;其中,存储器1601存储有可被至少一个处理器1602执行的指令,指令被至少一个处理器1602执行,以实现本公开实施例的文件处理方法的步骤。
[0114] 可选地,该电子设备具体可为本申请实施例的文件处理装置,并且该电子设备可以实现本申请实施例的各个方法中由文件处理装置实现的相应流程,为了简洁,在此不再赘述。
[0115] 可理解,电子设备中还包括通信接口1603。电子设备中的各个组件通过总线系统1604耦合在一起。可理解,总线系统1604用于实现这些组件之间的连接通信。总线系统1604除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明起见,在图16中将各种总线都标为总线系统1604。
[0116] 可以理解,存储器1601可以是易失性存储器或非易失性存储器,也可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(ROM,Read OnlyMemory)、可编程只读存储器(PROM,Programmable Read-Only Memory)、可擦除可编程只读存储器(EPROM,Erasable Programmable Read-Only Memory)、电可擦除可编程只读存储器(EEPROM,Electrically Erasable Programmable Read-Only Memory)、磁性随机存取存储器(FRAM,ferromagnetic random access memory)、快闪存储器(Flash Memory)、磁表面存储器、光盘、或只读光盘(CD-ROM,Compact Disc Read-Only Memory);磁表面存储器可以是磁盘存储器或磁带存储器。易失性存储器可以是随机存取存储器(RAM,Random AccessMemory),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(SRAM,Static Random Access Memory)、同步静态随机存取存储器(SSRAM,Synchronous Static Random Access Memory)、动态随机存取存储器(DRAM,Dynamic Random Access Memory)、同步动态随机存取存储器(SDRAM,SynchronousDynamic Random Access Memory)、双倍数据速率同步动态随机存取存储器(DDRSDRAM,Double Data Rate Synchronous Dynamic Random Access Memory)、增强型同步动态随机存取存储器(ESDRAM,Enhanced Synchronous Dynamic Random Access Memory)、同步连接动态随机存取存储器(SLDRAM,SyncLink Dynamic Random Access Memory)、直接内存总线随机存取存储器(DRRAM,Direct Rambus Random Access Memory)。本发明实施例描述的存储器1601旨在包括但不限于这些和任意其它适合类型的存储器。
[0117] 上述本公开实施例揭示的方法可以应用于处理器1602中,或者由处理器1602实现。处理器1602可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器1602中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器1602可以是通用处理器、DSP,或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。处理器1602可以实现或者执行本发明实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者任何常规的处理器等。结合本发明实施例所公开的方法的步骤,可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于存储介质中,该存储介质位于存储器1601,处理器1602读取存储器1601中的信息,结合其硬件完成前述方法的步骤。
[0118] 在示例性实施例中,电子设备可以被一个或多个应用专用集成电路(ASIC,Application Specific Integrated Circuit)、DSP、可编程逻辑器件(PLD,ProgrammableLogic Device)、复杂可编程逻辑器件(CPLD,Complex Programmable Logic Device)、FPGA、通用处理器、控制器、MCU、微处理器(Microprocessor)、或其他电子元件实现,用于执行前述方法。
[0119] 本公开实施例还提供了一种存储有计算机指令的非瞬时计算机可读存储介质,计算机指令用于使计算机执行时实现本发明实施例的文件处理方法的步骤。
[0120] 可选的,该计算机可读存储介质可应用于本申请实施例中的文件处理装置,并且该计算机指令使得计算机执行本申请实施例的各个方法中由文件处理装置实现的相应流程,为了简洁,在此不再赘述。
[0121] 本公开实施例还提供了一种计算机程序产品,包括计算机程序,计算机程序在被处理器执行时实现本发明实施例提供的文件处理方法的步骤。
[0122] 在本申请所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。
[0123] 上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以是、或也可以不是物理单元,即可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。
[0124] 另外,在本发明各实施例中的各功能单元可以全部集成在一个处理单元中,也可以是各单元分别单独作为一个单元,也可以两个或两个以上单元集成在一个单元中;上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。
[0125] 本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
[0126] 或者,本发明上述集成的单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机、服务器、或者网络设备等)执行本发明各个实施例方法的全部或部分。而前述的存储介质包括:移动存储设备、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
[0127] 以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。< / script>
Claims
1. A file processing method, characterized in that, include: Acquire resource files in multiple languages, including base language resource files and target language resource files; The keys in the baseline language resource file and the keys in the target language resource file are checked for consistency to obtain the set of differences between the baseline language resource file and the target language resource file; In response to the fact that the length of the difference key set is zero, redundant keys with the same value in the base language resource file and the target language resource file are identified, and deduplication is performed on the base language resource file and the target language resource file based on the redundant keys; the source code file is scanned, and based on the reference status of the keys in the deduplicated base language resource file and / or the target language resource file in the source code file, a set of invalid keys that are not referenced is determined. The set of invalid keys is used to prompt the user to process the deduplicated base language resource file and / or the target language resource file.
2. The method according to claim 1, characterized in that, The step of verifying the consistency between the keys in the benchmark language resource file and the keys in the target language resource file to obtain a set of differences between the benchmark language resource file and the target language resource file includes: extracting the keys in the benchmark language resource file and the keys in the target language resource file to obtain a first set of keys and a second set of keys; determining the set of differences between the benchmark language resource file and the target language resource file based on the different keys in the first set of keys and the second set of keys, wherein the set of differences is used to prompt the user to correct the benchmark language resource file and / or the target language resource file.
3. The method according to claim 1, characterized in that, After performing a consistency check on the keys in the reference language resource file and the keys in the target language resource file to obtain a set of differing keys between the reference language resource file and the target language resource file, the method further includes: in response to the length of the differing key set being zero, adjusting the order of the keys in the target language resource file according to the order of the keys in the reference language resource file, so that the order of the keys in the target language resource file is the same as the order of the keys in the reference language resource file.
4. The method according to claim 1, characterized in that, The step of determining redundant keys with the same value in the reference language resource file and the target language resource file in response to the length of the difference key set being zero includes: filtering keys with the same value from the reference language resource file to obtain at least one candidate key group, each candidate key group including at least two candidate keys; querying the value corresponding to each candidate key in the same candidate key group in the target language resource file; and determining that the candidate keys in the candidate key group are redundant keys with the same value in the reference language resource file and the target language resource file in response to the fact that the values corresponding to each candidate key in the same candidate key group are all the same.
5. The method according to claim 2, characterized in that, The step of scanning the source code file, based on the reference information of keys in the deduplicated base language resource file and / or the target language resource file in the source code file, to determine the set of invalid keys that are not referenced, includes: scanning the source code file, determining a third key set based on the reference information of keys in the deduplicated base language resource file and / or the target language resource file in the source code file; and determining the set of invalid keys that are not referenced based on the first key set and the third key set.
6. The method according to claim 5, characterized in that, The method of scanning the source code file, after determining the reference status of keys in the deduplicated base language resource file and / or the target language resource file in the source code file, and identifying invalid keys that are not referenced, further includes: scanning the source code file to identify code snippets that call internationalization functions; and inserting the dependency import statements at a preset position in the source code file in response to the fact that the source code file containing the code snippets does not contain dependency import statements required for internationalization functions.
7. A document processing device, characterized in that, include: The acquisition unit is used to acquire multiple language resource files, including a base language resource file and a target language resource file. A verification unit is used to perform consistency verification on the keys in the reference language resource file and the keys in the target language resource file to obtain a set of differences between the reference language resource file and the target language resource file; a processing unit is used to determine redundant keys with the same value in the reference language resource file and the target language resource file in response to the length of the set of differences being zero, and to perform deduplication processing on the reference language resource file and the target language resource file based on the redundant keys; The determining unit is used to scan the source code file and, based on the reference status of keys in the deduplicated base language resource file and / or the target language resource file in the source code file, determine a set of invalid keys that are not referenced. The set of invalid keys is used to prompt the user to process the deduplicated base language resource file and / or the target language resource file.
8. An electronic device, characterized in that, include: At least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 6.
10. A computer program product comprising a computer program that, when executed by a processor, implements the method of any one of claims 1 to 6.