File conversion method for structured data and related equipment

By automating the parsing and validation of structured data files to generate JSON files, the problem of low efficiency, error-proneness, and maintenance difficulties in existing technologies is solved, achieving efficient and accurate data conversion and format adaptation.

CN120849488APending Publication Date: 2025-10-28SHENZHEN LANYOU TECHNOLOGY CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510892196.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-10-28

AI Technical Summary

Technical Problem

Existing technologies are inefficient, error-prone, difficult to maintain, and have high technical barriers in the process of converting structured data files, making it difficult to adapt to flexible and ever-changing needs.

Method used

By obtaining the configuration file, parsing and validating the structured data based on preset validation rules, reading the worksheet into the target memory, traversing and converting it into intermediate data, and finally generating a JSON file, the automated process replaces manual operation. The configuration file defines conversion rules to adapt to format changes.

Benefits of technology

Significantly reduces processing time, minimizes human error, lowers maintenance costs, ensures data accuracy and standardization, adapts to different target formats, and supports rapid conversion of large volumes of data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120849488A_ABST
    Figure CN120849488A_ABST
Patent Text Reader

Abstract

The invention discloses a file conversion method for structured data and related equipment. The method comprises the following steps: acquiring a configuration file and to-be-processed structured data; analyzing the configuration file to obtain a configuration object; performing verification processing on the configuration object and the structured data based on a preset verification rule to obtain a verification result; when the verification result is passed, reading the worksheet from the structured data and loading the worksheet to a target memory; traversing each work table in the target memory, and converting the work table into intermediate data based on the configuration object; and based on the intermediate data, generating a JSON file according to a preset specification. According to the method, the problems of low efficiency, high error rate and poor maintainability of a traditional localization process can be solved, and efficient and accurate data processing is realized. The method can be widely applied to the technical field of data processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a method and related equipment for converting structured data into files. Background Technology

[0002] In the field of data processing, converting structured data files (such as spreadsheets, database export files, etc.) into localized file formats (such as JSON, XML, etc.) required by a specific target platform is a common requirement. Traditionally, such conversion processes have often relied heavily on manual operation. Technicians typically need to manually write specific scripts or programs to directly hard-code the conversion between the original data structure and the target format. Alternatively, a more primitive approach is for operators to directly open the original file (such as Excel), manually perform data processing, format adjustments, type conversions, and finally save it as a file in the target format.

[0003] This manual or semi-manual switching method has significant drawbacks:

[0004] 1. Inefficiency: Every time a new data structure is processed or the target format needs to be adapted, the conversion code / script needs to be rewritten or modified, or tedious manual operation steps need to be repeated, which consumes a lot of manpower and time costs, especially when processing large amounts of data, the bottleneck is obvious.

[0005] 2. High error rate: Manually writing complex conversion logic or performing manual operations can easily introduce errors, such as incorrect data mapping, missing fields, incorrect data type conversion, and non-standard formatting. These errors not only affect data quality but may also cause subsequent processing to fail.

[0006] 3. Difficult to maintain and poor scalability: Hard-coded conversion scripts are usually tightly coupled with specific source data structures and target formats. When the source data structure changes (such as adding / deleting columns, modifying field names) or the target platform requires new specifications, additional effort is needed to find and modify the code, resulting in high maintenance costs and difficulty in adapting to flexible and changing needs.

[0007] 4. High technical threshold and poor consistency: Manual coding requires developers to have high programming skills, and the conversion logic implemented by different developers may vary greatly, resulting in inconsistent output file formats and specifications, which affects the stable processing of downstream systems. Summary of the Invention

[0008] The main objective of this application is to provide a method, apparatus, electronic device, and storage medium for converting structured data into files, aiming to solve at least one problem in the prior art.

[0009] To achieve the above objectives, one aspect of this application proposes a method for converting structured data into files, the method comprising:

[0010] Obtain the configuration file and the structured data to be processed;

[0011] The configuration file is parsed to obtain the configuration object;

[0012] The configuration objects and structured data are validated based on preset validation rules to obtain validation results;

[0013] If the verification result is successful, the worksheet is read from the structured data and loaded into the target memory;

[0014] Iterate through each worksheet in the target memory and convert the worksheet into intermediate data based on the configuration object;

[0015] Based on intermediate data, a JSON file is generated according to a preset specification.

[0016] In some embodiments, the configuration file is pre-configured based on the target object. Parsing and loading the configuration file to obtain the configuration object includes the following steps:

[0017] The configuration loading module is used to read the configuration file, so that the configuration loading module can parse the configuration file and obtain the configuration object;

[0018] The configuration objects include the loading path for structured data, the output path for JSON files, table header information, and column mapping relationships;

[0019] Among them, the column mapping relationship represents the mapping relationship between the target language data and its corresponding column identifier in the structured data.

