Translation import method, readable storage medium and electronic equipment
By directly reading translation entries from translation documents through COM interfaces or file read/write libraries, the problem of inconvenient configuration of encrypted documents is solved, and the convenience and accuracy of string resource file configuration are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GREAT WALL MOTOR CO LTD
- Filing Date
- 2026-01-26
- Publication Date
- 2026-05-12
Smart Images

Figure CN122021671A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software development technology, and more specifically, to a translation import method, a readable storage medium, and an electronic device in the field of software development technology. Background Technology
[0002] During software development, to make the software compatible with users of different languages, multiple string resource files need to be configured. Each string resource file stores the text content in one language that is visible to users in the software. Configuring these string resource files first requires obtaining translation documents written by translators, and then importing the translation entries from these documents into the string resource files to complete the configuration.
[0003] Typically, translation documents are encrypted, requiring authorization during the configuration of string resource files before they can be opened. This authorization process is cumbersome and time-consuming, causing significant inconvenience to the string resource file configuration process. Summary of the Invention
[0004] This application provides a translation import method, a readable storage medium, and an electronic device, which can improve the convenience of the string resource file configuration process.
[0005] In a first aspect, a translation import method is provided, the method comprising: determining whether the translation document is an encrypted document; if so, reading the translation document by calling a spreadsheet program through a component object model interface to obtain multiple translation entries included in the translation document; if not, reading the translation document through a file read / write library to obtain the multiple translation entries; and importing the multiple translation entries into N string resource files, where N is greater than or equal to 1.
[0006] In this embodiment, during the translation import process, when the translation document is determined to be an encrypted document, a spreadsheet program is called via a COM interface to read the translation document and obtain multiple translation entries. When the translation document is determined to be an unencrypted document, a file read / write library is used to read the translation document and obtain multiple translation entries. These multiple translation entries are then imported into N string resource files. In this method, when the translation document is encrypted, reading multiple translation entries via a spreadsheet program using a COM interface bypasses the authorization application process, thereby improving the convenience of configuring string resource files.
[0007] Optionally, importing the plurality of translation entries into N string resource files includes: for each string resource file, using regular expressions to read the key name and original string value of each string entry from the string resource file; for each string entry, determining the corresponding target string value from the plurality of translation entries based on the key name; and when the original string value is different from the target string value, replacing the original string value in the string resource file with the target string value.
[0008] In this embodiment, regular expressions are used to read key names and original string values from the string resource file, which prevents automatic escaping and formatting of the read original string values during the reading process. Furthermore, when there is a difference between the literal values of the target string value and the original string value, the target string value is used to replace the original string value, which reduces the need for modification to the string resource file and thus lowers the probability of errors during the translation and import process.
[0009] Optionally, before determining the corresponding target string value from the plurality of translation entries based on the key name, the method further includes: determining whether the user has pre-set a corresponding key name prefix for the string resource file; if the key name prefix has been pre-set for the string resource file, then adding the key name prefix to the key name.
[0010] In this embodiment of the application, when the user has set a key name prefix for the string resource file in advance, the key name prefix is added to the key name, and then the translation entries are imported into the string resource file based on the key name with the added key name prefix, which makes it convenient for the user to flexibly import translation entries according to the actual situation.
[0011] Optionally, after replacing the original string value in the string resource file with the target string value, the method further includes: for each string resource file, determining whether the string value in the string resource file includes an unescaped character; if the unescaped character is included, then escaping the unescaped character into an escaped character.
[0012] In this embodiment of the application, after importing the translation entries into the string resource file, the string resource file is checked to identify unescaped characters and escaped them. This avoids the string resource file from being used while carrying unescaped characters, thereby improving the reliability of the string resource file.
[0013] Optionally, the N string resource files include a first string resource file for a base language and at least one second string resource file for other languages; after replacing the original string value in the string resource files with the target string value, the method further includes: obtaining placeholders from each string entry in the first string resource file to obtain a first placeholder sequence corresponding to each string entry; for each second string resource file, obtaining placeholders from each string entry in the second string resource file to obtain a second placeholder sequence corresponding to each string entry; for the first placeholder sequence and the second placeholder sequence corresponding to two string entries with the same key name, when the first placeholder sequence and the second placeholder sequence are different, outputting a first detection result, wherein the first detection result indicates that the placeholders in the two string entries with the same key name are inconsistent.
[0014] In this embodiment, after the translation and import are completed, the placeholders in each string entry of the string resource file corresponding to languages other than the base language are checked to determine whether there are errors in the placeholders in the string entries. If there are errors, the first detection result is output, which can facilitate users to modify the placeholders in a timely manner, so as to avoid configuring string resources with erroneous placeholders to the software, thereby reducing the probability of software abnormalities.
[0015] Optionally, the N string resource files include a first string resource file for a base language and at least one second string resource file for other languages; after replacing the original string values in the string resource files with the target string values, the method further includes: for each second string resource file, determining whether the multiple string entries included in the first string resource file correspond one-to-one with the multiple string entries included in the second string resource file; if not, outputting a second detection result, the second detection result including the string entries missing in the second string resource file compared to the first string resource file, or the string entries missing in the first string resource file compared to the second string resource file.
[0016] In this embodiment, after importing the translation entries from the translation document into the string resource file, the string resource file is checked. When there are missing string entries in the string resource file, the corresponding detection results are output, which makes it easy for users to quickly analyze and determine the string resource file with missing string entries based on the detection results.
[0017] Optionally, after replacing the original string value in the string resource file with the target string value, the method further includes: determining whether a preset placeholder exists in each string resource file; if the preset placeholder exists, outputting a third detection result including the preset placeholder.
[0018] In this embodiment of the application, after importing the translation entries in the translation document into the string resource file, it is detected whether there are preset placeholders in the string entries in the string resource file. When preset placeholders exist, a third detection result is output, which can help users quickly identify special placeholders in the string resource.
[0019] Optionally, determining whether a translated document is an encrypted document includes: if the header of the translated document includes a signature, then the translated document is determined to be an unencrypted document; if the header of the translated document does not include a signature, then the translated document is determined to be an encrypted document; or, the translated document is read through the file read / write library, and if the read fails, the translated document is determined to be an encrypted document.
[0020] In this embodiment, the encryption status of the translated document is determined based on the signature included in the document header, eliminating the need for document analysis and enabling rapid determination. Furthermore, by reading the translated document using a file read / write library, if the read operation fails, the document is determined to be encrypted; if the read operation succeeds, the retrieved translation entries can be directly imported into a string resource file, allowing for rapid retrieval of translation entries even when the document is unencrypted.
[0021] Secondly, a translation import device is provided, the device comprising:
[0022] The determination module is used to determine whether the translated document is an encrypted document; The reading module is configured to, if the translation document is an encrypted document, call a spreadsheet program through the component object model interface to read the translation document to obtain multiple translation entries included in the translation document; and if the translation document is not an encrypted document, read the translation document through a file read / write library to obtain the multiple translation entries. The import module is used to import the multiple translation entries into N string resource files, where N is greater than or equal to 1.
[0023] Thirdly, an electronic device is provided, the electronic device comprising: Memory, used to store executable program code; A processor is configured to call and run the executable program code from the memory, causing the electronic device to perform the method in any possible implementation of the first aspect described above.
[0024] Fourthly, a program product is provided, comprising: executable program code, which, when run on an electronic device, causes the electronic device to perform the method in any possible implementation of the first aspect described above.
[0025] Fifthly, a readable storage medium is provided that stores executable program code, which, when run on an electronic device, causes the electronic device to perform the method in any possible implementation of the first aspect described above. Attached Figure Description
[0026] Figure 1 This is a flowchart illustrating the steps of a translation import method provided in an embodiment of this application; Figure 2 This is a flowchart illustrating a translation import method provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a translation import device provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0027] The technical solutions in this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. "And / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0028] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0029] During software development, to make the software compatible with users of different languages, multiple string resource files need to be configured. Each string resource file corresponds to a different language, and each string resource file stores the text content for that language. Configuring the string resource files first requires obtaining translation documents written by translators, and then importing the translation entries from the translation documents into the string resource files to complete the configuration.
[0030] Taking in-vehicle software as an example, when a vehicle needs to be sold in China, the UK, and Japan, the in-vehicle software needs to be compatible with Chinese, English, and Japanese users. This requires configuring a string resource file 1 for Chinese, a string resource file 2 for English, and a string resource file 3 for Japanese for the in-vehicle software. String resource file 1 contains the Chinese text content that is visible to the user, string resource file 2 contains the English text content that is visible to the user, and string resource file 3 contains the Japanese text content that is visible to the user.
[0031] In the software development process, the software is developed using one of Chinese, English, and Japanese as the base language (e.g., Chinese). Each visible text in the software is stored in a string entry in string resource file 1. Each string entry stores the text content in the form of key-value pairs, including a key name and a key value. The key name is used to uniquely identify the text content, and the key value is the text content, also known as a string value or string resource.
[0032] The string values in string resource file 1 are standard text content. The translator translates the string values in each string entry in string resource file 1 into English and the string values in each string entry in string resource file 1 into Japanese. The text content in string resource file 1, string resource 2 and string resource 3 are all stored in the translation document.
[0033] Translation documents are usually in the form of spreadsheets, as shown in Table 1:
[0034] Table 1 In this column, the string in the Key column is the key name, the string in the values-zh-rCN column is the string value in string resource file 1, the string in the values-en column is the string value in string resource file 2, and the string in the values-ja column is the string value in string resource file 3.
[0035] The translation document is generally an Excel Open XML Spreadsheet (XLSX) file in the format of Extensible Markup Language (XML). The string resource file is usually an XML file. Taking the key name app_name as an example, the content of the line where app_name is located is a translation entry. String resource file 1, string resource file 2, and string resource file 3 each contain a string entry. The key name in this entry is app_name. The key value of this string entry in string resource file 1 is "我的应用", the key value of this string entry in string resource file 2 is "MyApp", and the key value of this string entry in string resource file 3 is "マイアプリ".
[0036] Under normal circumstances, the translation document is an encrypted document. During the process of configuring the string resource file through software tools, authorization needs to be applied. After obtaining authorization, the software tool can open the translation document, read the translation entries from the translation document, and import the translation entries into the string resource file. The process of applying for authorization is rather cumbersome and takes a certain amount of time, causing great inconvenience to the configuration process of the string resource file.
[0037] To solve the above technical problems, an embodiment of this application provides a translation import method. In this method, after the software tool obtains the translation document, when the translation document is a non-encrypted document, it reads the translation document through a file reading and writing library to obtain multiple translation entries, and imports the multiple translation entries into the string resource file. When the translation document is an encrypted document, it calls a spreadsheet program (such as Excel program) through a Component Object Model (COM) interface to read the translation document to obtain multiple translation entries, and imports the multiple translation entries into the string resource file. In this way, the process of applying for authorization can be avoided, thereby improving the convenience in the configuration process of the string resource file.
[0038] Among them, the file reading and writing library is, for example, the openpyxl (Open Python Excel Library, openpyxl) library. The above software tool refers to the software used to import the translation entries in the translation document into the string resource file.
[0039] See Figure 1 , Figure 1 is the step flow chart of a translation import method provided by an embodiment of this application. The execution subject of this method can be an electronic device installed with the above software tool. This method may include the following steps: Step 101, determine whether the translation document is an encrypted document.
[0040] In this embodiment, during the configuration of the string resource file, the electronic device (i.e., the software tool) first obtains the translation document and then determines whether the translation document is encrypted. For example, the developer (i.e., the user) can store the translation document in a preset storage location on the electronic device. After opening the software tool, the developer can access the preset storage location to obtain the translation document stored there, and then determine whether the translation document is encrypted.
[0041] Optionally, step 101 may include: If the header of the translated document contains a signature, the translated document is determined to be an unencrypted document; if the header of the translated document does not contain a signature, the translated document is determined to be an encrypted document. Alternatively, the translated document can be read through a file read / write library, and if the read fails, the translated document can be determined to be an encrypted document.
[0042] When the translated document is an XLSX file, it is actually a Zippy Information Package (ZIP) compressed file. When the ZIP compressed file is unencrypted, its header includes a ZIP signature (PK\x03\x04). However, when the ZIP compressed file is encrypted, its header is encrypted into encrypted metadata and does not include the ZIP signature (PK\x03\x04).
[0043] In one implementation, during the process of determining whether a translated document is an encrypted document, the electronic device (i.e., the software tool) can read the first 8 bytes of data in the header of the translated document. When reading the first 8 bytes of data in the header, it is determined whether the first 8 bytes of data include a ZIP signature (PK\x03\x04). If the ZIP signature (PK\x03\x04) is included, it can be determined that the translated document is an unencrypted document. If the ZIP signature (PK\x03\x04) is not included, it can be determined that the translated document is encrypted, and the translated document is an encrypted document.
[0044] In another implementation, after obtaining the translation document, the electronic device can directly call a file read / write library (such as the openpyxl library) to read translation entries from the translation document. If an error occurs during reading, the translation document is determined to be encrypted. If translation entries are read, the translation document is determined to be unencrypted, and the read translation entries can be directly imported into a string resource file.
[0045] In this embodiment, the encryption status of the translated document is determined based on the signature included in the document header, eliminating the need for document analysis and enabling rapid determination. Furthermore, by reading the translated document using a file read / write library, if the read operation fails, the document is determined to be encrypted; if the read operation succeeds, the retrieved translation entries can be directly imported into a string resource file, allowing for rapid retrieval of translation entries even when the document is unencrypted.
[0046] Step 102: If so, call the spreadsheet program through the component object model interface to read the translation document and obtain the multiple translation entries included in the translation document.
[0047] In this embodiment, when the translation document is determined to be an encrypted document, the Excel program can be invoked via the COM interface to read the translation document and obtain multiple translation entries from it. For example, when the translation document is determined to be encrypted, the electronic device invokes the document open method of the Excel application via the COM interface and specifies the storage path of the translation document for that method. The COM interface, as an inter-process communication mechanism, transmits file open instructions to the already started or newly created Excel process.
[0048] Upon receiving a file open command, the Excel process initializes the document loading environment and automatically loads the Rights Management Services (RMS) client component deployed in the electronic identification system. This component, integrated into the Office suite, is responsible for handling the authentication and decryption of enterprise-level encrypted documents. The Excel process opens the file stream based on the storage path and reads the encrypted metadata from the document header. This metadata includes structured information such as the encryption algorithm identifier, key identifier, and rights policy server address. The Excel process obtains the identity credentials of the currently logged-in user on the electronic device, including a domain account ticket and a Kerberos token. Based on the rights policy server address in the file metadata, the RMS client component sends a decryption key request to the enterprise rights management server using the identity credentials. This request includes the identity credentials and the document key identifier. The enterprise rights management server verifies the validity of the user's identity credentials and queries the enterprise policy database to verify whether the user has document access permissions.
[0049] After successful verification, the enterprise access control server generates a decryption key and sends it to the RMS client component via a secure channel. Upon receiving the decryption key, the RMS client component calls its built-in encryption algorithm module to decrypt the translation document, restoring a standard ZIP archive (i.e., the decrypted translation document), thus completing the decryption process. After decryption, the Excel process decompresses the ZIP archive, obtaining a complete Excel document object. The Excel process returns the Excel document object to the software tool via a COM interface, allowing the software tool to read each translation entry from the Excel document object. As shown in Table 1, after decryption, the software tool can read each translation entry from the translation document.
[0050] It should be understood that the above are merely illustrative examples, and the actual process of reading translated documents by calling a spreadsheet program through a COM interface may include, but is not limited to, the examples above.
[0051] Step 103: If not, read the translation document through the file read / write library to obtain multiple translation entries.
[0052] In this embodiment, when the translation document is determined to be unencrypted, it can be read using the openpyxl library to obtain multiple translation entries. For example, after determining the translation document is unencrypted, the software tool calls the load function of the openpyxl library and provides the storage path of the translation document to the load function. The load function reads the file header of the translation document in binary mode and verifies whether the file header conforms to the signature structure of a ZIP archive. After successful verification, the openpyxl library completely decompresses the verified translation document into memory and extracts the core XML file set that constitutes the translation document. Then, the openpyxl library calls the XML parsing engine to convert each component file in the XML file set into a structured data model, and instantiates the corresponding Python object hierarchy based on the structured data model, including workbook, worksheet, and cell objects. Afterwards, the openpyxl library converts the raw string data in the XML file set into Python native data types, loads style definitions, and finally assembles the Workbook object as the function return value and outputs it to the software tool.
[0053] The Workbook object contains the core data of the translation document, and the software tool can read each translation entry from the Workbook object. As shown in Table 1, after decryption, the software tool can read each translation entry shown in Table 1 from the translation document.
[0054] It should be understood that the above are merely illustrative examples, and the actual process of reading translated documents through a file read / write library may include, but is not limited to, the examples above.
[0055] Step 104: Import multiple translation entries into N string resource files.
[0056] Where N is greater than or equal to 1, importing multiple translation entries into N string resource files means importing the string value included in each translation entry into the string entry of each string resource file, that is, replacing the string value (hereinafter referred to as the original string value) in the character entry of the string resource file with the corresponding string value (hereinafter referred to as the target string value) in the translation entry.
[0057] In this embodiment, after reading multiple translation entries from the translation document, for each string resource file, the electronic device can read the key name included in each string entry from the string resource file, then determine the corresponding key value (i.e., the target string value) from the multiple translation entries based on the key name, and then replace the original string value in the string entry with the target character value in the translation entry.
[0058] Taking the string resource file 2 in the example above as an example, string resource file 2 includes a string entry corresponding to the key name "app_name": <string name="app_name"> XXX< / string> The string entry corresponding to the key name "Welcome": <string name="Welcome"> YYY< / string> For string resource file 2, the key name "app_name" can be obtained from the string entry corresponding to the key name "app_name". Based on the key name "app_name", the target string value "MyApp" corresponding to string resource file 2 can be determined from multiple translation entries. The string entry can then be replaced with the target string value "MyApp". <string name="app_name"> MyApp< / string> The original string value "XXX" in the file.
[0059] Additionally, the key name "Welcome" can be retrieved from the string entry corresponding to the key name "Welcome". Based on the key name "Welcome", the target string value "Hello" corresponding to string resource file 2 can be determined from multiple translation entries. The string entry can then be replaced with the target string value "MyApp". <string name="Welcome"> YYY< / string> The original string value "YYY".
[0060] Similarly, the same operation can be used to import translation entries into string resource file 2 for each string entry in string resource file 2. Likewise, the same operation can be used to import translation entries into string resource files 1 and 3.
[0061] It is understandable that, during the process of importing translation entries into N string resource files, the original string value corresponding to the same key name and the target string value may be the same or different.
[0062] In this embodiment, during the translation import process, when the translation document is determined to be an encrypted document, a spreadsheet program is called via a COM interface to read the translation document and obtain multiple translation entries. When the translation document is determined to be an unencrypted document, a file read / write library is used to read the translation document and obtain multiple translation entries. These multiple translation entries are then imported into N string resource files. In this method, when the translation document is encrypted, reading multiple translation entries via a spreadsheet program using a COM interface bypasses the authorization application process, thereby improving the convenience of configuring string resource files.
[0063] Optionally, multiple translation entries can be imported into N string resource files, including: For each string resource file, use regular expressions to read the key name and raw string value from each string entry in the string resource file; For each string entry, the corresponding target string value is determined from multiple translation entries based on the key name; When the original string value differs from the target string value, the original string value in the string resource file is replaced with the target string value.
[0064] In one implementation, when reading a string resource file, instead of using an XML parser, regular expressions are used to read the key name and raw string value from each string entry in the string resource file, in order to prevent the raw string value read during the reading process from being automatically escaped and formatted.
[0065] Based on the above examples, the string entries in string resource file 2 are as follows: <string name="app_name"> XXX< / string> When reading the key name "app_name" and the original string value "XXX" in the string entry, the XML parser is not used. Instead, regular expressions are used to read the key name "app_name" and the original string value "XXX". When using regular expressions, the key name "app_name" and the original string value "XXX" read will not be automatically escaped or formatted. They are the actual key name "app_name" and the original string value "XXX" in the string entry.
[0066] After reading the key name "app_name" and the original string value "XXX" from the string entry, the target string value "MyApp" corresponding to string resource file 2 is determined from multiple translation entries based on the key name "app_name". Then, a literal-level difference detection is performed on the original string value "XXX" and the target string value "MyApp" to determine whether there is a difference between them. If there is a difference, the original string value "XXX" in the string entry is replaced with the target string value "MyApp". If there is no difference, the original string value "XXX" in the string entry remains unchanged.
[0067] Similarly, using the same method, multiple translation entries can be imported into string resource files 1, 2, and 3 for each string entry in string resource file 1, 2, and 3.
[0068] In this embodiment, regular expressions are used to read key names and original string values from the string resource file, which prevents automatic escaping and formatting of the read original string values during the reading process. Furthermore, when there is a difference between the literal values of the target string value and the original string value, the target string value is used to replace the original string value, which reduces the need for modification to the string resource file and thus lowers the probability of errors during the translation and import process.
[0069] In the process of importing multiple translation entries into string resource files, if it is determined that a new translation entry exists among the multiple translation entries, a corresponding string entry is added to each resource file. For example, the translation document shown in Table 1 includes a translation entry with the key "WWW", while string resource files 1, 2, and 3 do not include a string entry with the key "WWW". Therefore, a string entry with the key "WWW" can be added to string resource files 1, 2, and 3 respectively.
[0070] Optionally, before determining the corresponding target string value from multiple translation entries based on the key name, the method may further include: Determine whether the user has pre-set the corresponding key name prefix for the string resource file; If a key name prefix has been set for the string resource file beforehand, then add the key name prefix to the key name.
[0071] In practical applications, to differentiate translation documents from different software, a corresponding key name prefix can be set for the key names in the translation documents for each software. This prefix distinguishes the translation documents from different software. To address this, during the translation document construction process, a key name prefix can be set for the key names in the translation entries for different software. For example, for each key name shown in Table 1, a corresponding key name prefix "set_" can be set, resulting in the translation documents shown in Table 2.
[0072] Table 2 To address this issue, during the translation and import process, developers can input corresponding key name prefixes into the software tool. After reading the key name and original string value for each string entry from the string resource file, the software tool first determines whether the developer has pre-input a key name prefix. If so, it adds the prefix to each read key name. Then, based on the prefixed key names, it determines the corresponding target string value from multiple translation entries. Finally, when there is a difference between the target string and the original string, the original string value is replaced with the target string value.
[0073] For example, after reading the key name "app_name" and the original string value "XXX" from string resource file 2, if it is determined that the developer has pre-entered the key name prefix "set_", the software tool can add the key name prefix "set_" to the key name "app_name" to obtain the key name "set_app_name". After obtaining the key name "set_app_name", the target string value "MyApp" corresponding to the key name "set_app_name" is determined from multiple translation entries. Then, a literal-level difference detection is performed on the original string value "XXX" and the target string value "MyApp". If a difference is determined between the original string value "XXX" and the target string value "MyApp", the original string value "XXX" in the string entry is replaced with the target string value "MyApp".
[0074] In this embodiment of the application, when the user has set a key name prefix for the string resource file in advance, the key name prefix is added to the key name, and then the translation entries are imported into the string resource file based on the key name with the added key name prefix, which makes it convenient for the user to flexibly import translation entries according to the actual situation.
[0075] Optionally, after replacing the original string value in the string resource file with the target string value, the method may further include: For each string resource file, determine whether the string values in the string resource file contain unescaped characters; If unescaped characters are included, they will be escaped as escaped characters.
[0076] Unescaped characters, also known as reserved characters or special characters, are characters with special syntactic meanings and cannot appear directly in XML text. Escaped characters, also known as escape characters or escape sequences, are created by adding characters such as "\" or "&xxx" to reserved characters, causing them to lose their special meaning and become ordinary text in the XML file. For example, the reserved character "'" has a special meaning, and its special purpose in XML files is to wrap attribute values. Adding the character " / " to the escape character "'" creates an escaped character " / '", thus causing the reserved character "'" to lose its special meaning.
[0077] In one implementation, after importing multiple translation entries into N string resource files, for each string resource file, the string value in each string entry in the string resource file (which can be the original string value without replacement or the target string value after replacement) is checked to determine whether the string value contains unescaped characters. If it contains unescaped characters, the unescaped characters are escaped to change them into escaped characters.
[0078] For example, in a string resource file, if a string entry in the file contains the string value "It's OK", it can be determined that the string value contains the unescaped character "'". In this case, the character "\" can be added to the string to change the string value "It's OK" to "It\'s OK", thus escaping the unescaped character "'" into the escaped character "\'".
[0079] For example, given a string resource file, if a string entry in that file contains the string value "It's "Smart"&John's App", it can be determined that the string value contains unescaped characters "" and "'". In this case, the character "\" can be added to each unescaped character to change the string value "It's "Smart"&John's App" to "It\'s \"Smart\"&John\'s App", thus escaping the unescaped character "'" to the escaped character "\'" and the unescaped character """ to the escaped character "\".
[0080] It is understood that unescaped characters may also include, but are not limited to, "<" and ">". The specific escaping method for each unescaped character can be set according to the specific circumstances, and this embodiment does not impose any restrictions on this.
[0081] In this embodiment of the application, after importing the translation entries into the string resource file, the string resource file is checked to identify unescaped characters and escaped them. This avoids the string resource file from being used while carrying unescaped characters, thereby improving the reliability of the string resource file.
[0082] Optionally, the N string resource files include a first string resource file for the baseline language and at least one second string resource file for other languages; after replacing the original string values in the string resource files with the target string values, the method may further include: Extract the placeholders from each string entry in the first string resource file to obtain the first placeholder sequence corresponding to each string entry; For each second string resource file, retrieve the placeholders from each string entry in the second string resource file to obtain the second placeholder sequence corresponding to each string entry; For two string entries with the same key name, the first placeholder sequence and the second placeholder sequence are respectively. When the first placeholder sequence and the second placeholder sequence are different, the first detection result is output. The first detection result indicates that the placeholders in the two string entries with the same key name are inconsistent.
[0083] Placeholders refer to special markers in a string used for dynamically inserting runtime data. Formats include, but are not limited to, %1$s, %2$d, etc.
[0084] In one implementation, after importing the translation entries into the string resource file, it is possible to check whether the placeholders in the string resource files corresponding to other languages (also known as target languages) besides the base language are correct. When an error is detected in the placeholders in the string resource files corresponding to other languages, the corresponding first detection result is output.
[0085] Based on the above examples, in string resource file 1, string resource file 2, and string resource file 3, the base language is Chinese. String resource file 1, which corresponds to Chinese, is the first string resource file, while string resource files 2 and 3, which correspond to English and Japanese, are the two second string resource files.
[0086] After importing multiple translation entries from the translation document into string resource files 1, 2, and 3, for each string entry in string resource file 1, placeholders are extracted from the string entry and combined to obtain a corresponding first placeholder sequence. Simultaneously, for each string entry in string resource file 2, placeholders are extracted from the string entry and combined to obtain a corresponding second placeholder sequence. Similarly, for each string entry in string resource file 3, placeholders are extracted from the string entry and combined to obtain a corresponding second placeholder sequence.
[0087] For example, there is a string entry in string resource file 1: <string name="order_confirm">Order #%1$d: You purchased %2$d items of %3$s, for a total price of ¥%4$.2f < / string> In this string entry, "%1$d", "%2$d", "%3$s", and "%4$.2f" are placeholders. For this string entry, a regular expression is used to extract each placeholder, and the extracted placeholders are combined into a sequence to obtain a first placeholder sequence: "%1$d", "%2$d", "%3$s", and "%4$.2f". The key name corresponding to this first placeholder sequence is "order_confirm".
[0088] Similarly, a corresponding string entry exists in string resource file 2: <string name="order_confirm"> order#%1$d:You have purchased%2$d pieces%3$s,Total Price¥%4$.2f< / string> For this string entry, regular expressions are used to extract each placeholder. The extracted placeholders are combined into a sequence to obtain a corresponding second placeholder sequence: "%1$d", "%2$d", "%3$s", "%4$.2f". The key name corresponding to this second placeholder sequence is "order_confirm".
[0089] For the first placeholder sequence and the second placeholder sequence corresponding to the key name "order_confirm", compare the first placeholder sequence and the second placeholder sequence to determine whether the number of placeholders in the first placeholder sequence is the same as the number of placeholders in the second placeholder sequence. If the number is the same, determine that the first placeholder sequence and the second placeholder sequence are the same.
[0090] Conversely, when the number of placeholders is inconsistent, determining that the first placeholder sequence is different from the second placeholder sequence can output a first detection result indicating that the placeholders in the two string entries are different. The first detection result may include the key name "order_confirm", as well as the first and second placeholder sequences.
[0091] Alternatively, for the first and second placeholder sequences corresponding to the key name "order_confirm", compare the first and second placeholder sequences to determine whether the number of placeholders in the first and second placeholder sequences is the same. If the number is the same, and the second placeholder sequence includes every placeholder in the first placeholder sequence (i.e., the placeholders in the first and second placeholder sequences correspond one-to-one), then the first and second placeholder sequences are determined to be the same.
[0092] Conversely, when the number of placeholders is different, the first placeholder sequence is determined to be different from the second placeholder sequence. Furthermore, when the number of placeholders is the same, if the placeholders in the second placeholder sequence do not correspond one-to-one with the placeholders in the first placeholder sequence, then the first placeholder sequence is determined to be different from the second placeholder sequence, and the corresponding first detection result can be output.
[0093] Similarly, for the string entry corresponding to the key name "order_confirm" in string resource file 3, the corresponding second placeholder sequence can be extracted, and the second placeholder sequence can be compared with the first placeholder sequence corresponding to the key name "order_confirm". When the second placeholder sequence is different from the first placeholder sequence, the first detection result is output.
[0094] After outputting the first detection result, the developers can use this result to determine which string values in each string resource file have inconsistent placeholders, and then make appropriate adjustments to the string values with inconsistent placeholders.
[0095] In practical applications, software is developed based on a benchmark language. Therefore, the placeholders in the string resource files corresponding to the benchmark language are usually accurate and error-free. However, the placeholders in the string resource files corresponding to other languages are prone to errors. If an incorrect string resource file is used after the software is put into use, it may cause errors when the software displays text content.
[0096] In this embodiment, after the translation and import are completed, the placeholders in each string entry of the string resource file corresponding to languages other than the base language are checked to determine whether there are errors in the placeholders in the string entries. If there are errors, the first detection result is output, which can facilitate users to modify the placeholders in a timely manner, so as to avoid configuring string resources with erroneous placeholders to the software, thereby reducing the probability of software abnormalities.
[0097] Optionally, after replacing the original string value in the string resource file with the target string value, the method may further include: For each second string resource file, determine whether there is a one-to-one correspondence between the multiple string entries included in the first string resource file and the multiple string entries included in the second string resource file; If not, output the second detection result, which includes the string entries that are missing from the second string resource file compared to the first string resource file, or the string entries that are missing from the first string resource file compared to the second string resource file.
[0098] In one implementation, after importing the translation entries from the translation document into the string resource file, for each second string resource file, it can be determined whether there are missing or redundant string entries in the second string resource file compared to the first string resource file. If there are missing or redundant string entries, the corresponding second detection result is output.
[0099] Based on the above examples, after importing multiple translation entries into string resource files 1, 2, and 3, for string resource file 2, compare string resource file 1 and 2 to determine whether the string entries in string resource file 1 correspond one-to-one with the string entries in string resource file 2. For example, if string resource file 2 contains two string entries corresponding to the keys "app_name" and "Welcome" respectively, and string resource file 1 also contains two string entries corresponding to the keys "app_name" and "Welcome", then it can be determined that multiple string entries in string resource file 1 correspond one-to-one with multiple string entries in string resource file 2.
[0100] If string resource file 1 contains multiple string entries but does not include a string entry corresponding to the key name "app_name", then string resource file 1 is determined to be missing a string entry corresponding to the key name "app_name" compared to string resource file 1. Similarly, if string resource file 1 contains multiple string entries corresponding to the key name "card", but string resource file 2 does not include a string entry corresponding to the key name "card", then string resource file 2 is determined to be missing a string entry corresponding to the key name "card" compared to string resource file 1.
[0101] When either string resource file 1 or string resource file 2 is missing a string entry, a second detection result can be output. This second result includes the string entries missing from string resource file 1 compared to string resource file 2, or vice versa. Based on this second detection result, the user can determine which string entries are missing from string resource file 1 or string resource file 2 compared to string resource file 1.
[0102] Similarly, for string resource file 3, it can be determined whether multiple string entries in string resource file 1 correspond one-to-one with multiple string entries in string resource file 3. If they do not correspond one-to-one, a second detection result is output. This detection result includes the string entries missing from string resource file 3 compared to string resource file 1, or the string entries missing from string resource file 1 compared to the second string resource file 3. When this second detection result is output, the user can determine, based on the second detection result, which string entries are missing from string resource file 1 compared to string resource file 3, or which string entries are missing from string resource file 3 compared to string resource file 1.
[0103] In this embodiment, after importing the translation entries from the translation document into the string resource file, the string resource file is checked. When there are missing string entries in the string resource file, the corresponding detection results are output, which makes it easy for users to quickly analyze and determine the string resource file with missing string entries based on the detection results.
[0104] Optionally, after replacing the original string value in the string resource file with the target string value, the method may further include: Determine if a pre-defined placeholder exists in each string resource file; If a preset placeholder exists, the output will include the third detection result.
[0105] Among them, the default placeholders are special placeholders, that is, placeholders that may cause ambiguity. For example, the placeholder "25%s" which is composed of numbers and placeholders, the placeholder "25%%s" which excludes explicit percentage escapes, and the placeholder "%1$s%2$s" which excludes consecutive placeholders, etc., but not limited to these.
[0106] In one implementation, after importing translation entries into string resource files, placeholders in each string entry within the string resource file can be detected. If a preset placeholder exists in a string entry, a third detection result is output. Referring to the above example, developers can pre-input preset placeholders into the software tool. After importing translation entries from the translation document into string resource files 1, 2, and 3, for string resource file 1, the string value in each string entry is detected to determine whether it includes a preset placeholder.
[0107] Similarly, the string values in each string entry in string resource file 2 and string resource file 3 can be checked to determine whether they include preset placeholders. If one or more string entries in all string resource files 1, 2, and 3 contain preset placeholders, a third detection result can be output, which may include string entries containing preset placeholders.
[0108] Based on the third detection result, the R&D personnel can determine which string entries in string resource file 1, string resource file 2 and string resource file 3 contain preset placeholders, and then process the preset placeholders accordingly according to actual needs.
[0109] In this embodiment of the application, after importing the translation entries in the translation document into the string resource file, it is detected whether there are preset placeholders in the string entries in the string resource file. When preset placeholders exist, a third detection result is output, which can help users quickly identify special placeholders in the string resource.
[0110] See Figure 2 , Figure 2 This is a flowchart illustrating a translation import method provided in an embodiment of this application. Figure 2 As shown, the method includes: Step 201: Obtain the translation document.
[0111] Step 202: Read the first 8 bytes of data from the header of the translation document.
[0112] Step 203: Based on the first 8 bytes of data read, determine whether the translation document is an encrypted document.
[0113] In this embodiment, during the translation import process, the R&D personnel specify a translation document for the software tool. The software tool obtains the specified translation document and first reads the first 8 bytes of data from the file header. After reading the first 8 bytes of data, if the first 8 bytes of data include a ZIP signature, the translation document is determined to be an unencrypted document; if the first 8 bytes of data do not include a ZIP signature, the translation document is determined to be an encrypted document.
[0114] Step 204: Use the COM interface to call the Excel program to read multiple translation entries from the translation document.
[0115] Step 205: Use the openpyxl library to read multiple translation entries from the translation document.
[0116] In this embodiment, when it is determined that the translation document is an unencrypted document, the openpyxl library is called to read multiple translation entries from the translation document. If the reading fails when calling the openpyxl library to read multiple translation entries from the translation document, step 206 is executed, which calls the Excel program through the COM interface to read multiple translation entries from the translation document.
[0117] When the translation document is determined to be encrypted, an Excel program is called via the COM interface to read multiple translation entries from the document. If the reading fails, a message can be output to inform the translator that the document reading failed and to prompt the user to check the document.
[0118] In practical applications, when the translation document is not encrypted, but the version of the translation document is relatively old and the openpyxl library cannot read it, the translation entries can also be read from the translation document by calling the Excel program through the COM interface.
[0119] Step 206: Import multiple translation entries into N string resource files.
[0120] In this embodiment, after reading multiple translation entries, the multiple translation entries are imported into N string resource files. After importing the multiple translation entries into the N string resource files, for each string resource file, if it is determined that the string value in the string resource file contains an unescaped character, the unescaped character is escaped as an escaped character.
[0121] Furthermore, after importing multiple translation entries into N string resource files, the placeholders in each string entry are obtained from the first string resource file to obtain the first placeholder sequence corresponding to each string entry. For each second string resource file, the placeholders in each string entry are obtained from the second string resource file to obtain the second placeholder sequence corresponding to each string entry. For two string entries with the same key name, the first placeholder sequence and the second placeholder sequence are respectively provided. When the first placeholder sequence and the second placeholder sequence are different, the first detection result is output.
[0122] Furthermore, after importing multiple translation entries into N string resource files, for each second string resource file, it is determined whether the multiple string entries included in the first string resource file correspond one-to-one with the multiple string entries included in the second string resource file. If not, the second detection result is output.
[0123] Furthermore, after importing multiple translation entries into N string resource files, it is determined whether a preset placeholder exists in each string resource file. If the preset placeholder exists, a third detection result including the preset placeholder is output.
[0124] The above text combined Figures 1 to 2 The translation import method provided in the embodiments of this application is described in detail below; the following will be combined with Figure 3 and Figure 4 The apparatus embodiments of this application are described in detail below. It should be understood that the apparatus in the embodiments of this application can perform the various methods described in the foregoing embodiments of this application, that is, the specific working processes of the various products described below can be referred to the corresponding processes in the foregoing method embodiments.
[0125] See Figure 3 , Figure 3 This is a schematic diagram of the structure of a translation import device provided in an embodiment of this application. Figure 3 As shown, the translation import device 300 may include: Module 301 is used to determine whether the translated document is an encrypted document; The reading module 302 is configured to, if the translation document is an encrypted document, call a spreadsheet program through the component object model interface to read the translation document to obtain multiple translation entries included in the translation document; and if the translation document is not an encrypted document, read the translation document through a file read / write library to obtain the multiple translation entries. Import module 403 is used to import the multiple translation entries into N string resource files, where N is greater than or equal to 1.
[0126] Optionally, the import module 403 is specifically configured to, for each string resource file, use regular expressions to read the key name and original string value from each string entry in the string resource file; for each string entry, determine the corresponding target string value from the plurality of translation entries based on the key name; and when the original string value is different from the target string value, replace the original string value in the string resource file with the target string value.
[0127] Optionally, the import module 403 is further configured to determine whether the user has pre-set a corresponding key name prefix for the string resource file before determining the corresponding target string value from the plurality of translation entries based on the key name; if the key name prefix has been pre-set for the string resource file, then the key name prefix is added to the key name.
[0128] Optionally, the apparatus further includes an escaping module, configured to, after replacing the original string value in the string resource file with the target string value, determine for each string resource file whether the string value in the string resource file includes an unescaped character; if the unescaped character is included, then escape the unescaped character into an escaped character.
[0129] Optionally, the N string resource files include a first string resource file for a base language and at least one second string resource file for other languages; the apparatus further includes a checking module, configured to, after replacing the original string value in the string resource file with the target string value, obtain placeholders in each string entry from the first string resource file to obtain a first placeholder sequence corresponding to each string entry; for each second string resource file, obtain placeholders in each string entry from the second string resource file to obtain a second placeholder sequence corresponding to each string entry; for the first placeholder sequence and the second placeholder sequence corresponding to two string entries with the same key name, when the first placeholder sequence and the second placeholder sequence are different, output a first detection result, the first detection result indicating that the placeholders in the two string entries with the same key name are inconsistent.
[0130] Optionally, the N string resource files include a first string resource file for a base language and at least one second string resource file for other languages; the apparatus further includes a checking module, configured to, after replacing the original string values in the string resource files with the target string values, determine for each second string resource file whether there is a one-to-one correspondence between the multiple string entries included in the first string resource file and the multiple string entries included in the second string resource file; if not, output a second detection result, the second detection result including the string entries missing in the second string resource file compared to the first string resource file, or the string entries missing in the first string resource file compared to the second string resource file.
[0131] Optionally, the device further includes a checking module, configured to determine whether a preset placeholder exists in each of the string resource files after the original string value in the string resource file is replaced with the target string value; if the preset placeholder exists, a third detection result including the preset placeholder is output.
[0132] Optionally, the determining module is specifically used to determine that the translated document is an unencrypted document if the header of the translated document includes a signature; and to determine that the translated document is an encrypted document if the header of the translated document does not include a signature; or, to read the translated document through the file read / write library, and to determine that the translated document is an encrypted document if the read fails.
[0133] See Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. For example... Figure 4 As shown, the electronic device 400 is, for example, a server, including: a memory 401 and a processor 402, wherein the memory 401 stores executable program code 4011, and the processor 402 is used to call and execute the executable program code 4011 to perform a translation import method.
[0134] Furthermore, embodiments of this application also protect a translation import device, which may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to perform a translation import method provided in embodiments of this application.
[0135] This embodiment can divide the device into functional modules according to the above method example. For example, each module can correspond to a separate functional module, or two or more functions can be integrated into one output module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0136] When the functional modules are divided according to their respective functions, the device may also include a determining module, a replacing module, and a controlling module. It should be noted that all relevant content regarding the steps involved in the above method embodiments can be referenced to the functional descriptions of the corresponding functional modules, and will not be repeated here.
[0137] It should be understood that the apparatus provided in this embodiment is used to execute the above-described translation import method, and therefore can achieve the same effect as the above-described implementation method.
[0138] When using integrated units, the device may include a determining module and a control module. Specifically, when the device is applied to an electronic device, the output module can be used to control and manage the operation of the electronic device. The storage module can be used to support the execution of relevant program code by the electronic device.
[0139] The output module can be a processor or a body setup module, which can implement or execute various exemplary logic blocks, modules, and circuits shown in conjunction with the disclosure of this application. The processor can also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and microprocessors, etc., and the storage module can be a memory.
[0140] This embodiment also provides a readable storage medium storing executable program code. When the executable program code is run on an electronic device, the electronic device performs the aforementioned related method steps to implement the translation import method provided in the above embodiment.
[0141] This embodiment also provides a program product that, when run on an electronic device, causes the electronic device to perform the aforementioned related steps to implement a translation import method provided in the above embodiment.
[0142] In this embodiment, the device, readable storage medium, program product, or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.
[0143] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0144] In the 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 modules or units 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 device, 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 devices or units may be electrical, mechanical, or other forms.
[0145] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A translation import method, characterized in that, The method includes: Determine if the document being translated is encrypted; If so, the spreadsheet program is called through the component object model interface to read the translation document in order to obtain the multiple translation entries included in the translation document; If not, the translation document is read through the file read / write library to obtain the multiple translation entries; Import the multiple translation entries into N string resource files, where N is greater than or equal to 1.
2. The method as described in claim 1, characterized in that, The step of importing the multiple translation entries into N string resource files includes: For each of the string resource files, use regular expressions to read the key name and original string value from each string entry in the string resource file; For each of the string entries, the corresponding target string value is determined from the plurality of translation entries based on the key name; When the original string value is different from the target string value, the original string value in the string resource file is replaced with the target string value.
3. The method as described in claim 2, characterized in that, Before determining the corresponding target string value from the plurality of translation entries based on the key name, the method further includes: Determine whether the user has pre-set the corresponding key name prefix for the string resource file; If the key name prefix has been set in advance for the string resource file, then the key name prefix is added to the key name.
4. The method as described in claim 2, characterized in that, After replacing the original string value in the string resource file with the target string value, the method further includes: For each of the string resource files, determine whether the string values in the string resource files contain unescaped characters; If the unescaped character is included, then the unescaped character will be escaped as an escaped character.
5. The method as described in claim 2, characterized in that, The N string resource files include a first string resource file for the baseline language and at least one second string resource file for other languages; After replacing the original string value in the string resource file with the target string value, the method further includes: Obtain placeholders from each string entry in the first string resource file to obtain a first placeholder sequence corresponding to each string entry; For each of the second string resource files, placeholders in each string entry are obtained from the second string resource file to obtain a second placeholder sequence corresponding to each string entry; For the first placeholder sequence and the second placeholder sequence corresponding to two string entries with the same key name, when the first placeholder sequence and the second placeholder sequence are different, a first detection result is output. The first detection result indicates that the placeholders in the two string entries with the same key name are inconsistent.
6. The method as described in claim 2, characterized in that, The N string resource files include a first string resource file for the baseline language and at least one second string resource file for other languages; After replacing the original string value in the string resource file with the target string value, the method further includes: For each of the second string resource files, determine whether there is a one-to-one correspondence between the multiple string entries included in the first string resource file and the multiple string entries included in the second string resource file; If not, output a second detection result, which includes the string entries that are missing from the second string resource file compared to the first string resource file, or the string entries that are missing from the first string resource file compared to the second string resource file.
7. The method as described in claim 2, characterized in that, After replacing the original string value in the string resource file with the target string value, the method further includes: Determine whether a preset placeholder exists in each of the string resource files; If the preset placeholder exists, the third detection result including the preset placeholder is output.
8. The method according to any one of claims 1-7, characterized in that, Determining whether the translated document is an encrypted document includes: If the header of the translated document includes a signature, the translated document is determined to be an unencrypted document; if the header of the translated document does not include a signature, the translated document is determined to be an encrypted document. Alternatively, the translated document can be read through the file read / write library, and if the read fails, the translated document can be determined to be an encrypted document.
9. A readable storage medium, characterized in that, The readable storage medium stores executable program code that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1 to 8.
10. An electronic device, characterized in that, The electronic device includes: Memory, used to store executable program code; A processor for calling and running the executable program code from the memory, causing the electronic device to perform the method as described in any one of claims 1 to 8.