A multilingual file processing method, device and electronic equipment
By automating the processing of multilingual files, identifying and handling valid, invalid, and duplicate keys, the problem of low efficiency in multilingual file management is solved, the quality and maintainability of the dictionary are optimized, and the readability and overall efficiency of multilingual files are improved.
Patent Information
- Application Number
- CN202410814557.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2044-06-21
AI Technical Summary
In existing technologies, the management of multilingual files relies on manual operation, which leads to low efficiency and is prone to errors. It is difficult to adapt to rapidly changing multilingual needs, and there are redundant and duplicate key-value pairs in multilingual files, which increases maintenance complexity.
This paper provides a method for processing multilingual files. It automatically identifies and processes valid, invalid, and duplicate keys in multilingual files. It utilizes Node.js's file processing and path processing packages to recursively read the file information queue, defines initialization parameters for multilingual matching, and generates optimized multilingual files.
Automated processing of multilingual files reduces redundant and invalid data, improves the quality and maintainability of the thesaurus, and enhances the readability and overall efficiency of multilingual files.
Smart Images

Figure CN118708557B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of multilingual document processing, specifically to a multilingual document processing method, apparatus, and electronic device. Background Technology
[0002] With the acceleration of globalization, the demand for website internationalization and localization is growing, giving rise to multilingual front-end technologies. This technology allows developers to use multiple languages in front-end development, enabling dynamic display and interaction of web page content in different language environments, thereby meeting the needs of users of various languages.
[0003] However, in front-end multilingual development practices, as time goes by and projects iterate, multilingual dictionaries often accumulate a large number of unused vocabulary entries. If these unused words are not cleaned up in a timely manner, it will lead to redundancy and duplication in the dictionary, further increasing maintenance complexity and resource consumption. In related technologies, the management of multilingual files still relies on manual operations by developers, which is not only inefficient and error-prone but also difficult to adapt to rapidly changing multilingual requirements. Therefore, there is an urgent need for a method that can automatically optimize the processing of multilingual files. Summary of the Invention
[0004] This disclosure provides a multilingual file processing method, apparatus, and electronic device, aiming to solve the problems existing in the background art.
[0005] To solve the above-mentioned technical problems, this disclosure is implemented as follows:
[0006] In a first aspect, embodiments of this disclosure provide a multilingual file processing method, the method comprising:
[0007] Retrieve the file information of the first multilingual file to be optimized from the file information queue, which records the file information of all multilingual files in the front-end project;
[0008] Define initialization parameters based on the file information of the first multilingual file;
[0009] Traverse the file information queue, perform multilingual matching based on the initialization parameters, determine the valid keys, invalid keys, and duplicate keys in the first multilingual file, and collect the template information of the valid keys. The valid keys are keys that are referenced at least once in multiple multilingual files, the invalid keys are keys that are not referenced in any multilingual file, and the duplicate keys are keys that are repeated in the first multilingual file and have the same value.
[0010] Based on the first multilingual file, the key-value pairs corresponding to the invalid keys and the duplicate keys are hidden and / or removed, and an optimized second multilingual file is generated according to the template information of the valid keys.
[0011] Optionally, before retrieving the file information of the first multilingual file to be optimized from the file information queue, the method further includes:
[0012] Import the file handling package and file path handling package from Node.js;
[0013] The file path processing package is used to define the location of the top-level multilingual folder in the front-end project;
[0014] The read path is determined based on the location of the top-level multilingual folder;
[0015] Retrieve file information from the file information queue for the first multilingual file to be optimized, including:
[0016] According to the read path, the file processing package is used to recursively read and collect all file information under the read path, including the file information of the first multilingual file.
[0017] Optionally, the recursive reading and collection of all file information under the read path includes:
[0018] The type of the object being read is determined based on the currently read file information, where the object type includes file type and folder type;
[0019] If the object type is a file type, the currently read file information is saved to the file information queue in the form of an array;
[0020] If the object type is a folder, continue reading recursively according to the reading path until all the file information read indicates that the object type is a file.
[0021] Optionally, the initialization parameters include: multilingual key, multilingual value, and key reference count;
[0022] Initialization parameters are defined based on the file information of the first multilingual file, including:
[0023] Based on the file information of the first multilingual file, determine the key and value of each key-value pair in the first multilingual file;
[0024] For each key-value pair in the first multilingual file, a one-to-one corresponding initialization parameter is defined, 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.
[0025] Optionally, traversing the file information queue and performing multilingual matching based on the initialization parameters includes:
[0026] Using one of the multilingual languages as the main language, the initialization parameters of each key-value pair in the first multilingual file are read in a loop.
[0027] The file information queue is iterated through in a loop, and the file information in the file information queue is matched with the multilingual key defined in the initialization parameters for multilingual matching.
[0028] Whenever file information successfully matches a defined multilingual key, the key reference count corresponding to the currently matched multilingual key is incremented by 1, and the template information of the key corresponding to the successfully matched multilingual key is collected. The template information includes the multilingual key, multilingual value, key reference count, key reference position, and key version.
[0029] Optionally, based on the first multilingual file, the key-value pairs corresponding to the invalid keys and the duplicate keys are hidden and / or removed, and an optimized second multilingual file is generated according to the template information of the valid keys, including:
[0030] Create a new JSON object based on the first multilingual file;
[0031] Hide and / or remove key-value pairs corresponding to invalid and duplicate keys from the set to be deleted in the new JSON object;
[0032] Integrate the template information corresponding to each valid key in the temporary content set into a new JSON object;
[0033] The file path processing package is used to define the generation location of the optimized second multilingual file;
[0034] A new JSON object is saved using a file processing package as an optimized second multilingual file. The first and second multilingual files have the same filename, and the second multilingual file is generated at the file location indicated by the generation location.
[0035] Optionally, the method further includes:
[0036] Using the file processing package, the import and export method of the first multilingual file is adjusted to adapt the import and export method of the first multilingual file to the Node.js runtime environment.
[0037] Secondly, embodiments of this disclosure provide a multilingual file processing apparatus, the apparatus comprising:
[0038] The acquisition module is used to acquire the file information of the first multilingual file to be optimized from the file information queue, which records the file information of all multilingual files in the front-end project;
[0039] A definition module is used to define initialization parameters based on the file information of the first multilingual file;
[0040] The traversal module is used to traverse the file information queue, perform multilingual matching based on the initialization parameters, determine the valid keys, invalid keys, and duplicate keys in the first multilingual file, and collect the template information of the valid keys. The valid keys are keys that are referenced at least once in multiple multilingual files, the invalid keys are keys that are not referenced in any multilingual file, and the duplicate keys are keys that are repeated in the first multilingual file and have the same value.
[0041] The generation 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 multilingual file, and generate an optimized second multilingual file according to the template information of the valid keys.
[0042] Optionally, the device further includes:
[0043] Import modules are used to import Node.js's file handling and file path handling packages;
[0044] The top-level location definition module is used to define the location of the top-level multilingual folder of the front-end project using the file path processing package;
[0045] The read path determination module is used to determine the read path based on the location of the top-level multilingual 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, including the file information of the first multilingual file.
[0048] Optionally, the recursive reading submodule includes:
[0049] The judgment unit is used to determine the type of the object being read based on the currently read file information, wherein the object type includes file type and folder type;
[0050] A storage unit is used to save the currently read file information to the file information queue in the form of an array when the object type is a file type;
[0051] The recursive reading unit is used to continue recursively reading according to the reading path when the object type is a folder, until all the file information read indicates that the object type is a file.
[0052] Optionally, the initialization parameters include: multilingual key, multilingual value, and key reference count;
[0053] The definition module includes:
[0054] The key-value determination submodule is used to determine the key and value of each key-value pair in the first multilingual file based on the file information of the first multilingual file.
[0055] An initialization parameter definition submodule is used to define 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.
[0056] Optionally, the traversal module includes:
[0057] The loop reading submodule is used to read the initialization parameters of each key-value pair in the first multi-language file, with one of the languages as the main language.
[0058] The loop traversal submodule is used to loop through the file information queue and perform multilingual matching between the file information in the file information queue and the multilingual keys defined in the initialization parameters.
[0059] The multilingual matching submodule is used to increment the key reference count of the currently matched multilingual key by 1 whenever file information is successfully matched with a defined multilingual key, and to collect the template information of the key corresponding to the successfully matched multilingual key. The template information includes the multilingual key, multilingual value, key reference count, key reference position, and key version.
[0060] Optionally, the traversal module includes:
[0061] The first inspection submodule is used to check the number of key references for all key-value pairs in the first multilingual file;
[0062] The first tagging submodule is used to mark the key of any key-value pair in the first multilingual file as a valid key when the key reference count is greater than 0, collect the template information of the valid key, and add the collected template information of the valid key to a temporary content set.
[0063] The second marking submodule is used to check whether the key of a key-value pair is in the whitelist when the key reference count is less than 0. If the key of the key-value pair is 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 added to a temporary content set. 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.
[0064] The second checking submodule is used to traverse all key-value pairs in the first multilingual file and check whether there are multiple key-value pairs with duplicate keys.
[0065] The third tagging submodule is used to mark a key as a duplicate key if multiple key-value pairs have the same key and value, and to add the duplicate key to the set of contents to be deleted.
[0066] Optionally, the generation module includes:
[0067] Create a submodule to create a new JSON object based on the first multilingual file;
[0068] Remove submodules to hide and / or remove key-value pairs corresponding to invalid and duplicate keys from the set of contents 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] The generation location definition submodule is used to process packages using file paths and define the generation location of the optimized second multilingual file;
[0071] A generation submodule is used to save a new JSON object as an optimized second multilingual file using a file processing package. The first multilingual file and the second multilingual file have the same filename, and the second multilingual file is generated in the file location indicated by the generation location.
[0072] Optionally, the device further includes:
[0073] The adjustment module is used to adjust the import and export method of the first multilingual file using the file processing package, so that the import and export method of the first multilingual file is adapted to the Node.js runtime environment.
[0074] Thirdly, embodiments of this disclosure provide an electronic device, including: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of a multilingual file processing method.
[0075] The technical solutions provided by the embodiments of this disclosure bring at least the following beneficial effects:
[0076] This disclosure automates the identification and processing of valid, invalid, and duplicate keys in multilingual documents through multilingual matching, systematically cleaning and optimizing the thesaurus and reducing unnecessary data burden. Overall, this disclosure not only reduces the accumulation of invalid words in the multilingual thesaurus later on, improving the overall quality and maintainability of the thesaurus, but also increases the readability of the optimized multilingual documents through annotated template information. Attached Figure Description
[0077] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0078] Figure 1 This is a schematic diagram illustrating the steps of a multilingual file processing method provided in one embodiment of this disclosure;
[0079] Figure 2 This is a flowchart illustrating a recursive reading process provided in one embodiment of this disclosure;
[0080] Figure 3 This is a flowchart illustrating a multilingual matching process provided in one embodiment of this disclosure;
[0081] Figure 4 This is a flowchart illustrating the generation of a second multilingual file according to an embodiment of this disclosure;
[0082] Figure 5 This is a structural block diagram of a multilingual file processing apparatus provided in one embodiment of the present disclosure. Detailed Implementation
[0083] The technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0084] When developing websites or applications that support multiple languages, a large number of multilingual files are typically involved. Using the method provided in this disclosure, these multilingual files can be effectively managed, reducing redundant, duplicate, and invalid key-value pairs, and ensuring that each multilingual file is optimal. Furthermore, for cross-language platforms such as multilingual e-commerce platforms and educational platforms based on multilingual front-end projects, this disclosure demonstrates significant technical effects in optimizing multilingual files during actual development, reducing redundant and invalid information, improving the overall quality of multilingual files, and providing developers and project users with a smoother and more efficient experience.
[0085] Multilingual files are files used during software or website internationalization (i18n) to store text content in different language versions. They are typically stored as key-value pairs, where the key is a unique identifier and the value is the corresponding text content. The main purpose of multilingual files is to provide localized interface text for users of different languages, enabling software or websites to support multiple languages. By loading files in different languages, the interface language can be dynamically switched without modifying the code. Multilingual files typically use formats such as JSON, YAML, and XML to store text content. Each file corresponds to one language, and the text content is recorded internally as key-value pairs. For 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 actual text content, which is the translated text for one of the multilingual 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 practical applications, when a user selects English, the program loads the en.json file and uses its text content to display the interface; when a user selects Spanish, the program loads the es.json file and uses its text content to display the interface. It should be noted that the "key-value pairs" described in this embodiment are uniformly considered to be multilingual key-value pairs in multilingual files, in order to avoid ambiguity and misunderstanding with other forms of key-value pairs.
[0086] Figure 1 This is a schematic diagram illustrating the steps of a multilingual file processing method provided in one embodiment of this disclosure, as follows: Figure 1 As shown, the method includes:
[0087] Step S101: Obtain the file information of the first multilingual file to be optimized from the file information queue, wherein the file information queue records the file information of all multilingual files in the front-end project;
[0088] Step S102: Define initialization parameters based on the file information of the first multilingual file;
[0089] Step S103: Traverse the file information queue, perform multilingual matching based on the initialization parameters, determine the valid keys, invalid keys, and duplicate keys in the first multilingual file, and collect the template information of the valid keys. The valid keys are keys that are referenced at least once in multiple multilingual files, the invalid keys are keys that are not referenced in any multilingual file, and the duplicate keys are keys that are repeated in the first multilingual file and have the same value.
[0090] Step S104: Based on the first multilingual file, hide and / or remove the key-value pairs corresponding to the invalid keys and the duplicate keys, and generate an optimized second multilingual file according to the template information of the valid keys.
[0091] In step S101, the file information queue is a structure that records detailed information about all multilingual files in the front-end project, providing a comprehensive file information foundation for subsequent multilingual file optimization. In this 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 are checked one by one to determine their validity and then subjected to subsequent optimization processing.
[0092] In step S102, the file information of the first multilingual file includes information on all key-value pairs in the first multilingual file, including the key and value of each key-value pair. Based on the file information of the first multilingual file, the information on all key-value pairs in the first multilingual file is determined, and initialization parameters are defined for each key-value pair. In this embodiment, 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-value pairs in the first multilingual file during the multilingual matching process. The purpose of defining the initialization parameters is to facilitate accurate identification and processing of the key-value pairs in the first multilingual file in subsequent multilingual matching steps. This will be explained later and will not be detailed here.
[0093] In step S103, for each key-value pair in the first multilingual file, its initialization parameters are obtained. During the traversal of 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 against the multilingual keys defined in the initialization parameters. During the multilingual matching process, valid keys, invalid keys, and duplicate keys in the first multilingual file are determined. Valid keys are keys referenced in at least one multilingual file in the file information queue, with a reference count greater than 0. Invalid keys are keys that have not been referenced in any multilingual file, have a reference count of 0, and are not protected. Duplicate keys are keys that are repeated in the first multilingual file with identical values. For multilingual keys determined to be valid, their template information is collected, including the multilingual key, multilingual value, key reference count, key reference position, and key version.
[0094] Suppose there exists a multilingual file (e.g., en.json) and the following key-value pair content:
[0095] "welcome_message":"Welcome",
[0096] "logout":"Logout",
[0097] "login":"Login",
[0098] "login":"Login",
[0099] "unused_key":"Thisisnotused".
[0100] In addition, the file information queue also contains file information for several other multilingual files (e.g., fr.json, de.json, etc.). For the multilingual 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 multilingual file de.json, the key-value pairs are as follows:
[0105] "welcome_message":"Willkommen",
[0106] "logout":"Abmelden",
[0107] "login":"Anmelden" From the example above, we can see that welcome_message, logout, and login are all referenced in en.json, fr.json, and de.json, therefore they are valid keys. unused_key exists in en.json but is not referenced in any other multilingual files, therefore it is an invalid key. login appears twice in en.json with the same value, therefore it is both a valid key and a duplicate key.
[0108] In step S104, after multilingual matching is completed, the valid, invalid, and duplicate keys for the first multilingual language have been determined. First, the key-value pairs corresponding to invalid and duplicate keys need to be removed (e.g., commented out using template information). Invalid key-value pairs are removed from the original first multilingual file, or they are hidden; duplicate key-value pairs are deleted and / or hidden, retaining only one instance to make it the only valid key-value pair. Continuing with the example in step S103, the first multilingual file to be optimized is as follows:
[0109] "welcome_message":"Welcome",
[0110] "logout":"Logout",
[0111] "login":"Login"
[0112] "login":"Login",
[0113] Given "unused_key": "This is not used", we have determined that welcome_message and logout are valid keys, unused_key is an invalid key, and login is both a valid key and a duplicate key. After processing in step S104, based on the collected template information of valid keys, an optimized second multilingual file is generated.
[0114] "welcome_message":"Welcome" / / Template information corresponding to welcome_message;
[0115] "logout":"Logout" / / Template information corresponding to logout;
[0116] "login":"Login" / / The template information corresponding to login. In this embodiment, the display of valid keys and the hiding and / or removal of invalid 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 key, multilingual value, key reference count, duplicate key, invalid key, key reference position, and key version. The template information can be customized according to the needs of the developer and the development environment. In the above example, the valid keys "welcome_message", "logout", and "login" should be annotated with the defined template information, followed by annotation information such as key reference count, key reference position, and key version after the key-value pair. The template information for the invalid key "unused_key" can include the annotation "invalid key". During processing, it is convenient to hide the key-value pair of the invalid key according to the "invalid key" annotation. The processing of redundant keys is similar. In this way, the generated second multilingual file more intuitively conveys its validity and reference information to the developer, which not only reduces the redundant information of the file, but also improves the maintainability and readability of the file.
[0117] This disclosure automates the identification and processing of valid, invalid, and duplicate keys in multilingual documents through multilingual matching, systematically cleaning and optimizing the thesaurus and reducing unnecessary data burden. Overall, this disclosure not only reduces the accumulation of invalid words in the multilingual thesaurus later on, improving the overall quality and maintainability of the thesaurus, but also increases the readability of the optimized multilingual documents through annotated template information.
[0118] For example, before obtaining the file information of the first multilingual file to be optimized from the file information queue, the method further includes: importing the Node.js file processing package and file path processing package; using the file path processing package to define the location of the top-level multilingual folder of the front-end project; and determining the reading path based on the location of the top-level multilingual folder.
[0119] In Node.js, there are built-in `fs` (file handling package) and `path` (file path handling package), which provide basic functionality for handling files and paths. The file handling package is used for reading, writing, deleting, and manipulating files, while the file path handling package is used for processing and transforming file paths. Assuming the multilingual folder of a front-end project is located in the `locales` folder under the project root directory, this location can be defined using the file path handling package:
[0120] constprojectRoot=__dirname;
[0121] `const localesFolderPath = path.join(projectRoot, 'locales');` Here, `__dirname` is a global variable in Node.js that represents the directory where the current script is located. The `path.join()` method joins the project root directory and the name of the `locales` folder to form the absolute path of the multi-language folder. Next, it is necessary to read all file information under the `locales` folder. That is, based on the location of the top-level multi-language folder `locales`, the read path is determined, and preparation is made to recursively read the contents of these folders.
[0122] For example, obtaining file information of the first multilingual file to be optimized from the file information queue includes: recursively reading and collecting 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 the file information of the first multilingual file.
[0123] After determining the read path, the file processing package is used to traverse the directory and subdirectories of the top-level multilingual file, collecting information about all multilingual files, including the file information of the first multilingual file. Optionally, this can be implemented using 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, providing basic data for subsequent multilingual file optimization.
[0124] For example, the recursive reading and collection of all file information under the reading path includes: determining the type of the object being read based on the currently read file information, wherein the object type includes file type and folder type; if the object type is file type, saving the currently read file information to the file information queue in the form of an array; if the object type is folder, continuing to recursively read according to the reading path until all the object types indicated by the read file information are file type.
[0125] Figure 2 This is a flowchart illustrating a recursive reading process provided in one embodiment of this disclosure, such as... Figure 2As shown, in the process of processing multilingual files, files and / or folders under the determined input reading path are recursively read. During the reading process, it is necessary to determine whether the currently read object is a file or a folder, because the processing methods for files and folders are different. Files need to be processed directly on their contents, while folders require further in-depth reading of their internal files. This embodiment of the disclosure relies on the object type of the file and / or folder to indicate this, which is equivalent to one of the attribute information of the read file information. The object type includes both files and folders. When it is determined that the currently read object is a file, the file information of that file needs to be recorded. This recorded file information is saved in the form of an array in the file information queue. When it is determined that the currently read object is a folder, the contents of that folder need to be further read. This is a recursive process, meaning that the reading process will delve deeper into each subfolder layer by layer until all sub-items have been processed. If a sub-item is a folder, then the folder will be entered again, the current folder and path information will be reorganized into a new path, and the contents of its contents will continue to be read. The recursive call will continuously repeat the above steps until the object type indicated by all the read file information is a file. By recursively reading, we can delve into every 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] For example, 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 explains each parameter of the initialization parameters. The multilingual key (lankey) corresponds to the key of each key-value pair in the multilingual file; it is a placeholder string used to identify different language texts. The multilingual value (lanvalue) corresponds to the value of each key-value pair in the multilingual 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 multilingual files; it is initially set to 0 and will be dynamically updated during subsequent multilingual matching.
[0128] Defining initialization parameters involves preliminary analysis and configuration of the multilingual file content, laying the foundation for subsequent multilingual matching. The detailed steps are as follows: First, obtain the file information of the first multilingual file to be optimized, including information on all key-value pairs in the first multilingual file. Read the file information content of the first multilingual file and parse each key-value pair. As mentioned earlier, each key-value pair consists of a unique key and a corresponding value. For each parsed key-value pair, define the corresponding initialization parameter. For example, for the key-value pair "welcome_message":"Welcome", set the multilingual key of the initialization parameter to the key in this key-value pair. For example, "welcome_message". Set the multilingual value of the initialization parameter to the value in this key-value pair. For example, "Welcome". Set the key reference count of the initialization parameter to an initial value of 0. This is because in the initial stage, multilingual matching has not yet been performed, so the reference count is 0.
[0129] For example, the step of traversing the file information queue and performing multilingual matching based on the initialization parameters includes: taking one of the multilingual languages as the main body, cyclically reading the initialization parameters of each key-value pair in the first multilingual file; cyclically traversing the file information queue, performing multilingual matching between the file information in the file information queue and the multilingual keys defined in the initialization parameters; whenever a file information successfully matches a defined multilingual key, incrementing the key reference count corresponding to the currently matched multilingual key by 1, and collecting the template information of the key corresponding to the successfully matched multilingual key, wherein the template information includes the multilingual key, multilingual value, key reference count, key reference position, and key version.
[0130] To optimize and manage key-value pairs, a language is selected as the primary language from the multilingual files. For example, if processing a multilingual file containing English, French, and German, English can be selected as the primary language. For the primary language multilingual file, each key-value pair and its initialization parameters are read one by one: multilingual key, multilingual value, and key reference count (initially 0). For example, when English is selected as the primary 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 reading the initialization parameters of the primary language file, these parameters are matched against other file information in the file information queue. For each file information, the file information queue is iterated through. For each file information in the file information queue, its content is checked to see if it contains the multilingual key defined in the initialization parameters. If a key in the file information matches a multilingual key in the initialization parameters, it means that the multilingual file corresponding to this file information references a key in one of the key-value pairs in the first multilingual file, and the key reference count corresponding to the currently matched multilingual key is incremented by 1. This allows us to count the number of times the key is referenced across all files and collect relevant template information for successfully matched multilingual keys. The template information corresponding to a multilingual key should include: the multilingual key, the multilingual value, the number of key references (i.e., the current number of references), the key reference location, the location of the multilingual file referencing the key, the key version, and the key's version information or identifier. Developers can also customize the template information according to actual development needs to generate a readable second multilingual file; this disclosure does not impose any restrictions on this.
[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 example, the initialization parameters defined for the file information of the first multilingual file are: multilingual key: welcome_message; multilingual value: Welcome; key reference count: 0. Loop through the file information queue to perform multilingual matching.
[0135] In file A, if welcome_message is matched, the key reference count is incremented by 1, and the template information is updated as follows: Multilingual key: welcome_message; Multilingual value: Welcome; Key reference count: 1; Key reference location: file A; Key version: N / A (if version information is available, it will be recorded).
[0136] In file B, welcome_message is matched, the key reference count is incremented by 1, and the template information is updated as follows: Multilingual key: welcome_message; Multilingual value: Bienvenue; Key reference count: 2; Key reference location: file B; Key version: N / A.
[0137] In file C, a match is found for `welcome_message`, the key reference count is incremented by 1, and the template information is updated as follows: Multilingual key: `welcome_message`; Multilingual value: `Willkommen`; Key reference count: 3; Key reference location: File C; Key version: N / A. Through the above multilingual matching, the reference count of each multilingual 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 key-value pairs corresponding to invalid and duplicate keys, and generating optimized multilingual files.
[0138] For example, determining the valid keys, invalid keys, and duplicate keys in the first multilingual file, and collecting the template information of the valid keys, includes: checking the key reference count of all key-value pairs in the first multilingual file; for any key-value pair in the first multilingual file, if the key reference count is greater than 0, marking the key of the key-value pair as a valid key, collecting the template information of the valid key, and adding the collected template information of the valid key to a temporary content set; if the key reference count is less than 0, checking whether the key of the key-value pair is in a 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 added to the temporary content set. 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 added to the content set to be deleted. All key-value pairs of the first multilingual file are traversed to check if there are multiple key-value pairs with duplicate keys. If there are multiple key-value pairs with duplicate keys and the same value, the key is marked as a duplicate key and added to the content set to be deleted.
[0139] Figure 3 This is a flowchart illustrating a multilingual matching process provided in one embodiment of this disclosure, such as... Figure 3As shown, after defining the initialization parameters based on the file information of the first multilingual file, the system recursively reads the file information of all multilingual files requiring multilingual matching. It iteratively reads the file information queue, performs multilingual matching on each file based on the initialization parameters, collects template information for successfully matched multilingual keys during matching, and updates the key reference count of each successfully matched key by incrementing it by one, until all information in the file information queue has been read. After reading all information in the file information queue, all key-value pairs in the first multilingual file are checked, focusing on the reference count of each key. If the reference count of a multilingual key is greater than 0, it means that the key has been referenced in at least one file, and this key is marked as a valid key. For each key marked as valid, its template information is collected and added to a temporary content set. For keys with a reference count of 0, it is first checked whether these keys are in a whitelist. The whitelist is a predefined list containing multilingual keys that need protection. If a key is in the whitelist, even if its reference count is 0, the key is still marked as a valid key, and its template information is collected and added to the temporary content set. If a key is not in the whitelist, it is marked as an invalid key and added to the list of items to be deleted. The purpose of the whitelist is to ensure that certain critical keys are not accidentally deleted, even if they are not currently being used. For example, a specific error message key may not be used temporarily, but it still needs to be retained due to its importance. Finally, all key-value pairs in the first multilingual file are traversed to check for duplicate keys. If multiple keys in the first multilingual file have the same name and corresponding identical values, these keys are marked as duplicate keys and added to the list of items to be deleted for removal during subsequent optimization.
[0140] The multilingual matching method provided in this disclosure can effectively identify valid, invalid, and duplicate keys in multilingual files. Valid keys are retained and detailed template information is collected to ensure their correct reference and use in multilingual files. Invalid and duplicate keys are marked and subsequently removed, thereby optimizing the structure and content of multilingual files and improving their maintainability and readability.
[0141] For example, based on the first multilingual file, the key-value pairs corresponding to the invalid keys and the duplicate keys are hidden and / or removed, and an optimized second multilingual file is generated according to the template information of the valid keys. This includes: creating a new JSON object based on the first multilingual file; hiding and / or removing the key-value pairs corresponding to the invalid keys and duplicate keys in the content set to be deleted from the new JSON object; integrating the template information corresponding to each of the valid keys in the temporary content set into the new JSON object; defining the generation location of the optimized second multilingual file using a file path processing package; and saving the new JSON object as the optimized second multilingual file using a file processing package, wherein the filenames of the first multilingual file and the second multilingual file are the same, and the second multilingual file is generated in the file location indicated by the generation location.
[0142] Figure 4 This is a flowchart illustrating the generation of a second multilingual file according to an embodiment of this disclosure. Please refer to it. Figure 4The process iteratively reads the file information of a first multilingual file, focusing on a single language. This includes reading all key-value pairs from the first multilingual file. During this process, template information for valid keys in the first multilingual file is obtained according to the multilingual matching process and methods described earlier, and the key reference count for valid keys is dynamically incremented by 1 accordingly. After reading all key-value pairs from the first multilingual file, a new JSON object is created based on the first multilingual file. This object will serve as the basis for the optimized multilingual file. It is an empty JSON structure, ready to hold the optimized key-value pairs. Invalid and duplicate keys need to be handled in the new JSON object. Invalid and duplicate keys have already been identified and collected, 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 comment them out as "invalid key" or "duplicate key" so that they can be restored if needed. If you choose to remove them, you completely delete these key-value pairs so that they no longer occupy file space. Next, the template information for all valid keys in the temporary content set is integrated into a new JSON object. As mentioned earlier, the template information for valid keys has already been collected, including the multilingual key, its corresponding value, reference count, reference location, and version. These valid keys and their related information are added to the new JSON object one by one, ensuring that each valid key has complete template information. Using a file path handling package, the generation location of the optimized second multilingual file is defined. Optionally, this includes defining the project's top-level directory or a specified multilingual folder to determine the specific location where the new JSON object (i.e., the optimized file) will be saved. Using a file handling package, the new JSON object is written to the file system. The optimized second multilingual file has the same filename as the first multilingual file to replace the old file or maintain filename consistency. The newly generated second multilingual file will be saved to the previously defined generation location.
[0143] For example, the method further includes: using the file processing package to adjust the import and export method of the first multilingual file so that the import and export method of the first multilingual file is adapted to the Node.js runtime environment.
[0144] In this embodiment of the disclosure, the first multilingual file import method refers to how to read and load the multilingual file so that its content can be used for multilingual processing of the program. The first multilingual file export method refers to how to export the multilingual file to save or update it.
[0145] For the import method adjustment, use a file handling package to read multilingual files. The read operation should be adapted to Node.js's asynchronous programming model. Optionally, use callback functions, Promises, or async / await for asynchronous processing. Ensure that the file path is correctly parsed in the Node.js environment. You can use a file path handling package to process the file path and ensure cross-platform compatibility. After reading the file content, it needs to be parsed into a JavaScript object. For JSON files, you can optionally use the JSON.parse() method. For the export method adjustment, use a file handling package to write multilingual data to a file. The write operation should also be adapted to Node.js's asynchronous programming model. Similarly, ensure that the file path is correctly parsed in the Node.js environment. Use a file path handling package to ensure the path is correct. Convert the multilingual 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 multilingual files to adapt to the Node.js runtime environment, Node.js's file processing capabilities can be effectively utilized, ensuring the efficiency and reliability of reading and writing multilingual files. This ensures the correct loading and updating of multilingual files in the Node.js environment, providing a reliable foundation for multilingual support in the program.
[0147] For example, this embodiment of the disclosure adds a dynamic update module to achieve real-time monitoring of changes to 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 continuously monitors changes to project files related to the multilingual file. Once a new, modified, or deleted operation is detected in the relevant file, 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 counts of existing keys, and deleting invalid or duplicate keys. In addition, the dynamic update module can automatically adjust the storage structure of key-value pairs, optimize data access efficiency, ensure the real-time performance 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 This is a structural block diagram of a multilingual file processing apparatus provided in one embodiment of the present disclosure, such as... Figure 5 As shown, the device includes:
[0149] The acquisition module 201 is used to acquire the file information of the first multilingual file to be optimized from the file information queue, wherein the file information queue records the file information of all multilingual files in the front-end project;
[0150] Definition module 202 is used to define initialization parameters based on the file information of the first multilingual file;
[0151] Traversal module 203 is used to traverse the file information queue, perform multilingual matching based on the initialization parameters, determine the valid keys, invalid keys and duplicate keys in the first multilingual file, and collect the template information of the valid keys. The valid keys are keys that are referenced at least once in multiple multilingual files, the invalid keys are keys that are not referenced in any multilingual file, and the duplicate keys are keys that are repeated in the first multilingual file and have the same value.
[0152] The generation module 204 is used to hide and / or remove the key-value pairs corresponding to the invalid keys and the duplicate keys based on the first multilingual file, and generate an optimized second multilingual file according to the template information of the valid keys.
[0153] Exemplarily, the device further includes:
[0154] Import modules are used to import Node.js's file handling and file path handling packages;
[0155] The top-level location definition module is used to define the location of the top-level multilingual folder of the front-end project using the file path processing package;
[0156] The read path determination module is used to determine the read path based on the location of the top-level multilingual folder;
[0157] For example, 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, including the file information of the first multilingual file.
[0159] For example, the recursive reading submodule includes:
[0160] The judgment unit is used to determine the type of the object being read based on the currently read file information, wherein the object type includes file type and folder type;
[0161] A storage unit is used to save the currently read file information to the file information queue in the form of an array when the object type is a file type;
[0162] The recursive reading unit is used to continue recursively reading according to the reading path when the object type is a folder, until all the file information read indicates that the object type is a file.
[0163] For example, the initialization parameters include: multilingual key, multilingual value, and key reference count;
[0164] The definition module includes:
[0165] The key-value determination submodule is used to determine the key and value of each key-value pair in the first multilingual file based on the file information of the first multilingual file.
[0166] An initialization parameter definition submodule is used to define 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.
[0167] For example, the traversal module includes:
[0168] The loop reading submodule is used to read the initialization parameters of each key-value pair in the first multi-language file, with one of the languages as the main language.
[0169] The loop traversal submodule is used to loop through the file information queue and perform multilingual matching between the file information in the file information queue and the multilingual keys defined in the initialization parameters.
[0170] The multilingual matching submodule is used to increment the key reference count of the currently matched multilingual key by 1 whenever file information is successfully matched with a defined multilingual key, and to collect the template information of the key corresponding to the successfully matched multilingual key. The template information includes the multilingual key, multilingual value, key reference count, key reference position, and key version.
[0171] For example, the traversal module includes:
[0172] The first inspection submodule is used to check the number of key references for all key-value pairs in the first multilingual file;
[0173] The first tagging submodule is used to mark the key of any key-value pair in the first multilingual file as a valid key when the key reference count is greater than 0, collect the template information of the valid key, and add the collected template information of the valid key to a temporary content set.
[0174] The second marking submodule is used to check whether the key of a key-value pair is in the whitelist when the key reference count is less than 0. If the key of the key-value pair is 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 added to a temporary content set. 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.
[0175] The second checking submodule is used to traverse all key-value pairs in the first multilingual file and check whether there are multiple key-value pairs with duplicate keys.
[0176] The third tagging submodule is used to mark a key as a duplicate key if multiple key-value pairs have the same key and value, and to add the duplicate key to the set of contents to be deleted.
[0177] For example, the generation module includes:
[0178] Create a submodule to create a new JSON object based on the first multilingual file;
[0179] Remove submodules to hide and / or remove key-value pairs corresponding to invalid and duplicate keys from the set of contents 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] The generation location definition submodule is used to process packages using file paths and define the generation location of the optimized second multilingual file;
[0182] A generation submodule is used to save a new JSON object as an optimized second multilingual file using a file processing package. The first multilingual file and the second multilingual file have the same filename, and the second multilingual file is generated in the file location indicated by the generation location.
[0183] Exemplarily, the device further includes:
[0184] The adjustment module is used to adjust the import and export method of the first multilingual file using the file processing package, so that the import and export method of the first multilingual file is adapted to the Node.js runtime environment.
[0185] This 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, it implements the various processes described above in the multilingual file processing method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here.
[0186] Those skilled in the art will understand that embodiments of this disclosure can be provided as methods, apparatus, and electronic devices. Therefore, embodiments of this disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of this disclosure can take the form of a computer program product embodied 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] This disclosure describes embodiments of methods, terminal devices (systems), and computer program products according to embodiments of this disclosure with reference to flowchart illustrations and / or block diagrams. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 The computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The functions specified in one or more boxes. These computer program instructions may also be loaded onto a computer or other programmable data processing terminal equipment to cause a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0188] While preferred embodiments of the present disclosure have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the present disclosure.
[0189] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the term "comprising" or any other variations thereof is intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element. The above provides a detailed description of a multilingual document processing method, apparatus, and electronic device provided by this disclosure. Specific examples have been used to illustrate the principles and implementation methods of this disclosure. The descriptions of the above embodiments are only for the purpose of helping to understand the method and its core ideas; at the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of this disclosure. Therefore, the content of this specification should not be construed as a limitation of this disclosure.
Claims
1. A multilingual file processing method, characterized in that, The method includes: Retrieve the file information of the first multilingual file to be optimized from the file information queue, which records the file information of all multilingual files in the front-end project; Define initialization parameters based on the file information of the first multilingual file; Traverse the file information queue, perform multilingual matching based on the initialization parameters, determine the valid keys, invalid keys, and duplicate keys in the first multilingual file, and collect the template information of the valid keys. The valid keys are keys that are referenced at least once in multiple multilingual files, the invalid keys are keys that are not referenced in any multilingual file, and the duplicate keys are keys that are repeated in the first multilingual file and have the same value. Based on the first multilingual file, the key-value pairs corresponding to the invalid keys and the duplicate keys are hidden and / or removed, and an optimized second multilingual file is generated according to the template information of the valid keys; The step of traversing the file information queue and performing multilingual matching based on the initialization parameters includes: Using one of the multilingual languages as the main language, the initialization parameters of each key-value pair in the first multilingual file are read in a loop. The file information queue is iterated through in a loop, and the file information in the file information queue is matched with the multilingual key defined in the initialization parameters for multilingual matching. Whenever file information successfully matches a defined multilingual key, the key reference count corresponding to the currently matched multilingual key is incremented by 1, and the template information of the key corresponding to the successfully matched multilingual key is collected. The template information includes the multilingual key, multilingual value, key reference count, key reference position, and key version. The process of determining valid keys, invalid keys, and duplicate keys in the first multilingual file, and collecting template information for the valid keys, includes: Check the key reference count for all key-value pairs in the first multilingual file; For any key-value pair in the first multilingual file, if the key reference count is greater than 0, mark the key of the key-value pair as a valid key, collect the template information of the valid key, and add the collected template information of the valid key to the temporary content set. If the key reference count is less than 0, check if 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 the template information of the valid key, and add the collected template information of the valid key to a 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. Iterate through all key-value pairs in the first multilingual file and check if there are multiple key-value pairs with duplicate keys; If multiple key-value pairs have the same key and value, mark the key as a duplicate key and add the duplicate key to the set of items to be deleted.
2. The method according to claim 1, characterized in that, Before retrieving file information of the first multilingual file to be optimized from the file information queue, the method further includes: Import the file handling package and file path handling package from Node.js; The file path processing package is used to define the location of the top-level multilingual folder in the front-end project; The read path is determined based on the location of the top-level multilingual folder; Retrieve file information from the file information queue for the first multilingual file to be optimized, including: According to the read path, the file processing package is used to recursively read and collect all file information under the read path, including the file information of the first multilingual file.
3. The method according to claim 2, characterized in that, The recursive reading and collection of all file information under the read path includes: The type of the object being read is determined based on the currently read file information, where the object type includes file type and folder type; If the object type is a file type, the currently read file information is saved to the file information queue in the form of an array; If the object type is a folder, continue reading recursively according to the reading path until all the file information read indicates that the object type is a file.
4. The method according to claim 1, characterized in that, The initialization parameters include: multilingual key, multilingual value, and key reference count; Initialization parameters are defined based on the file information of the first multilingual file, including: Based on the file information of the first multilingual file, determine the key and value of each key-value pair in the first multilingual file; For each key-value pair in the first multilingual file, a one-to-one corresponding initialization parameter is defined, 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.
5. The method according to any one of claims 1-4, characterized in that, Based on the first multilingual file, the key-value pairs corresponding to the invalid keys and the duplicate keys are hidden and / or removed, and an optimized second multilingual file is generated according to the template information of the valid keys, including: Create a new JSON object based on the first multilingual file; Hide and / or remove key-value pairs corresponding to invalid and duplicate keys from the set to be deleted in the new JSON object; Integrate the template information corresponding to each valid key in the temporary content set into a new JSON object; The file path processing package is used to define the generation location of the optimized second multilingual file; A new JSON object is saved using a file processing package as an optimized second multilingual file. The first and second multilingual files have the same filename, and the second multilingual file is generated at the file location indicated by the generation location.
6. The method according to claim 2, characterized in that, The method further includes: Using the file processing package, the import and export method of the first multilingual file is adjusted to adapt the import and export method of the first multilingual file to the Node.js runtime environment.
7. A multilingual document processing device, characterized in that, The device includes: The acquisition module is used to acquire the file information of the first multilingual file to be optimized from the file information queue, which records the file information of all multilingual files in the front-end project; A definition module is used to define initialization parameters based on the file information of the first multilingual file; The traversal module is used to traverse the file information queue, perform multilingual matching based on the initialization parameters, determine the valid keys, invalid keys, and duplicate keys in the first multilingual file, and collect the template information of the valid keys. The valid keys are keys that are referenced at least once in multiple multilingual files, the invalid keys are keys that are not referenced in any multilingual file, and the duplicate keys are keys that are repeated in the first multilingual file and have the same value. The generation 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 multilingual file, and generate an optimized second multilingual file according to the template information of the valid keys; The traversal module is further configured to: Using one of the multilingual languages as the main language, the initialization parameters of each key-value pair in the first multilingual file are read in a loop. The file information queue is iterated through in a loop, and the file information in the file information queue is matched with the multilingual key defined in the initialization parameters for multilingual matching. Whenever file information successfully matches a defined multilingual key, the key reference count corresponding to the currently matched multilingual key is incremented by 1, and the template information of the key corresponding to the successfully matched multilingual key is collected. The template information includes the multilingual key, multilingual value, key reference count, key reference position, and key version. Check the key reference count for all key-value pairs in the first multilingual file; For any key-value pair in the first multilingual file, if the key reference count is greater than 0, mark the key of the key-value pair as a valid key, collect the template information of the valid key, and add the collected template information of the valid key to the temporary content set. If the key reference count is less than 0, check if 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 the template information of the valid key, and add the collected template information of the valid key to a 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. Iterate through all key-value pairs in the first multilingual file and check if there are multiple key-value pairs with duplicate keys; If multiple key-value pairs have the same key and value, mark the key as a duplicate key and add the duplicate key to the set of items to be deleted.
8. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored on the memory, wherein the processor executes the computer program to implement the multilingual file processing method as described in any one of claims 1-6.
Citation Information
Patent Citations
Client multi-language dynamic configuration method and system
CN111240781A
Component data statistical method and device
CN114492324A