[0020] In some embodiments, the configuration object includes a column mapping relationship, which represents the mapping relationship between the target language data and its corresponding column identifier in the structured data. The configuration object and the structured data are validated based on preset validation rules, including at least one of the following steps:

[0021] Perform column mapping integrity verification on structured data based on column mapping relationships;

[0022] Among them, column mapping integrity verification includes verifying whether the target language data exists in the structured data and is not empty, and verifying whether the column identifiers in the structured data conform to the preset valid rules;

[0023] Data consistency verification is performed on structured data based on column mapping relationships;

[0024] Data consistency verification includes verifying the uniqueness of the key column corresponding to the target language data, detecting whether the key field is empty, and verifying the data type consistency of the key column in different language columns.

[0025] In some embodiments, the configuration object includes the loading path and header information of the structured data. Loading the worksheet from the structured data into the target memory includes the following steps:

[0026] Based on the loading path and header information, multilingual data is read from the structured data;

[0027] Multilingual data is loaded and stored into the target memory based on a dictionary data structure;

[0028] The dictionary data structure includes multiple worksheets, each corresponding to a list of rows in the structured data. Each row in the worksheet stores column values ​​in dictionary form.

[0029] In some embodiments, the configuration object includes header information and column mapping relationships. The column mapping relationships characterize the mapping relationship between the target language data and its corresponding column identifiers in the structured data. Converting the worksheet into intermediate data based on the configuration object includes the following steps:

[0030] Locate the header of the worksheet based on the header information, and then determine the original mapping relationship between each column in the worksheet and the language.

[0031] Iterate through the rows of data in the worksheet and extract the value of the key column as a unique identifier;

[0032] Based on the original mapping relationship, the values ​​of each language column are extracted from the worksheet, and then the standard fields of the preset standard are generated as intermediate data according to the column mapping relationship;

[0033] Specifically, when there are empty cells or cells with abnormal formatting in the worksheet, the pre-configured log operation will record and report them.

[0034] In some embodiments, the method further includes the following steps:

[0035] Based on pre-configured log operations, the data status and corresponding timestamps of the target data are recorded and reported.

[0036] The target data includes configuration objects, validation results, worksheets, intermediate data, and JSON files.

[0037] To achieve the above objectives, another aspect of this application provides a structured data file conversion apparatus, the apparatus comprising:

[0038] The main module is used to obtain configuration files and structured data to be processed;

[0039] The configuration loading module is used to parse the configuration file and obtain the configuration object;

[0040] The verification module is used to perform verification processing on configuration objects and structured data based on preset verification rules, and obtain verification results;

[0041] The read module is used to read the worksheet from the structured data and load it into the target memory when the verification result is passed;

[0042] The worksheet processing module is used to traverse each worksheet in the target memory and convert the worksheet into intermediate data based on the configuration object.

[0043] The JSON generation module is used to generate JSON files based on intermediate data and according to preset specifications.

[0044] In some embodiments, the apparatus further includes:

[0045] The logging module is used to record and report the data status and corresponding timestamps of the target data based on pre-configured logging operations.

[0046] The target data includes configuration objects, validation results, worksheets, intermediate data, and JSON files.

[0047] To achieve the above objectives, another aspect of the embodiments of this application proposes an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the aforementioned method.

[0048] To achieve the above objectives, another aspect of the embodiments of this application proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned method.

[0049] To achieve the above objectives, another aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the aforementioned method.

[0050] The embodiments of this application include at least the following beneficial effects: This application provides a method, apparatus, electronic device, storage medium, and program product for converting structured data into files. This solution obtains a configuration file and structured data to be processed; parses the configuration file to obtain a configuration object; performs verification processing on the configuration object and structured data based on preset verification rules to obtain a verification result; when the verification result is passed, reads a worksheet from the structured data and loads it into the target memory; traverses each worksheet in the target memory and converts the worksheet into intermediate data based on the configuration object; and generates a JSON file based on the intermediate data according to a preset specification. This application automates the data reading, parsing, verification, transformation, and generation processes, replacing tedious and error-prone manual operations and significantly shortening processing time, making it particularly suitable for the rapid transformation of large volumes of data. Furthermore, this application automates the verification of configurations and data sources based on preset verification rules, minimizing errors introduced by human intervention and ensuring the accuracy and standardization of output data. Transformation rules and mapping relationships are defined through configuration files rather than hard-coded. When the source data structure or target format requirements change, typically only the configuration file needs to be modified, without altering the core program code, greatly reducing maintenance costs and complexity. In addition, by first converting worksheet data into intermediate data and then generating the final JSON file according to preset specifications, the transformation logic and the final output format are decoupled, making it easier to adapt to different target specifications or add new output formats. Attached Figure Description

[0051] Figure 1 This is a schematic diagram of an implementation environment for the file conversion method for structured data provided in this application embodiment;

[0052] Figure 2 This is a flowchart illustrating a method for converting structured data into files, as provided in an embodiment of this application.

