Multi-language file processing method and device and electronic equipment
Through automated multilingual file processing methods, invalid and duplicate keys in multilingual files are identified and optimized, solving the problems of lexicon redundancy and maintenance complexity, and improving the quality and maintainability of multilingual files.
Patent Information
- Application Number
- CN202410814557.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-06-21
AI Technical Summary
In front-end multilingual development, multilingual vocabulary databases lead to redundancy and duplication due to the accumulation of no longer used words, which increases maintenance complexity and resource consumption. The existing technology relies on manual operations, is inefficient and error-prone, and is difficult to adapt to rapidly changing Multilingual requirements.
Provides a multi-language file processing method that obtains multi-language files to be optimized from the file information queue, defines initialization parameters, traverses the file information queue to perform multi-language matching, identifies and hides or removes invalid keys and duplicate keys, and generates optimization The final multi-language file is adapted to the Node.js environment.
Automatically identify and process valid keys, invalid keys and duplicate keys in multi-language files, systematically clean up the lexicon, reduce unnecessary data burden, improve the quality and maintainability of the lexicon, and increase the readability of optimized files.
Smart Images

Figure CN118708557A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of multi-language document processing, and in particular to a multi-language document processing method, device and electronic equipment. Background Art
[0002] With the acceleration of globalization, the demand for website internationalization and localization is growing, and front-end multilingual technology has emerged. This technology allows developers to use multiple languages in front-end development, realize dynamic display and interaction of web page content in different language environments, and thus meet the needs of users of various languages.
[0003] However, in the practice of front-end multilingual development, as time goes by and the project is iterated, the multilingual vocabulary often accumulates a large number of no longer used vocabulary entries. If these no longer used words are not cleaned up in time, it will lead to redundancy and duplication of the vocabulary, further increasing the complexity of maintenance and resource consumption. In the related art, the vocabulary management of multilingual files still relies on manual operations by developers, which is not only inefficient, but also prone to errors and difficult to adapt to the rapidly changing multilingual needs. Therefore, there is an urgent need for a processing method that can automatically optimize multilingual files. Summary of the invention
[0004] The embodiments of the present disclosure provide a multi-language file processing method, device and electronic device, aiming to solve the problems existing in the above-mentioned background technology.
[0005] In order to solve the above technical problems, the present disclosure is implemented as follows:
[0006] In a first aspect, an embodiment of the present disclosure provides a multi-language file processing method, the method comprising:
[0007] Acquire file information of a first multilingual file to be optimized from a file information queue, wherein the file information queue records file information of all multilingual files in the front-end project;
[0008] defining initialization parameters according to the file information of the first multi-language file;
[0009] Traversing the file information queue, performing multi-language matching based on the initialization parameters, determining valid keys, invalid keys, and duplicate keys in the first multi-language file, and collecting template information of the valid keys, wherein the valid key is a key referenced at least once in multiple multi-language files, the invalid key is a key not referenced in any multi-language file, and the duplicate key is a key that is repeated in the first multi-language file and has exactly the same value;
[0010] Based on the first multi-language file, the key-value pairs corresponding to the invalid key and the duplicate key are hidden and / or removed, and an optimized second multi-language file is generated according to the template information of the valid key.
[0011] Optionally, before acquiring the file information of the first multilingual file to be optimized from the file information queue, the method further includes:
[0012] Import the file processing package and file path processing package of Node.js;
[0013] Using the file path processing package, define the top-level multi-language folder location of the front-end project;
[0014] Determine a reading path according to the location of the top-level multi-language folder;
[0015] Obtain file information of the first multi-language file to be optimized from the file information queue, including:
[0016] According to the reading path, the file processing package is used to recursively read and collect all file information under the reading path, where all file information under the reading path includes file information of the first multi-language file.
[0017] Optionally, the recursive reading and collecting of all file information under the reading path includes:
[0018] Determine the type of the object currently read according to the currently read file information, where the object type includes the file type and the folder type;
[0019] When the object type is a file type, the currently read file information is saved in the form of an array to the file information queue;
[0020] When the object type is a folder, the recursive reading is continued according to the reading path until the object types indicated by all the read file information are file types.
[0021] Optionally, the initialization parameters include: a multi-language key, a multi-language value, and a key reference count;
[0022] Defining initialization parameters according to the file information of the first multi-language file includes:
[0023] Determining, according to the file information of the first multi-language file, the key and value of each key-value pair in the first multi-language file;
[0024] For each key-value pair in the first multi-language file, a one-to-one corresponding initialization parameter is defined, wherein the multi-language key of the initialization parameter is defined as the key of the key-value pair, the multi-language value of the initialization parameter is defined as the value of the key-value pair, and the number of key references of the initialization parameter is set to an initial value of 0.
[0025] Optionally, traversing the file information queue and performing multi-language matching based on the initialization parameters includes:
[0026] Taking one of the multiple languages as the main body, cyclically reading initialization parameters of each key-value pair in the first multiple language file;
[0027] Looping through the file information queue, and performing multi-language matching between the file information in the file information queue and the multi-language key defined in the initialization parameters;
[0028] Whenever file information successfully matches a defined multilingual key, the number of key references corresponding to the currently matched multilingual key is increased by 1, and template information of the key corresponding to the successfully matched multilingual key is collected, wherein the template information includes the multilingual key, multilingual value, key reference number, key reference position and key version.
[0029] Optionally, based on the first multi-language file, the key-value pairs corresponding to the invalid key and the duplicate key are hidden and / or removed, and an optimized second multi-language file is generated according to the template information of the valid key, including:
[0030] Create a new JSON object based on the first multilingual file;
[0031] Hide and / or remove the key-value pairs corresponding to invalid keys and duplicate keys in the content set to be deleted from the new JSON object;
[0032] Integrate the template information corresponding to all valid keys in the temporary content set into a new JSON object;
[0033] Using a file path processing package, defining a generation location of the optimized second multi-language file;
[0034] The new JSON object is saved as an optimized second multi-language file using a file processing package, the first multi-language file and the second multi-language file have the same file name, and the second multi-language file is generated in the file location indicated by the generation location.
[0035] Optionally, the method further comprises:
[0036] The file processing package is used to adjust the method of importing and exporting the first multi-language file, so that the method of importing and exporting the first multi-language file is adapted to the operating environment of Node.js.
[0037] In a second aspect, an embodiment of the present disclosure provides a multi-language file processing device, the device comprising:
[0038] An acquisition module, used for acquiring file information of a first multilingual file to be optimized from a file information queue, wherein the file information queue records file information of all multilingual files in the front-end project;
[0039] A definition module, used to define initialization parameters according to the file information of the first multi-language file;
[0040] a traversal module, configured to traverse the file information queue, perform multi-language matching based on the initialization parameters, determine valid keys, invalid keys, and duplicate keys in the first multi-language file, and collect template information of the valid keys, wherein the valid keys are keys referenced at least once in multiple multi-language files, the invalid keys are keys not referenced in any multi-language file, and the duplicate keys are keys that are repeated in the first multi-language file and have exactly the same value;
[0041] A generating module is used to hide and / or remove the key-value pairs corresponding to the invalid keys and the duplicate keys based on the first multi-language file, and generate an optimized second multi-language file according to the template information of the valid keys.
[0042] Optionally, the device further comprises:
[0043] Import module, used to import Node.js file processing package and file path processing package;
[0044] A top-level location definition module, used to define the top-level multi-language folder location of the front-end project using the file path processing package;
[0045] A reading path determination module, used to determine a reading path according to the location of the top-level multi-language folder;
[0046] Optionally, the acquisition module includes:
[0047] The recursive reading submodule is used to recursively read and collect all file information under the reading path using the file processing package according to the reading path, wherein all file information under the reading path includes file information of the first multi-language file.
[0048] Optionally, the recursive reading submodule includes:
[0049] A judging unit, used to judge the type of the object currently read according to the file information currently read, wherein the object type includes a file type and a folder type;
[0050] A saving unit, used for saving the currently read file information in the form of an array to the file information queue when the object type is a file type;
[0051] The recursive reading unit is used to, when the object type is a folder, continue to recursively read according to the reading path until the object types indicated by all the read file information are file types.
[0052] Optionally, the initialization parameters include: a multi-language key, a multi-language value, and a key reference count;
[0053] The definition module includes:
[0054] a key-value determination submodule, configured to determine the key and value of each key-value pair in the first multi-language file according to the file information of the first multi-language file;
[0055] The initialization parameter definition submodule is used to define a one-to-one corresponding initialization parameter for each key-value pair in the first multi-language file, wherein the multi-language key of the initialization parameter is defined as the key of the key-value pair, the multi-language value of the initialization parameter is defined as the value of the key-value pair, and the number of key references of the initialization parameter is set to an initial value of 0.
[0056] Optionally, the traversal module includes:
[0057] A loop reading submodule, used for loop reading initialization parameters of each key-value pair in the first multi-language file based on one of the multi-languages;
[0058] A loop traversal submodule, used for looping through the file information queue, and performing multi-language matching between the file information in the file information queue and the multi-language key defined in the initialization parameter;
[0059] The multi-language matching sub-module is used to increase the number of key references corresponding to the currently matched multi-language key by 1 whenever file information successfully matches a defined multi-language key, and collect template information of the key corresponding to the successfully matched multi-language key, wherein the template information includes the multi-language key, multi-language value, key reference number, key reference position and key version.
[0060] Optionally, the traversal module includes:
[0061] A first checking submodule, configured to check the number of key references of all key-value pairs in the first multi-language file;
[0062] A first marking submodule is used for marking, for any key-value pair in the first multi-language file, a key of the key-value pair as a valid key when the number of key references is greater than 0, collecting template information of the valid key, and adding the collected template information of the valid key to a temporary content set;
[0063] a second marking submodule, configured to check whether the key of the key-value pair is in a whitelist when the number of key references is less than 0; if the key of the key-value pair is in the whitelist, mark the key of the key-value pair as a valid key, collect template information of the valid key, and add the collected template information of the valid key to a temporary content set, wherein the whitelist is a list defining multilingual keys that need to be protected; if the key of the key-value pair is not in the whitelist, mark the key of the key-value pair as an invalid key, and add the invalid key to a set of content to be deleted;
[0064] A second checking submodule is used to traverse all key-value pairs of the first multilingual file to check whether there are duplicate keys in multiple key-value pairs;
[0065] The third marking submodule is used for marking the key as a duplicate key if there are multiple key-value pairs with duplicate keys and the same value, and adding the duplicate key to the set of content to be deleted.
[0066] Optionally, the generating module includes:
[0067] Creating a submodule for creating a new JSON object based on the first multi-language file;
[0068] The remove submodule is used to hide and / or remove the key-value pairs corresponding to invalid keys and duplicate keys in the content set to be deleted from the new JSON object;
[0069] The integration submodule is used to integrate the template information corresponding to all valid keys in the temporary content set into a new JSON object;
[0070] A generation location definition submodule, used to define the generation location of the optimized second multi-language file by using a file path processing package;
[0071] The generating submodule is used to save the new JSON object as an optimized second multi-language file by using a file processing package, wherein the first multi-language file and the second multi-language file have the same file name, and the second multi-language file is generated in a file location indicated by the generating location.
[0072] Optionally, the device further comprises:
[0073] The adjustment module is used to use the file processing package to adjust the import and export method of the first multi-language file so that the import and export method of the first multi-language file is adapted to the operating environment of Node.js.
[0074] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the steps of a multi-language file processing method when executed by the processor.
[0075] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0076] The present disclosure automatically identifies and processes valid keys, invalid keys and duplicate keys in multilingual files through multilingual matching, systematically cleans and optimizes the word library, and reduces unnecessary data burden. Overall, the present disclosure not only reduces the invalid accumulation of words in the later multilingual word library, improves the overall quality and maintainability of the word library, but also increases the readability of the optimized multilingual file through annotated template information. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0078] Figure 1 It is a schematic diagram of the steps of a multi-language file processing method provided by an embodiment of the present disclosure;
[0079] Figure 2 is a flowchart of a recursive reading process provided by an embodiment of the present disclosure;
[0080] Figure 3 is a flowchart of a multi-language matching process provided by an embodiment of the present disclosure;
[0081] Figure 4 is a flowchart of generating a second multi-language file provided by an embodiment of the present disclosure;
[0082] Figure 5 The present invention is a block diagram of a multi-language document processing device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0083] The following will be combined with the drawings in the embodiments of the present disclosure to clearly and completely describe the technical solutions in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0084] When developing websites or applications that need to support multiple languages, a large number of multilingual files are usually involved. Using the method provided in the embodiment of the present disclosure, these multilingual files can be effectively managed, redundancy, duplication, and invalid key values can be reduced, and each multilingual file can be ensured to be optimal. In addition, for cross-language platforms based on multilingual front-end projects such as multilingual e-commerce platforms and education platforms, in actual development, the present disclosure has the technical effect of significantly optimizing multilingual files, reducing redundancy and invalid information, and improving the overall quality of multilingual files, bringing a smoother and more efficient experience to developers and project users.
[0085] Multilingual files are files used to store text content in different language versions during the internationalization (i18n) of software or websites. They usually store text in the form of key-value pairs, where the key is a unique identifier and the value is the corresponding text content. The main function of multilingual files is to provide localized interface text for users of different languages, so that software or websites can support multiple languages. By loading files in different languages, the interface language can be switched dynamically without modifying the code. Multilingual files usually use JSON, YAML, XML and other formats to store text content. Each file corresponds to a language, and the text content is recorded in the form of key-value pairs inside the file. For the key-value pairs in multilingual files, the key is a unique identifier used to reference the text content in the code. The value is the specific text content, which is the translated text of one of the multiple languages. For example, for an English file (en.json): "hello": "Hello", "welcome": "Welcome"; and for a Spanish file (es.json): "hello": "Hola", "welcome": "Bienvenido". In actual application, when the user selects English, the program will load the en.json file and use the text content therein to display the interface; when the user selects Spanish, the program will load the es.json file and use the text content therein to display the interface. It should be noted that the "key-value pairs" described in the embodiments of the present disclosure are uniformly identified as multilingual key-value pairs in multilingual files to avoid ambiguity and understanding conflicts with other forms of key-value pairs.
[0086] Figure 1 FIG. 1 is a schematic diagram of the steps of a multilingual file processing method provided by an embodiment of the present disclosure. Figure 1 As shown, the method includes:
[0087] Step S101, obtaining file information of a first multilingual file to be optimized from a file information queue, wherein the file information queue records file information of all multilingual files in a front-end project;
[0088] Step S102, defining initialization parameters according to the file information of the first multi-language file;
[0089] Step S103, traversing the file information queue, performing multi-language matching based on the initialization parameters, determining valid keys, invalid keys, and duplicate keys in the first multi-language file, and collecting template information of the valid keys, wherein the valid key is a key referenced at least once in multiple multi-language files, the invalid key is a key not referenced in any multi-language file, and the duplicate key is a key that is repeated in the first multi-language file and has exactly the same value;
[0090] Step S104: based on the first multi-language file, hiding and / or removing the key-value pairs corresponding to the invalid key and the repeated key, and generating an optimized second multi-language file according to the template information of the valid key.
[0091] In step S101, the file information queue is a structure that records the detailed information of all multilingual files in the front-end project, providing a comprehensive file information basis for subsequent multilingual file optimization. In the disclosed embodiment, the file information is stored in the file information queue in the form of arrays and linked lists. The first multilingual file is the multilingual file to be optimized selected from the file information queue, which is the starting point of the optimization process. Its key-value pairs will be checked one by one to determine the validity, and subsequent optimization processing will be performed.
[0092] Involving step S102, the file information of the first multilingual file includes information of all key-value pairs of the first multilingual file, including the key and value of each key-value pair. According to the file information of the first multilingual file, the information of all key-value pairs of the first multilingual file is determined, and according to the information of each key-value pair, the corresponding initialization parameters are defined. In the embodiment of the present disclosure, the initialization parameters include the multilingual key langKey, the multilingual value langValue and the key reference count times. The initialization parameters are used to identify and process the key values in the first multilingual file during the multilingual matching process. The purpose of defining the initialization parameters is to facilitate the subsequent multilingual matching steps to accurately identify and process the key values in the first multilingual file. This will be explained later and will not be described in detail here.
[0093] Involving step S103, for each key-value pair in the first multilingual file, its initialization parameters are obtained. In the process of traversing the file information queue, a multilingual matching operation is performed. Specifically, the file information of each multilingual file in the file information queue is matched with the multilingual keys defined in the initialization parameters. In the process of multilingual matching, the valid keys, invalid keys and duplicate keys in the first multilingual file are determined. A valid key is a key that has been referenced in at least one multilingual file in the file information queue. Its key reference count is greater than 0. An invalid key is a key that has not been referenced in any multilingual file, its key reference count is 0, and it is not protected. A duplicate key is a key that is repeated in the first multilingual file and has exactly the same value. For a multilingual key determined to be a valid key, its template information is collected, including the multilingual key, multilingual value, key reference count, key reference position and key version, etc.
[0094] Assume there is a multi-language file (for example: en.json) and the following key-value pairs:
[0095] "welcome_message":"Welcome",
[0096] "logout":"Logout",
[0097] "login":"Login",
[0098] "login":"Login",
[0099] "unused_key":"Thisisnotused".
[0100] In addition, there are file information of multiple other multi-language files in the file information queue (for example: fr.json, de.json, etc.). For the multi-language file fr.json, the key-value pair content is as follows:
[0101] "welcome_message":"Bienvenue",
[0102] "logout":"Déconnexion",
[0103] "login":"Connexion"
[0104] For the multi-language file de.json, the key-value pairs are as follows:
[0105] "welcome_message":"Willkommen",
[0106] "logout":"Abmelden",
[0107] "login":"Anmelden", from the above example, we can conclude that welcome_message, logout, and login are referenced in en.json, fr.json, and de.json, so they are valid keys. unused_key exists in en.json, but is not referenced in any other multilingual files, so it is an invalid key. login appears twice in en.json with the same value, so it is both a valid key and a duplicate key.
[0108] In step S104, after the multi-language matching is completed, the valid keys, invalid keys and duplicate keys of the first multi-language have been determined. First, the key-value pairs corresponding to the invalid keys and duplicate keys need to be removed (for example, by commenting out the template information). The key-value pairs of the invalid keys are removed from the original first multi-language file, or they are hidden, and the key-value pairs of the duplicate keys are deleted and / or hidden, and only one instance is retained to make it the only valid key-value pair. Continuing with the example in step S103, the first multi-language file to be optimized:
[0109] "welcome_message":"Welcome",
[0110] "logout":"Logout",
[0111] "login":"Login"
[0112] "login":"Login",
[0113] "unused_key":"Thisisnotused", it has been determined that welcome_message and logout are valid keys, unused_key is an invalid key, login is both a valid key and a duplicate key. After the processing of step S104, the optimized second multilingual file is generated according to the collected template information of the valid keys:
[0114] "welcome_message":"Welcome" / / Template information corresponding to welcome_message;
[0115] "logout":"Logout" / / Template information corresponding to logout;
[0116] "login":"Login" / / Template information corresponding to login. In the disclosed embodiment, the display of valid keys and the hiding and / or removal of invalid keys and redundant keys can also be implemented based on annotated template information. Optionally, the template information can be at least one of the following: multilingual keys, multilingual values, key reference times, duplicate keys, invalid keys, key reference positions, and key versions. Template information can be customized according to the needs of developers and development environments. In the above example, the valid keys "welcome_message", "logout", and "login" should annotate the defined template information, and the key-value pairs are followed by annotation information such as key reference times, key reference positions, and key versions. The template information of the invalid key "unused_key" can include an annotation of "invalid key". In the process, it is convenient to hide the key-value pairs of invalid keys according to the "invalid key" annotation, and the same applies to the processing of redundant keys. In this way, the generated second multilingual file conveys its validity and reference information to the developer more intuitively, which not only reduces the redundant information of the file, but also improves the maintainability and readability of the file.
[0117] The present disclosure automatically identifies and processes valid keys, invalid keys and duplicate keys in multilingual files through multilingual matching, systematically cleans and optimizes the word library, and reduces unnecessary data burden. Overall, the present disclosure not only reduces the invalid accumulation of words in the later multilingual word library, improves the overall quality and maintainability of the word library, but also increases the readability of the optimized multilingual file through annotated template information.
[0118] Exemplarily, before obtaining the file information of the first multilingual file to be optimized from the file information queue, the method further includes: importing a file processing package and a file path processing package of Node.js; using the file path processing package to define the top-level multilingual folder location of the front-end project; and determining a reading path according to the top-level multilingual folder location.
[0119] In Node.js, it comes with fs (file processing package) and path (file path processing package), which provide basic functions for processing files and paths. The file processing package is used to read, write, delete and operate files, and the file path processing package is used to process and convert file paths. Assuming that the multi-language folder of the front-end project is located in the locales folder under the project root directory, you can use the file path processing package to define this location:
[0120] constprojectRoot=__dirname;
[0121] constlocalesFolderPath = path.join(projectRoot,'locales'); Here, __dirname is a global variable in Node.js, which indicates the directory where the current script is located. The path.join() method connects the project root directory and the locales folder name to form the absolute path of the multi-language folder. Next, it is necessary to read all the file information under the locales folder, that is, according to the location of the top-level multi-language folder locales, determine the reading path, and prepare to recursively read the contents of these folders.
[0122] Exemplarily, obtaining file information of a first multilingual file to be optimized from a file information queue includes: according to the reading path, using the file processing package, recursively reading and collecting all file information under the reading path, wherein all file information under the reading path includes file information of the first multilingual file.
[0123] After determining the reading path, the file processing package is used to traverse the directory of the top-level multilingual file and its subdirectories according to the reading path to collect information of all multilingual files, including the file information of the first multilingual file. Optionally, it is implemented by a recursive function, which traverses all multilingual files and folders under the specified path and saves the information of each multilingual file into an array to provide basic data for subsequent multilingual file optimization.
[0124] Exemplarily, the recursive reading and collection of all file information under the reading path includes: judging the type of the object currently being read based on the file information currently being read, the object types including file types and folder types; when the object type is a file type, saving the file information currently being read in the form of an array to the file information queue; when the object type is a folder, continuing to recursively read along the reading path until the object types indicated by all the read file information are file types.
[0125] Figure 2 is a flowchart of a recursive reading process provided by an embodiment of the present disclosure, such as Figure 2As shown, in the process of processing multilingual files, according to the determined, input reading path, the files and / or folders under the path are recursively read. In the reading process, it is necessary to determine whether the currently read object is a file or a folder, because the processing methods of files and folders are different. Files need to directly process their contents, while folders need to further read the files inside them. The disclosed embodiment relies on the object type of files and / or folders to indicate, which is equivalent to one of the attribute information of the read file information. The object type includes two types: files and folders. When it is determined that the currently read object is a file, the file information of the file needs to be recorded, and the recorded file information will be saved in the file information queue in the form of an array. When it is determined that the currently read object is a folder, it is necessary to further read the contents inside the folder. This is a recursive process, which means that the reading process will go deep into each subfolder layer by layer until all subitems are processed. If a subitem is a folder again, then the folder will be entered again, the current folder and path information will be sorted into a new path, and the contents inside it will continue to be read. The recursive call will repeat the above steps until the object types indicated by all the read file information are file types. Through recursive reading, it is possible to go deep into each subfolder, ensuring that no matter how complex the file structure is, as long as the reading path is determined, the file information of all files under the path can be completely collected, laying a solid foundation for subsequent multilingual file processing.
[0126] Exemplarily, the initialization parameters include: a multilingual key, a multilingual value, and a key reference count; defining the initialization parameters according to the file information of the first multilingual file includes: determining the key and value of each key-value pair in the first multilingual file according to the file information of the first multilingual file; defining a one-to-one corresponding initialization parameter for each key-value pair in the first multilingual file, wherein the multilingual key of the initialization parameter is defined as the key of the key-value pair, the multilingual value of the initialization parameter is defined as the value of the key-value pair, and the key reference count of the initialization parameter is set to an initial value of 0.
[0127] The following is an explanation of each parameter of the initialization parameter. The multi-language key (lankey) corresponds to the key of each key-value pair in the multi-language file, that is, the placeholder string when using multiple languages, which is used to identify different language texts. The multi-language value (lanvalue) corresponds to the value of each key-value pair in the multi-language file, which is the text content in different languages. The key reference count (times) represents the number of times each key is referenced in all other multi-language files. It is initially set to 0 and will be dynamically updated in the subsequent multi-language matching process.
[0128] Defining initialization parameters is to conduct preliminary analysis and setting of the content of multilingual files, laying the foundation for subsequent multilingual matching. The following are detailed steps. First, obtain the file information of the first multilingual file to be optimized, including the information of all key-value pairs of the first multilingual file. Read the file information content of the first multilingual file and parse each key-value pair therein. As mentioned above, each key-value pair consists of a unique key and a corresponding value. For each parsed key-value pair, define the corresponding initialization parameters, such as the key-value pair "welcome_message": "Welcome", and set the multilingual key of the initialization parameter to the key in the key-value pair. For example, "welcome_message". Set the multilingual value of the initialization parameter to the value in the key-value pair. For example, "Welcome". Set the number of key references of the initialization parameter to the initial value 0. This is because in the initial stage, multilingual matching has not been performed, so the number of references is 0.
[0129] Exemplarily, traversing the file information queue and performing multi-language matching based on the initialization parameters include: taking one of the multi-languages as the main body, cyclically reading the initialization parameters of each key-value pair in the first multi-language file; cyclically traversing the file information queue, and performing multi-language matching on the file information in the file information queue and the multi-language keys defined in the initialization parameters; whenever file information successfully matches the defined multi-language key, adding 1 to the number of key references corresponding to the currently matched multi-language key, and collecting template information of the key corresponding to the successfully matched multi-language key, wherein the template information includes the multi-language key, the multi-language value, the number of key references, the key reference position and the key version.
[0130] In order to optimize and manage key-value pairs, a language is selected from the multilingual file as the main language. For example, if a multilingual file containing English, French, and German is processed, English can be selected as the main language. For the multilingual file of the main language, each key-value pair and its initialization parameters are read one by one: multilingual key, multilingual value, and key reference count (initialized to 0). For example, when English is selected as the main language, for the key-value pair {"welcome_message":"Welcome"}, the initialization parameters include: multilingual key: welcome_message; multilingual value: Welcome; key reference count: 0. After completing the initialization parameter reading of the main language file, the next step is to match these parameters with other file information in the file information queue. For each file information, loop through the file information queue to determine. For each file information in the file information queue, check whether its content contains the multilingual key defined in the initialization parameter. If a key in the file information matches the multilingual key in the initialization parameter, it means that the multilingual file corresponding to the file information references a key of one of the key-value pairs in the first multilingual file, and then increase the key reference count corresponding to the currently matched multilingual key by 1. In this way, the number of times the key is referenced in all files can be counted, and the relevant template information of the successfully matched multilingual keys can be collected. The template information corresponding to a multilingual key should include: multilingual key, multilingual value, key reference count, that is, the current reference count, key reference position, the location of the multilingual file that references the key, key version, key version information or identification, and developers can also customize the template information according to actual development needs to generate a second multilingual file with good readability, which is not limited by the present disclosure.
[0131] For example, the file information queue contains the following multilingual files (represented in simplified form):
[0132] File A (English): {"welcome_message":"Welcome","logout_message":"Goodbye"};
[0133] File B (French): {"welcome_message":"Bienvenue","logout_message":"Aurevoir"};
[0134] File C (German): {"welcome_message":"Willkommen","login_prompt":"BittegebenSieIhreZugangsdatenein"}. For another example, the initialization parameters defined for the file information of the first multi-language file are: multi-language key: welcome_message; multi-language value: Welcome; key reference count: 0. The file information queue is traversed in a loop to perform multi-language matching.
[0135] In file A, welcome_message is matched, the key reference count is increased by 1, and the template information is updated to: multi-language key: welcome_message; multi-language value: Welcome; key reference count: 1; key reference position: file A; key version: N / A (record the version information if there is one).
[0136] In file B, welcome_message is matched, the key reference count increases by 1, and the template information is updated to: multi-language key: welcome_message; multi-language value: Bienvenue; key reference count: 2; key reference location: file B; key version: N / A.
[0137] In file C, welcome_message is matched, the key reference count is increased by 1, and the template information is updated to: multi-language key: welcome_message; multi-language value: Willkommen; key reference count: 3; key reference location: file C; key version: N / A. After the above multi-language matching, the reference count of each multi-language key can be effectively counted and managed, and its detailed template information can be collected. This information will be used for subsequent optimization processing, such as hiding and removing the key-value pairs corresponding to invalid keys and duplicate keys, and generating optimized multi-language files.
[0138] Exemplarily, the determining of valid keys, invalid keys, and duplicate keys in the first multi-language file, and collecting template information of the valid keys, includes: checking the number of key references of all key-value pairs in the first multi-language file; for any key-value pair in the first multi-language file, if the number of key references is greater than 0, marking the key of the key-value pair as a valid key, collecting template information of the valid key, and adding the collected template information of the valid key to the temporary content set; if the number of key references is less than 0, checking whether the key of the key-value pair is in the whitelist, and if the key of the key-value pair is in the whitelist, In the whitelist, the key of the key-value pair is marked as a valid key, and the template information of the valid key is collected, and the collected template information of the valid key is added to the temporary content set, wherein the whitelist is a list of multilingual keys that need to be protected; if the key of the key-value pair is not in the whitelist, the key of the key-value pair is marked as an invalid key, and the invalid key is added to the content set to be deleted; all key-value pairs of the first multilingual file are traversed to check whether there are repeated keys of multiple key-value pairs; if there are repeated keys of multiple key-value pairs and the values are the same, the key is marked as a duplicate key, and the duplicate key is added to the content set to be deleted.
[0139] Figure 3 is a flowchart of a multi-language matching process provided by an embodiment of the present disclosure, such as Figure 3As shown, after the definition of the initialization parameters is performed according to the file information of the first multilingual file, the file information of all multilingual files that need to be matched in multilingual is recursively read, the file information queue is read cyclically, and multilingual matching is performed on each file information based on the initialization parameters. During the matching, the template information of the successfully matched multilingual key is collected, and the key reference count corresponding to the successfully matched multilingual key is updated to increase by one until all the information in the file information queue is read. After reading all the information in the file information queue, all key-value pairs in the first multilingual file are checked, with the focus on the number of references of each key. If the number of references of a multilingual key is greater than 0, it means that the key has been referenced in at least one file, and then the key is marked as a valid key. For each key marked as valid, its template information is collected and added to the temporary content set. For those keys with a reference count equal to 0, first check whether these keys are in the whitelist. The whitelist is a predefined list containing multilingual keys that need to be protected. If the key is in the whitelist, even if the reference count is equal to 0, the key is still marked as a valid key, and its template information is collected and added to the temporary content set. If the key is not in the whitelist, it is marked as an invalid key and added to the set of content to be deleted. The purpose of the whitelist is to ensure that certain critical keys are not deleted by mistake even if they are not referenced temporarily. For example, a specific error message key may not be used temporarily, but due to its importance, it still needs to be retained. Finally, all key-value pairs of the first multilingual file are traversed to check whether there are duplicate keys. If there are multiple keys with duplicate names and the corresponding values are exactly the same in the first multilingual file, these keys are marked as duplicate keys and added to the set of content to be deleted so that they can be removed in the subsequent optimization process.
[0140] Through the multi-language matching method provided by the embodiment of the present disclosure, valid keys, invalid keys and duplicate keys in a multi-language file can be effectively determined. Valid keys retain and collect detailed template information to ensure their correct reference and use in multi-language files, and invalid keys and duplicate keys are marked and subsequently removed, thereby optimizing the structure and content of multi-language files and improving their maintainability and readability.
[0141] Exemplarily, based on the first multi-language file, hiding and / or removing the key-value pairs corresponding to the invalid keys and the duplicate keys, and generating an optimized second multi-language file according to the template information of the valid keys, includes: creating a new JSON object based on the first multi-language file; hiding and / or removing the key-value pairs corresponding to the invalid keys and the duplicate keys in the to-be-deleted content set from the new JSON object; integrating the template information corresponding to all the valid keys in the temporary content set into the new JSON object; defining a generation location of the optimized second multi-language file by using a file path processing package; and saving the new JSON object as an optimized second multi-language file by using a file processing package, wherein the first multi-language file and the second multi-language file have the same file name, and the second multi-language file is generated in a file location indicated by the generation location.
[0142] Figure 4 This is a flowchart of the second multi-language file generation process provided by an embodiment of the present disclosure. Please refer to Figure 4, taking a multi-language as the subject, looping and reading the file information of the first multi-language file, including looping and reading all the key-value pairs of the first multi-language file, during which the template information of the valid keys in the first multi-language file is obtained according to the multi-language matching process and method described above, and the key reference count of the valid keys is dynamically updated accordingly by adding 1. After reading all the key-value pairs of the first multi-language file, first, a new JSON object is created according to the first multi-language file, which will serve as the basis for the optimized multi-language file. This is an empty JSON structure, ready to carry the optimized key-value pairs. In the new JSON object, invalid keys and duplicate keys need to be processed. Invalid keys and duplicate keys have been identified and collected before, and these key-value pairs need to be hidden and / or removed from the new JSON object. If you choose to hide these key-value pairs, you can mark them as "invalid keys" or "duplicate keys" and comment them out so that they can be restored when needed. If you choose to remove, these key-value pairs are completely deleted so that they no longer occupy file space. Then, the template information of all valid keys in the temporary content set is integrated into the new JSON object. As mentioned above, the template information of the valid keys has been collected before, including the multilingual keys, the corresponding values, the number of references, the reference locations and the versions, etc. These valid keys and their related information are added to the new JSON object one by one to ensure that each valid key has complete template information. Using the file path processing package, define the generation location of the optimized second multilingual file, optionally including defining the top-level directory of the project or the specified multilingual folder to determine the specific location where the new JSON object (i.e., the optimized file) will be saved. Use the file processing package to write the new JSON object to the file system. The optimized second multilingual file has the same file name as the first multilingual file so as to replace the old file or keep the consistency of the file name. The newly generated second multilingual file will be saved to the previously defined generation location.
[0143] Exemplarily, the method further includes: using the file processing package to adjust the way of importing and exporting the first multi-language file, so that the way of importing and exporting the first multi-language file is adapted to the operating environment of Node.js.
[0144] In the disclosed embodiment, the first multi-language file import method refers to how to read and load the multi-language file so that its content can be used for multi-language processing of the program. The first multi-language file export method refers to how to export the multi-language file to save or update the multi-language file.
[0145] For the adjustment of import mode, use the file processing package to read multi-language files. The reading operation should adapt to the asynchronous programming model of Node.js. Optionally, use callback functions, Promise, or async / await for asynchronous processing. Ensure that the file path is correctly parsed in the Node.js environment. You can use the file path processing package to process the file path to ensure the cross-platform compatibility of the path. After reading the file content, it needs to be parsed into a JavaScript object. For JSON files, optionally, use the JSON.parse() method to achieve this. For the adjustment of export mode, use the file processing package to write multi-language data to the file. The writing operation should also adapt to the asynchronous programming model of Node.js. Similarly, ensure that the file path is correctly parsed in the Node.js environment. Use the file path processing package to ensure the correctness of the path. Convert the multi-language data to a string format (such as a JSON string). Optionally, use the JSON.stringify() method.
[0146] By adjusting the import and export methods of multi-language files to adapt them to the Node.js operating environment, the file processing capabilities of Node.js can be effectively utilized to ensure the efficiency and reliability of multi-language files when reading and writing. This ensures the correct loading and updating of multi-language files in the Node.js environment, providing a reliable foundation for the program's multi-language support.
[0147] Exemplarily, the disclosed embodiment adds a dynamic update module to achieve real-time monitoring of changes in multilingual files in the front-end project. After determining the valid keys, invalid keys and duplicate keys in the first multilingual file, the dynamic update module will continue to monitor changes in project files related to the multilingual file. Once the addition, modification or deletion operation of the relevant file is detected, the dynamic update module updates the key-value pairs and template information in the first multilingual file according to the current operation. This update operation includes but is not limited to adding new valid keys, updating the values or reference times of existing keys, and deleting invalid or duplicate keys. In addition, the dynamic update module can also automatically adjust the storage structure of key-value pairs, optimize data access efficiency, ensure the real-time and accuracy of multilingual files, and is suitable for agile development environments. It can quickly adapt to rapid changes in development requirements, thereby maintaining the overall consistency and functional integrity of multilingual files.
[0148] Figure 5 is a structural block diagram of a multi-language file processing device provided by an embodiment of the present disclosure, such as Figure 5 As shown, the device comprises:
[0149] An acquisition module 201 is used to acquire file information of a first multilingual file to be optimized from a file information queue, wherein the file information queue records file information of all multilingual files in a front-end project;
[0150] A definition module 202, configured to define initialization parameters according to the file information of the first multi-language file;
[0151] a traversal module 203, configured to traverse the file information queue, perform multi-language matching based on the initialization parameters, determine valid keys, invalid keys, and duplicate keys in the first multi-language file, and collect template information of the valid keys, wherein the valid keys are keys referenced at least once in multiple multi-language files, the invalid keys are keys not referenced in any multi-language file, and the duplicate keys are keys that are repeated in the first multi-language file and have exactly the same value;
[0152] The generating module 204 is configured to hide and / or remove the key-value pairs corresponding to the invalid keys and the duplicate keys based on the first multi-language file, and generate an optimized second multi-language file according to the template information of the valid keys.
[0153] Exemplarily, the device further includes:
[0154] Import module, used to import Node.js file processing package and file path processing package;
[0155] A top-level location definition module, used to define the top-level multi-language folder location of the front-end project using the file path processing package;
[0156] A reading path determination module, used to determine a reading path according to the location of the top-level multi-language folder;
[0157] Exemplarily, the acquisition module includes:
[0158] The recursive reading submodule is used to recursively read and collect all file information under the reading path using the file processing package according to the reading path, wherein all file information under the reading path includes file information of the first multi-language file.
[0159] Exemplarily, the recursive reading submodule includes:
[0160] A judging unit, used to judge the type of the object currently read according to the file information currently read, wherein the object type includes a file type and a folder type;
[0161] A saving unit, used for saving the currently read file information in the form of an array to the file information queue when the object type is a file type;
[0162] The recursive reading unit is used to, when the object type is a folder, continue to recursively read according to the reading path until the object types indicated by all the read file information are file types.
[0163] Exemplarily, the initialization parameters include: a multi-language key, a multi-language value, and a key reference count;
[0164] The definition module includes:
[0165] a key-value determination submodule, configured to determine the key and value of each key-value pair in the first multi-language file according to the file information of the first multi-language file;
[0166] The initialization parameter definition submodule is used to define a one-to-one corresponding initialization parameter for each key-value pair in the first multi-language file, wherein the multi-language key of the initialization parameter is defined as the key of the key-value pair, the multi-language value of the initialization parameter is defined as the value of the key-value pair, and the number of key references of the initialization parameter is set to an initial value of 0.
[0167] Exemplarily, the traversal module includes:
[0168] A loop reading submodule, used for loop reading initialization parameters of each key-value pair in the first multi-language file based on one of the multi-languages;
[0169] A loop traversal submodule, used for looping through the file information queue, and performing multi-language matching between the file information in the file information queue and the multi-language key defined in the initialization parameter;
[0170] The multi-language matching sub-module is used to increase the number of key references corresponding to the currently matched multi-language key by 1 whenever file information successfully matches a defined multi-language key, and collect template information of the key corresponding to the successfully matched multi-language key, wherein the template information includes the multi-language key, multi-language value, key reference number, key reference position and key version.
[0171] Exemplarily, the traversal module includes:
[0172] A first checking submodule, configured to check the number of key references of all key-value pairs in the first multi-language file;
[0173] A first marking submodule is used for marking, for any key-value pair in the first multi-language file, a key of the key-value pair as a valid key when the number of key references is greater than 0, collecting template information of the valid key, and adding the collected template information of the valid key to a temporary content set;
[0174] a second marking submodule, configured to check whether the key of the key-value pair is in a whitelist when the number of key references is less than 0; if the key of the key-value pair is in the whitelist, mark the key of the key-value pair as a valid key, collect template information of the valid key, and add the collected template information of the valid key to a temporary content set, wherein the whitelist is a list defining multilingual keys that need to be protected; if the key of the key-value pair is not in the whitelist, mark the key of the key-value pair as an invalid key, and add the invalid key to a set of content to be deleted;
[0175] A second checking submodule is used to traverse all key-value pairs of the first multilingual file to check whether there are duplicate keys in multiple key-value pairs;
[0176] The third marking submodule is used for marking the key as a duplicate key if there are multiple key-value pairs with duplicate keys and the same value, and adding the duplicate key to the set of content to be deleted.
[0177] Exemplarily, the generating module includes:
[0178] Creating a submodule for creating a new JSON object based on the first multi-language file;
[0179] The remove submodule is used to hide and / or remove the key-value pairs corresponding to invalid keys and duplicate keys in the content set to be deleted from the new JSON object;
[0180] The integration submodule is used to integrate the template information corresponding to all valid keys in the temporary content set into a new JSON object;
[0181] A generation location definition submodule, used to define the generation location of the optimized second multi-language file by using a file path processing package;
[0182] The generating submodule is used to save the new JSON object as an optimized second multi-language file by using a file processing package, wherein the first multi-language file and the second multi-language file have the same file name, and the second multi-language file is generated in a file location indicated by the generating location.
[0183] Exemplarily, the device further comprises:
[0184] The adjustment module is used to use the file processing package to adjust the import and export method of the first multi-language file so that the import and export method of the first multi-language file is adapted to the operating environment of Node.js.
[0185] The embodiment of the present disclosure also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the various processes in the above-mentioned embodiment of the multi-language file processing method are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0186] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, devices, and electronic devices. Therefore, the embodiments of the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present disclosure may take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0187] The embodiments of the present disclosure are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing terminal device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded into a computer or other programmable data processing terminal device, so that a series of operation steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable terminal device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0188] Although the preferred embodiments of the present disclosure have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present disclosure.
[0189] Finally, it should be noted that, in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "include..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements. The above is a detailed introduction to a multilingual file processing method, device and electronic device provided by the present disclosure. The principle and implementation method of the present disclosure are explained in this article using specific examples. The description of the above embodiments is only used to help understand the method and its core idea of the present disclosure; at the same time, for those of ordinary skill in the art, according to the idea of the present disclosure, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present disclosure.
Claims
1. A multi-language file processing method, characterized in that: The method comprises: Acquire file information of a first multilingual file to be optimized from a file information queue, wherein the file information queue records file information of all multilingual files in the front-end project; defining initialization parameters according to the file information of the first multi-language file; Traversing the file information queue, performing multi-language matching based on the initialization parameters, determining valid keys, invalid keys, and duplicate keys in the first multi-language file, and collecting template information of the valid keys, wherein the valid key is a key referenced at least once in multiple multi-language files, the invalid key is a key not referenced in any multi-language file, and the duplicate key is a key that is repeated in the first multi-language file and has exactly the same value; Based on the first multi-language file, the key-value pairs corresponding to the invalid key and the duplicate key are hidden and / or removed, and an optimized second multi-language file is generated according to the template information of the valid key.
2. The method according to claim 1, characterized in that Before obtaining the file information of the first multilingual file to be optimized from the file information queue, the method further includes: Import the file processing package and file path processing package of Node.js; Using the file path processing package, define the top-level multi-language folder location of the front-end project; Determine a reading path according to the location of the top-level multi-language folder; Obtain file information of the first multi-language file to be optimized from the file information queue, including: According to the reading path, the file processing package is used to recursively read and collect all file information under the reading path, where all file information under the reading path includes file information of the first multi-language file.
3. The method according to claim 2, characterized in that The recursive reading and collection of all file information under the reading path includes: Determine the type of the object currently read according to the currently read file information, where the object type includes the file type and the folder type; When the object type is a file type, the currently read file information is saved in the form of an array to the file information queue; When the object type is a folder, the recursive reading is continued according to the reading path until the object types indicated by all the read file information are file types.
4. The method according to claim 1, characterized in that: The initialization parameters include: multi-language key, multi-language value and key reference count; Defining initialization parameters according to the file information of the first multi-language file includes: Determining, according to the file information of the first multi-language file, the key and value of each key-value pair in the first multi-language file; For each key-value pair in the first multi-language file, a one-to-one corresponding initialization parameter is defined, wherein the multi-language key of the initialization parameter is defined as the key of the key-value pair, the multi-language value of the initialization parameter is defined as the value of the key-value pair, and the number of key references of the initialization parameter is set to an initial value of 0.
5. The method according to claim 4, characterized in that The traversing the file information queue and performing multi-language matching based on the initialization parameters includes: Taking one of the multiple languages as the main body, cyclically reading initialization parameters of each key-value pair in the first multiple language file; Looping through the file information queue, and performing multi-language matching between the file information in the file information queue and the multi-language key defined in the initialization parameters; Whenever file information successfully matches a defined multilingual key, the number of key references corresponding to the currently matched multilingual key is increased by 1, and template information of the key corresponding to the successfully matched multilingual key is collected, wherein the template information includes the multilingual key, multilingual value, key reference number, key reference position and key version.
6. The method according to claim 5, characterized in that The determining of valid keys, invalid keys, and duplicate keys in the first multi-language file and collecting template information of the valid keys includes: Checking the number of key references of all key-value pairs in the first multi-language file; For any key-value pair in the first multi-language file, if the number of key references is greater than 0, mark the key of the key-value pair as a valid key, collect template information of the valid key, and add the collected template information of the valid key to the temporary content set; When the number of key references is less than 0, check whether the key of the key-value pair is in the whitelist. If the key of the key-value pair is in the whitelist, mark the key of the key-value pair as a valid key, collect template information of the valid key, and add the collected template information of the valid key to the temporary content set. The whitelist is a list that defines multilingual keys that need to be protected. If the key of the key-value pair is not in the whitelist, mark the key of the key-value pair as an invalid key, and add the invalid key to the content set to be deleted. Traversing all key-value pairs of the first multilingual file, and checking whether there are duplicate keys in multiple key-value pairs; If there are multiple key-value pairs with duplicate keys and identical values, the key is marked as a duplicate key and added to the set of content to be deleted.
7. The method according to any one of claims 1 to 6, characterized in that: Based on the first multi-language file, the key-value pairs corresponding to the invalid key and the duplicate key are hidden and / or removed, and an optimized second multi-language file is generated according to the template information of the valid key, including: Create a new JSON object based on the first multilingual file; Hide and / or remove the key-value pairs corresponding to invalid keys and duplicate keys in the content set to be deleted from the new JSON object; Integrate the template information corresponding to all valid keys in the temporary content set into a new JSON object; Using a file path processing package, defining a generation location of the optimized second multi-language file; The new JSON object is saved as an optimized second multi-language file using a file processing package, the first multi-language file and the second multi-language file have the same file name, and the second multi-language file is generated in the file location indicated by the generation location.
8. The method according to claim 2, characterized in that: The method further comprises: The file processing package is used to adjust the method of importing and exporting the first multi-language file, so that the method of importing and exporting the first multi-language file is adapted to the operating environment of Node.js.
9. A multi-language document processing device, characterized in that: The device comprises: An acquisition module, used for acquiring file information of a first multilingual file to be optimized from a file information queue, wherein the file information queue records file information of all multilingual files in the front-end project; A definition module, used to define initialization parameters according to the file information of the first multi-language file; a traversal module, configured to traverse the file information queue, perform multi-language matching based on the initialization parameters, determine valid keys, invalid keys, and duplicate keys in the first multi-language file, and collect template information of the valid keys, wherein the valid keys are keys referenced at least once in multiple multi-language files, the invalid keys are keys not referenced in any multi-language file, and the duplicate keys are keys that are repeated in the first multi-language file and have exactly the same value; A generating module is used to hide and / or remove the key-value pairs corresponding to the invalid keys and the duplicate keys based on the first multi-language file, and generate an optimized second multi-language file according to the template information of the valid keys.
10. An electronic device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the multi-language document processing method according to any one of claims 1 to 8.