[0053] Figure 3 This is a schematic diagram illustrating a specific organizational form of intermediate data provided in the embodiments of this application;

[0054] Figure 4 This is a schematic diagram of the business process of a file conversion method for structured data provided in an embodiment of this application;

[0055] Figure 5 This is a schematic diagram of the structure of a file conversion device for structured data provided in an embodiment of this application;

[0056] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0057] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit it. In the following description, when referring to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with those of this application; they are merely examples of apparatuses and methods consistent with some aspects of the embodiments of this application as detailed in the appended claims.

[0058] It is understood that the terms “first,” “second,” etc., used in this application may be used herein to describe various concepts, but unless otherwise stated, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the embodiments of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the words “if,” “when,” or “in response to a determination” as used herein may be interpreted as “when…” or “when…” or “in response to a determination.”

[0059] As used in this application, the terms "at least one", "multiple", "each", "any", etc., "at least one" includes one, two or more, "multiple" includes two or more, "each" refers to each of the corresponding multiples, and "any" refers to any one of the multiples.

[0060] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0061] In related technologies, converting structured data files (such as spreadsheet files, database export files, etc.) into localized file formats (such as JSON, XML, etc.) required by a specific target platform is a common requirement. Traditionally, such conversion processes have often relied heavily on manual operation.

[0062] In view of this, this application provides a method for converting structured data into files. This method involves: obtaining a configuration file and the structured data to be processed; parsing the configuration file to obtain a configuration object; performing verification processing on the configuration object and the structured data based on preset verification rules to obtain a verification result; when the verification result is passed, reading the worksheet from the structured data and loading it into the target memory; traversing each worksheet in the target memory and converting the worksheet into intermediate data based on the configuration object; and generating a JSON file based on the intermediate data according to preset specifications. This application automates the data reading, parsing, verification, transformation, and generation processes, replacing tedious and error-prone manual operations and significantly shortening processing time, making it particularly suitable for the rapid transformation of large volumes of data. Furthermore, this application automates the verification of configurations and data sources based on preset verification rules, minimizing errors introduced by human intervention and ensuring the accuracy and standardization of output data. Transformation rules and mapping relationships are defined through configuration files rather than hard-coded. When the source data structure or target format requirements change, typically only the configuration file needs to be modified, without altering the core program code, greatly reducing maintenance costs and complexity. In addition, by first converting worksheet data into intermediate data and then generating the final JSON file according to preset specifications, the transformation logic and the final output format are decoupled, making it easier to adapt to different target specifications or add new output formats.

[0063] It is understood that the structured data file conversion method provided in this application can be applied to any computer device with data processing and computing capabilities, and this computer device can be various terminals or servers. When the computer device in the embodiment is a server, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal can be a smartphone, tablet, laptop, or desktop computer, but it is not limited to these.

[0064] like Figure 1 The diagram shown is a schematic representation of an implementation environment provided in an embodiment of this application. (Refer to...) Figure 1 The implementation environment includes at least one terminal 102 and a server 101. The terminal 102 and the server 101 can be connected via a network, either wirelessly or via a wired connection, to complete data transmission and exchange.

[0065] Server 101 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0066] Additionally, server 101 can also be a node server in a blockchain network. Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms.

[0067] Terminal 102 can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. Terminal 102 and server 101 can be directly or indirectly connected via wired or wireless communication, and this embodiment of the application does not impose any limitations.

[0068] For example, based on Figure 1 The implementation environment shown in this application embodiment provides a method for converting structured data into files. The following description uses the application of this method in server 101 as an example. It can be understood that this method can also be applied in terminal 102.

[0069] Reference Figure 2 , Figure 2 This is an optional flowchart of a method for converting structured data into files provided in this application embodiment. The execution subject of this method can be any of the aforementioned computer devices (including servers or terminals). Figure 2 The method may include, but is not limited to, steps S100 to S600.

[0070] Step S100: Obtain the configuration file and the structured data to be processed;

[0071] For example, in some specific implementations, the main module can pre-collect or receive user-inputted configuration files and structured data to be processed. Specifically, the structured data files include spreadsheet files, database export files, etc. In subsequent embodiments, the structured text will be uniformly represented as an Excel file, and the example will be illustrated using the Localizable.xcstrings format, which is based on the iOS localization specification.

[0072] Step S200: Parse the configuration file to obtain the configuration object;

[0073] It should be noted that the configuration file is pre-configured based on the target object. In some embodiments, step S200 may include the following steps: using the configuration loading module to read the configuration file so that the configuration loading module parses the configuration file to obtain the configuration object; wherein, the configuration object includes the loading path of the structured data, the output path of the JSON file, the header information, and the column mapping relationship; wherein, the column mapping relationship represents the mapping relationship between the target language data and its corresponding column identifier in the structured data.

[0074] For example, in some specific embodiments, step S200 can be implemented by a configuration loading module (ConfigLoader). Specifically, the functions and features of this module are as follows:

[0075] Functionality: This module reads a JSON-formatted configuration file and parses it to obtain parameters such as the path to the loaded Excel file, the path to the output JSON file, the source language, the version number, the header row numbers, and column mapping relationships (these parameters are pre-configured by the user; this module primarily retrieves them from the configuration file). Column mapping relationships are represented as a set of key-value pairs, where the key is the target language code (e.g., "en", "zh-Hans") or the special identifier "key" (representing the key column), and the value is the column identifier corresponding to that language data in Excel (which can be a column letter or column name, such as "C", "zh-Hans", "en", "English").

[0076] Features: Supports dynamic configuration, allowing users to flexibly define the mapping relationship between column names and languages ​​in the configuration file, adapting to different Excel formats and language configuration requirements without modifying the code.

[0077] Step S300: Perform verification processing on the configuration object and structured data based on preset verification rules to obtain the verification result;

[0078] It should be noted that the configuration object includes column mapping relationships, which represent the mapping relationship between the target language data and its corresponding column identifier in the structured data. In some embodiments, the configuration object and the structured data are validated based on preset validation rules, including at least one of the following steps: performing column mapping integrity verification on the structured data based on the column mapping relationships; wherein, the column mapping integrity verification includes verifying whether the target language data exists in the structured data and is not empty, and verifying whether the column identifier in the structured data conforms to preset valid rules; performing data consistency verification on the structured data based on the column mapping relationships; wherein, the data consistency verification includes verifying the uniqueness of the key column corresponding to the target language data, detecting whether the key field is empty, and verifying the data type consistency of the key column in different language columns.

[0079] For example, in some specific embodiments, step S300 can be implemented by a validation module (Validator). Specifically, the module implements the following functions and features:

[0080] Function: Perform format and content validation on configuration files and Excel files. The specific validation rules are as follows:

[0081] Column mapping integrity verification: Check that all target language columns defined in the configuration file actually exist in the specified worksheet of Excel; verify that the column used as the "key" exists and is not empty; check that the column identifiers defined in the mapping relationship are valid in Excel (the column letters do not exceed the maximum number of columns, and the column names exist in the header row).

[0082] Data consistency verification: Ensure the uniqueness of the key column (Key) to prevent duplicate keys; check that key fields (such as the key column and the source language column) are not null; verify the consistency of data type (mainly string type) for the same key in different language columns.

[0083] Features: Provides detailed error messages, making it easy for users to quickly locate problems.

[0084] Step S400: When the verification result is passed, read the worksheet from the structured data and load it into the target memory;

[0085] It should be noted that the configuration object includes the loading path and header information of the structured data. In some embodiments, reading the worksheet from the structured data and loading it into the target memory includes the following steps: reading the multilingual data in the structured data based on the loading path and header information; loading and storing the multilingual data into the target memory based on the dictionary data structure; wherein, the dictionary data structure includes multiple worksheets, each worksheet corresponding to a row list in the structured data, and each row of data in the worksheet stores column values ​​in dictionary form.

[0086] For example, in some specific embodiments, step S400 can be implemented by an Excel reading module (ExcelReader). Specifically, the functions and features of this module are as follows:

[0087] Function: Reads multilingual data from an Excel file based on the path and header information in the configuration file, and supports processing multiple worksheets.

[0088] Features: Supports multiple Excel file formats (such as .xlsx, .xls) and can handle complex cell content (such as merged cells). The module outputs / stores data in memory as a dictionary containing multiple worksheets. Each worksheet corresponds to a row list, and each row's data stores column values ​​in dictionary form. The specific structure is as follows:

[0089]

[0090] Step S500: Traverse each worksheet in the target memory and convert the worksheet into intermediate data based on the configuration object;

[0091] It should be noted that the configuration object includes header information and column mapping relationships. The column mapping relationship represents the mapping relationship between the target language data and its corresponding column identifier in the structured data. In some embodiments, the worksheet is converted into intermediate data based on the configuration object, including the following steps: locating the header of the worksheet according to the header information, and then determining the original mapping relationship between each column in the worksheet and the language; traversing the row data of the worksheet and extracting the value of the key column as a unique identifier; extracting the value of each language column from the worksheet based on the original mapping relationship, and then generating a pre-defined standard field as intermediate data according to the column mapping relationship; wherein, when there are empty cells or cells with abnormal format in the worksheet, they are recorded and reported through pre-configured log operations.

[0092] For example, in some specific embodiments, step S500 can be implemented by a worksheet processing module (SheetProcessor). Specifically, the functions and features of this module are as follows:

[0093] Function: Parses, cleans, and transforms the data in each worksheet to generate an intermediate data structure conforming to the Localizable.xcstrings format.

[0094] Features: Supports multilingual key-value pair extraction and handles null values ​​or abnormal formatting. For example... Figure 3 The image shows a structural example of a specific organization of intermediate data (this is for illustrative purposes only and should not be construed as a limitation of this application). The specific steps for this module to generate multilingual key-value pairs for a single key from raw Excel row data can be implemented as follows:

[0095] 1. Locate the table header based on the header_row in the configuration information and determine the mapping relationship between each column and the language;

[0096] 2. Traverse the Excel rows and extract the key column values ​​as unique identifiers;

[0097] 3. Based on the configured column mapping relationship, extract the values ​​of each language column and generate the corresponding localizations field;

[0098] 4. When processing empty cells, mark the corresponding language's state as "untranslated"; when encountering cells with abnormal formatting (such as containing illegal characters), log the error and decide whether to skip or prompt the user to correct it based on the configuration.

[0099] Step S600: Based on the intermediate data, generate a JSON file according to a preset specification;

[0100] For example, in some specific embodiments, step S600 can be implemented by a JSON generation module (JSONWriter). Specifically, the module implements the following functions and features:

[0101] Function: Converts the processed intermediate data into a JSON file in Localizable.xcstrings format and saves it to the specified path.

[0102] Features: Supports format validation to ensure output files conform to iOS native specifications. The specific object of format validation is the intermediate data structure in memory, and the validation rules are based on the specific clauses and structural requirements of the iOS specifications, including:

[0103] Ensure that the generated JSON data includes required fields such as sourceLanguage, version, and strings;

[0104] Each key under strings contains extractionState and localizations;

[0105] Each language code in the localizations conforms to the ISO 639-1 standard;

[0106] stringUnit contains state (translated / untranslated) and value fields;

[0107] The generated JSON string conforms to the RFC 8259 standard and has no syntax errors.

[0108] It should be noted that, in some embodiments, the method may further include the following steps: based on pre-configured log operations, recording and reporting the data status and corresponding timestamps of the target data; wherein, the target data includes configuration objects, verification results, worksheets, intermediate data, and JSON files.

[0109] For example, in some specific implementations, recording and reporting based on pre-configured log operations can be achieved through a logger module. Specifically, the functions and features of this module are as follows:

[0110] Function: Records key steps, status changes, and exception information during system operation, and supports log output to the console or file.

[0111] Features: Provides timestamp and module-level log hierarchies for easy debugging and maintenance.

[0112] To explain in detail the principles of the technical solution of this application, the overall process of this application will be described below with reference to some specific embodiments. It is easy to understand that the following is an explanation of the technical principles of this application and should not be regarded as a limitation of this application.

[0113] First, it's important to note that with the increasing prevalence of globalized software development, multilingual localization has become a crucial step in adapting applications to different language environments. Typically, development teams use Excel files to manage multilingual translations, then manually convert them to the localized file formats required by the target platform, such as Localizable.xcstrings files for iOS. However, this manual conversion process has the following problems:

[0114] 1. Inefficient: Large amounts of translation data need to be processed one by one, which is time-consuming and highly repetitive;

[0115] 2. Prone to errors: Manual operation is prone to formatting errors or data omissions;

[0116] 3. Difficult to maintain: Lack of a systematic error recording and tracking mechanism, resulting in low efficiency in troubleshooting.

[0117] Furthermore, while existing automation tools can partially solve the above problems, they still have limitations, such as:

[0118] 4. Insufficient adaptability: Difficult to handle diverse Excel file formats;

[0119] 5. Poor format compatibility: Cannot directly generate files conforming to the iOS Localizable.xcstrings specification;

[0120] 6. Lack of robustness: The lack of data validation and operation log functions leads to insufficient system reliability.

[0121] Therefore, developing an efficient, flexible, and stable automated conversion system has become an urgent need in the field of multilingual localization.

[0122] In view of this, the purpose of this application is to provide a technical solution for automated conversion. Specifically, the file conversion method for structured data in this application can be implemented through the following system architecture, which includes the following core components:

[0123] 1. Configuration Loader Module:

[0124] Functionality: Reads a JSON-formatted configuration file and parses it to obtain parameters such as the path to the loaded Excel file, the path to the output JSON file, the source language, the version number, the header row numbers, and the column mapping relationships. The column mapping relationships are in the form of a key-value pair set, where the key is the target language code (e.g., "en", "zh-Hans") or the special identifier "key" (representing the key column), and the value is the column identifier corresponding to that language data in Excel (which can be a column letter or column name, such as "C", "zh-Hans", "en", "English").

[0125] Features: Supports dynamic configuration, allowing users to flexibly define the mapping relationship between column names and languages ​​in the configuration file, adapting to different Excel formats and language configuration requirements without modifying the code.

[0126] 2. Validation Module (Validator):

[0127] Function: Perform format and content validation on configuration files and Excel files. The specific validation rules are as follows:

[0128] Column mapping integrity verification: Check that all target language columns defined in the configuration file actually exist in the specified worksheet of Excel; verify that the column used as the "key" exists and is not empty; check that the column identifiers defined in the mapping relationship are valid in Excel (the column letters do not exceed the maximum number of columns, and the column names exist in the header row).

[0129] Data consistency verification: Ensure the uniqueness of the key column (Key) to prevent duplicate keys; check that key fields (such as the key column and the source language column) are not null; verify the consistency of data type (mainly string type) for the same key in different language columns.

[0130] Features: Provides detailed error messages, making it easy for users to quickly locate problems.

[0131] 3. Excel Reading Module (ExcelReader):

[0132] Function: Reads multilingual data from an Excel file based on the path and header information in the configuration file, and supports processing multiple worksheets.

[0133] Features: Supports multiple Excel file formats (such as .xlsx, .xls) and can handle complex cell content (such as merged cells). The module outputs / stores data in memory as a dictionary containing multiple worksheets. Each worksheet corresponds to a row list, and each row's data stores column values ​​in dictionary form. The specific structure is as follows:

[0134]

[0135] 4. SheetProcessor module:

[0136] Function: Parses, cleans, and transforms the data in each worksheet to generate an intermediate data structure conforming to the Localizable.xcstrings format.

[0137] Features: Supports multilingual key-value pair extraction and handles null values ​​or format errors. The specific organization of the intermediate data structure is as follows: Figure 3 As shown.

[0138] The specific steps of this module to generate multilingual key-value pairs from raw Excel row data are as follows:

[0139] 1. Locate the table header based on the header_row in the configuration information and determine the mapping relationship between each column and the language;

[0140] 2. Traverse the Excel rows and extract the key column values ​​as unique identifiers;

[0141] 3. Based on the configured column mapping relationship, extract the values ​​of each language column and generate the corresponding localizations field;

[0142] 4. When processing empty cells, mark the corresponding language's state as "untranslated"; when encountering cells with abnormal formatting (such as containing illegal characters), log the error and decide whether to skip or prompt the user to correct it based on the configuration.

[0143] 5. JSON generation module (JSONWriter):

[0144] Function: Converts the processed intermediate data into a JSON file in Localizable.xcstrings format and saves it to the specified path.

[0145] Features: Supports format validation to ensure output files conform to iOS native specifications. The specific object of format validation is the intermediate data structure in memory, and the validation rules are based on the specific clauses and structural requirements of the iOS specifications, including:

[0146] Ensure that the generated JSON data includes required fields such as sourceLanguage, version, and strings;

[0147] Each key under strings contains extractionState and localizations;

[0148] Each language code in the localizations conforms to the ISO 639-1 standard;

[0149] stringUnit contains state (translated / untranslated) and value fields;

[0150] The generated JSON string conforms to the RFC 8259 standard and has no syntax errors.

[0151] 6. Logger module:

[0152] Function: Records key steps, status changes, and exception information during system operation, and supports log output to the console or file.

[0153] Features: Provides timestamp and module-level log hierarchies for easy debugging and maintenance.

[0154] In some specific implementations, such as Figure 4 As shown, based on the above system architecture, the workflow of the structured data file conversion method of this application can be implemented as follows:

[0155] Step 1: The main module is initialized, and the configuration loading module is called to read the configuration file and return the configuration object.

[0156] Step 2: The main module passes the configuration object to the verification module, performs integrity verification of the configuration and Excel file, and returns the verification result.

[0157] Step 3: If the verification passes, the main module calls the Excel reading module to load the Excel file data into memory.

[0158] Step 4: The main module iterates through each worksheet, calls the worksheet processing module to extract and transform data, and generates intermediate JSON data.

[0159] Step 5: The main module passes the intermediate data to the JSON generation module to generate the final Localizable.xcstrings file.

[0160] Step 6: During operation, each module records operation logs through the log module to ensure process traceability.

[0161] Specifically, the data flow involved in this application embodiment includes:

[0162] Input: Excel file (containing multilingual data) + JSON configuration file.

[0163] Output: A JSON file conforming to the iOS Localizable.xcstrings specification.

[0164] Intermediate data: A temporary data structure in key-value pair form used to store the results of worksheet processing.

[0165] In some specific application scenarios, based on the aforementioned system architecture, the file conversion method for structured data in this application can be implemented as follows:

[0166] 1. Configuration Loading: The main module can parse the configuration file and return a configuration object containing information such as path and language by calling the relevant functions pre-configured by the configuration loading module (e.g., ConfigLoader.load_config('config.json', the specific implementation logic is as described in the previous implementation of this module).

[0167] 2. Validation process: Call the relevant functions pre-configured in the validation module (e.g., Validator.validate_config(config,excel_format), the specific implementation logic is as described in the previous implementation of this module, and will not be repeated here), to check whether the path in the configuration file exists, whether the Excel file is readable, and whether the column mapping is complete.

[0168] 3. Data Reading: Call the relevant functions pre-configured in the Excel reading module (e.g., ExcelReader.read_excel(config), the specific implementation logic is as described in the previous implementation of this module, and will not be repeated here) to read the Excel file and generate an object containing all worksheet data.

[0169] 4. Data Processing: For each worksheet, call the relevant functions pre-configured in the worksheet processing module (e.g., SheetProcessor.process_sheet(sheet_data,config), the specific implementation logic of which is described in the previous implementation of this module and will not be repeated here), extract the key-value pairs and convert them into a JSON structure.

[0170] 5. File generation: Call the relevant functions pre-configured in the JSON generation module (e.g., JSONWriter.write_json(data,output_path), the specific implementation logic of which is described in the previous implementation of this module and will not be repeated here) to generate the Localizable.xcstrings file.

[0171] 6. Log Recording: Each module records operation details, such as "Configuration loaded successfully" and "Excel data read completed", through the relevant functions pre-configured in the logging module (e.g., Logger.log(level, message), the specific implementation logic of which is described in the previous implementation of this module).

[0172] In some specific application scenarios, the following examples, using configuration files and Excel files, illustrate the effects of the method implementation in this application:

[0173] Here is an example of a configuration file:

[0174]

[0175]

[0176] Assume the Excel file contains data as shown in Table 1 below:

[0177] Table 1

[0178] Translation Key English Simplified Chinese French WELCOME Welcome to the app Welcome to this application Bienvenue SETTINGS Settings set up Paramètres

[0179] The Localizable.xcstrings file generated after conversion based on the method and process of this application is as follows:

[0180]

[0181]

[0182] In some optional implementations, if a column in the Excel file is missing, the verification module will return an error, and the logging module will record the following:

[0183] [ERROR]2023-10-15 10:00:00-Validator:Column'zh-Hans'not found inExcelsheet'Sheet1'.

[0184] [INFO]2023-10-15 10:00:01-Main:Process terminated due to validationfailure.

[0185] In summary, the structured data file conversion provided in this application can be applied to structured data file conversion scenarios. Specifically, it can be applied to convert multilingual data in Excel files into iOSLocalizable.xcstrings files, solving the problems of low efficiency, high error rate and poor maintainability of traditional localization processes, and achieving efficient and accurate processing of multilingual data.

[0186] like Figure 5 As shown in the illustration, this application also provides a structured data file conversion apparatus 900, which can implement the above-described method. The apparatus includes:

[0187] Main module 901 is used to obtain configuration files and structured data to be processed;

[0188] The configuration loading module 902 is used to parse the configuration file and obtain the configuration object;

[0189] The verification module 903 is used to perform verification processing on the configuration object and structured data based on preset verification rules to obtain the verification result;

[0190] The read module 904 is used to read the worksheet from the structured data and load it into the target memory when the verification result is passed;

[0191] The worksheet processing module 905 is used to traverse each worksheet in the target memory and convert the worksheet into intermediate data based on the configuration object.

[0192] JSON generation module 906 is used to generate JSON files based on intermediate data and according to preset specifications.

[0193] In some embodiments, the apparatus further includes:

[0194] The logging module is used to record and report the data status and corresponding timestamps of the target data based on pre-configured logging operations.

[0195] The target data includes configuration objects, validation results, worksheets, intermediate data, and JSON files. It is understood that the content of the above method embodiments is applicable to this device embodiment, and the specific functions implemented in this device embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.

[0196] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0197] It is understood that the content of the above method embodiments is applicable to this device embodiment. The specific functions implemented by this device embodiment are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0198] like Figure 6 As shown, Figure 6 The hardware structure of an electronic device 1000 according to another embodiment is illustrated. The electronic device 1000 includes:

[0199] The processor 1001 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (aSIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.

[0200] The memory 1002 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RaM). The memory 1002 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1002 and is called and executed by the processor 1001.

[0201] Input / output interface 1003 is used to implement information input and output;

[0202] The communication interface 1004 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0203] Bus 1005 transmits information between various components of the device (e.g., processor 1001, memory 1002, input / output interface 1003, and communication interface 1004);

[0204] The processor 1001, memory 1002, input / output interface 1003 and communication interface 1004 are connected to each other within the device via bus 1005.

[0205] The electronic device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0206] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.

[0207] It is understood that the content of the above method embodiments is applicable to this storage medium embodiment. The specific functions implemented in this storage medium embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.

[0208] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0209] It is understood that the content of the above method embodiments is applicable to the embodiments of this program product. The specific functions implemented by the embodiments of this program product are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0210] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0211] The method, apparatus, electronic device, storage medium, and program product for converting structured data provided in this application embodiment acquire a configuration file and structured data to be processed; parse the configuration file to obtain a configuration object; perform verification processing on the configuration object and structured data based on preset verification rules to obtain a verification result; when the verification result is passed, read the worksheet from the structured data and load it into the target memory; traverse each worksheet in the target memory and convert the worksheet into intermediate data based on the configuration object; and generate a JSON file based on the intermediate data according to a preset specification. This application automates the data reading, parsing, verification, transformation, and generation processes, replacing tedious and error-prone manual operations and significantly shortening processing time, making it particularly suitable for the rapid transformation of large volumes of data. Furthermore, this application automates the verification of configurations and data sources based on preset verification rules, minimizing errors introduced by human intervention and ensuring the accuracy and standardization of output data. Transformation rules and mapping relationships are defined through configuration files rather than hard-coded. When the source data structure or target format requirements change, typically only the configuration file needs to be modified, without altering the core program code, greatly reducing maintenance costs and complexity. In addition, by first converting worksheet data into intermediate data and then generating the final JSON file according to preset specifications, the transformation logic and the final output format are decoupled, making it easier to adapt to different target specifications or add new output formats.

[0212] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0213] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0214] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0215] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0216] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0217] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0218] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0219] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0220] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0221] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0222] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A method for converting structured data into files, characterized in that, The method includes the following steps: Obtain the configuration file and the structured data to be processed; The configuration file is parsed to obtain a configuration object; The configuration object and the structured data are validated based on preset validation rules to obtain validation results; If the verification result is successful, the worksheet is read from the structured data and loaded into the target memory; Iterate through each of the worksheets in the target memory and convert the worksheets into intermediate data based on the configuration object; Based on the intermediate data, a JSON file is generated according to a preset specification.

2. The method according to claim 1, characterized in that, The configuration file is pre-configured based on the target object. The process of parsing and loading the configuration file to obtain the configuration object includes the following steps: The configuration loading module is used to read the configuration file, so that the configuration loading module can parse the configuration file to obtain the configuration object; The configuration object includes the loading path of the structured data, the output path of the JSON file, the table header information, and the column mapping relationship; The column mapping relationship represents the mapping relationship between the target language data and its corresponding column identifier in the structured data.

3. The method according to claim 1, characterized in that, The configuration object includes column mapping relationships, which represent the mapping relationship between target language data and its corresponding column identifiers in the structured data. The verification process of the configuration object and the structured data based on preset verification rules includes at least one of the following steps: Column mapping integrity verification is performed on the structured data based on the column mapping relationship; The column mapping integrity verification includes verifying whether the target language data exists in the structured data and is not empty, and verifying whether the column identifier in the structured data conforms to a preset valid rule. Data consistency verification is performed on the structured data based on the column mapping relationship; The data consistency verification includes verifying the uniqueness of the key column corresponding to the target language data, detecting whether the key field is empty, and verifying the data type consistency of the key column in different language columns.

4. The method according to claim 1, characterized in that, The configuration object includes the loading path and header information of the structured data. The step of reading the worksheet from the structured data and loading it into the target memory includes the following steps: Based on the loading path and the header information, read the multilingual data from the structured data; The multilingual data is loaded and stored into the target memory based on a dictionary data structure; The dictionary data structure includes multiple worksheets, each worksheet corresponding to a row list in the structured data, and each row of data in the worksheet stores column values ​​in dictionary form.

5. The method according to claim 1, wherein The configuration object includes header information and column mapping relationships. The column mapping relationships represent the mapping relationship between the target language data and its corresponding column identifiers in the structured data. The process of converting the worksheet into intermediate data based on the configuration object includes the following steps: Based on the header information, locate the header of the worksheet, and then determine the original mapping relationship between each column in the worksheet and the language; Traverse the rows of data in the worksheet and extract the values ​​of the key columns as unique identifiers; Based on the original mapping relationship, the values ​​of each language column are extracted from the worksheet, and then the standard field of the preset standard is generated as the intermediate data according to the column mapping relationship; Specifically, when there are empty cells or cells with abnormal formatting in the worksheet, the data is recorded and reported through a pre-configured log operation.

6. The method according to any one of claims 1 to 5, characterized in that, The method further includes the following steps: Based on pre-configured log operations, the data status and corresponding timestamps of the target data are recorded and reported. The target data includes the configuration object, the verification result, the worksheet, the intermediate data, and the JSON file.

7. A file conversion device for structured data, characterized in that, The device includes: The main module is used to obtain configuration files and structured data to be processed; A configuration loading module is used to parse the configuration file to obtain a configuration object; The verification module is used to perform verification processing on the configuration object and the structured data based on preset verification rules, and obtain the verification result; The reading module is used to read a worksheet from the structured data and load it into the target memory when the verification result is passed; The worksheet processing module is used to traverse each worksheet in the target memory and convert the worksheet into intermediate data based on the configuration object; The JSON generation module is used to generate a JSON file based on the intermediate data according to a preset specification.

8. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method according to any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 6.

Citation Information

Cited By

  • Method and system for converting low-code deployment configuration into Kubernetes standard resource file

    CN121326333A

  • A method and system for converting a low-code deployment configuration to a kubernetes standard resource file

    CN121326333B