A language conversion method and device for code string
By combining the extraction engine and the translation platform in the code file, the inefficiency and omission of multilingual text extraction and translation in the code is solved, efficient multilingual support and key-value pair generation are achieved, and language ability is reduced Require.
Patent Information
- Application Number
- CN202010053402.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-01-17
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2040-01-17
AI Technical Summary
The prior art is inefficient and costly when extracting and translating multilingual text in code, and regular expressions cannot fully scan all text, which is easy to miss and requires high language ability.
Read the code file through the root path, call the first language extraction engine to extract the string, and use the translation platform to translate it, generate key-value pairs and store them in the configuration file, and use the code to highlight the syntax elements and character range to determine the string type. Reduce manual intervention.
It realizes efficient identification of the first language string in the code file, avoids information omission, reduces the requirements for language capabilities, is suitable for multilingual support, and avoids complex regular expression writing.
Smart Images

Figure CN113139390B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a language conversion method and device applied to a code string. Background Art
[0002] Currently, Internet or software companies in many countries are gradually developing international business, but the software, network system interfaces, prompts, etc. are all in their national languages. The code needs to be internationalized and support multiple languages to be suitable for different countries and regions.
[0003] Currently, software engineers are usually relied on to manually find the first language text from the code and write it into the configuration file, and then manually translate it into the second language. The overall implementation efficiency is low and the cost is high.
[0004] As an optimization of the previous method, regular expressions can be used to extract the first language text in the code, and then the first language can be converted into the second language by staff with language conversion capabilities.
[0005] In the process of implementing the present invention, the inventors found that the prior art has at least the following disadvantages:
[0006] Regular expressions cannot scan all the first language texts in the code, and are prone to omissions; they may split a sentence into two or more keys (representing words or sentences), which is not conducive to translators' understanding of the context and requires high language skills of the staff. Summary of the invention
[0007] In view of this, an embodiment of the present invention provides a language conversion method and device applied to a code string, which can at least solve the difficulty of extracting and translating Chinese in the code in the prior art.
[0008] To achieve the above object, according to one aspect of an embodiment of the present invention, a language conversion method applied to a code string is provided, comprising:
[0009] Read the code file according to the root path, call the first language extraction engine, and extract the first language string in the code file; wherein the root path is the file storage path;
[0010] Determine a second language to be converted, determine a translation platform based on the first language and the second language, and call the translation platform to translate the first language string to obtain a translated second language string;
[0011] A key name corresponding to the first language string is obtained, a key-value pair is generated based on the key name and the second language string, and the key-value pair is stored in a configuration file corresponding to the second language.
[0012] Optionally, the code file reading according to the root path further includes: obtaining a blacklist file list, determining the code files in the blacklist file list in the root path as blacklist files, and then reading the remaining code files.
[0013] Optionally, the calling of the first language extraction engine to extract the first language character string in the code file includes:
[0014] Using code highlighting, according to the syntax structure of the programming language, the syntax elements in the code file are identified; wherein the syntax elements include classes, methods, keywords, variables, strings, and comments;
[0015] A range of characters corresponding to the first language is determined, and if the characters in the character string are within the range, the character string is determined to be a character string in the first language.
[0016] Optionally, obtaining a key name corresponding to the first language character string includes:
[0017] Obtaining an identifier corresponding to the code file, and determining whether the length of the first language character string is within a predetermined length range;
[0018] If yes, generating a key name based on the identifier and the second language string;
[0019] If not, a key name is generated based on the position of the first string in the code file and the identifier.
[0020] Optionally, generating a key name based on the position of the first string in the code file and the identifier includes: determining a serial number before the position, taking the sum of the serial number and a preset value as the serial number of the first language string, and then generating a key name based on the identifier and the obtained serial number.
[0021] To achieve the above object, according to another aspect of an embodiment of the present invention, a language conversion device applied to a code string is provided, comprising:
[0022] An extraction module, configured to read a code file according to a root path, call a first language extraction engine, and extract a first language string from the code file; wherein the root path is a file storage path;
[0023] A translation module, configured to determine a second language to be converted, determine a translation platform based on the first language and the second language, and call the translation platform to translate the first language string to obtain a translated second language string;
[0024] A generation module is used to obtain a key name corresponding to the first language string, generate a key-value pair based on the key name and the second language string, and store the key-value pair in a configuration file corresponding to the second language.
[0025] Optionally, the extraction module is further used to: obtain a blacklist file list, determine the code files in the blacklist file list in the root path as blacklist files, and then read the remaining code files.
[0026] Optionally, the extraction module is used to:
[0027] Using code highlighting, according to the syntax structure of the programming language, the syntax elements in the code file are identified; wherein the syntax elements include classes, devices, keywords, variables, strings, and comments;
[0028] A range of characters corresponding to the first language is determined, and if the characters in the character string are within the range, the character string is determined to be a character string in the first language.
[0029] Optionally, the generating module is used to:
[0030] Obtaining an identifier corresponding to the code file, and determining whether the length of the first language character string is within a predetermined length range;
[0031] If yes, generating a key name based on the identifier and the second language string;
[0032] If not, a key name is generated based on the position of the first string in the code file and the identifier.
[0033] Optionally, the generating module is used to: determine a serial number located before the position, use the sum of the serial number and a preset value as the serial number of the first language string, and then generate a key name based on the identifier and the obtained serial number.
[0034] To achieve the above objective, according to another aspect of an embodiment of the present invention, a language conversion electronic device for code character strings is provided.
[0035] The electronic device of an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement any of the above-mentioned language conversion methods applied to code strings.
[0036] To achieve the above object, according to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, any of the above-mentioned language conversion methods applied to a code string is implemented.
[0037] According to the solution provided by the present invention, an embodiment of the above invention has the following advantages or beneficial effects: it can efficiently identify the first language string in the code file, replace the manual search method, avoid information omissions, reduce the requirements for the language ability of developers, and be applicable to multiple countries; use the translation platform to complete the translation work, effectively avoid complex regular expression writing, avoid information omissions, and will not split a line of first language into multiple keys.
[0038] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0040] Figure 1 is a schematic diagram of the main flow of a language conversion method applied to a code string according to an embodiment of the present invention;
[0041] Figure 2 is a flow chart of an optional language conversion method applied to a code string according to an embodiment of the present invention;
[0042] Figure 3 is a flow chart of another optional language conversion method applied to a code string according to an embodiment of the present invention;
[0043] Figure 4 is a schematic diagram of the framework structure of an embodiment of the present invention;
[0044] Figure 5 is a schematic diagram of main modules of a language conversion device applied to a code string according to an embodiment of the present invention;
[0045] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0046] Figure 7 It is a schematic diagram of the structure of a computer system of a mobile device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0047] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0048] It should be noted that the embodiment of the present invention can realize the conversion of the first language in the code into a second language, such as converting Chinese into a foreign language or converting the appearance into Chinese. To facilitate the description of the specific implementation process, the conversion of Chinese into a foreign language is mainly described as an example.
[0049] See also Figure 1 , which shows a main flow chart of a language conversion method applied to a code string provided by an embodiment of the present invention, comprising the following steps:
[0050] S101: Read the code file according to the root path, call the first language extraction engine, and extract the first language string in the code file; wherein the root path is the file storage path;
[0051] S102: determining a second language to be converted, determining a translation platform based on the first language and the second language, and calling the translation platform to translate the first language string to obtain a translated second language string;
[0052] S103: Acquire a key name corresponding to the first language character string, generate a key-value pair based on the key name and the second language character string, and store the key-value pair in a configuration file corresponding to the second language.
[0053] In the above implementation, for step S101, the present invention is a code language translation program, and the program operation depends on the computer system. Therefore, the data processing in the code translation process is performed in its memory, and the memory is the memory of the computer system running the program of the present invention.
[0054] After the system is started, the input parameter configuration, translation parameter configuration, and output parameter configuration will be written into the context (which represents the context of code execution) according to the staff settings;
[0055] 1) The input parameters mainly include the root path of the code project directory to be scanned. The root path starts from the bottom layer of the website. The root directory of a general website is the folder corresponding to the domain name, which can be regarded as the reading path and storage path;
[0056] 2) Translation parameters include:
[0057] ① Account and password for logging into the translation platform, but for self-developed translation tools, account and password are not required;
[0058] ② The translation source language, i.e. the first language, is described in the present invention using Chinese as an example;
[0059] ③ The translation language, i.e. the second language, is described by taking English as an example.
[0060] 3) Output parameters include:
[0061] ①Result path, that is, the path where the result file is saved. The result file content is a key-value pair (Key-Value), which is saved in a properties file or a json file;
[0062] ②Key prefix, that is, the prefix of the result file Key;
[0063] ③Placeholders, that is, placeholders used to replace Chinese positions in the code files of various development languages; that is, the position where the first language was originally written in the code file is replaced by a placeholder (which may be a word or a phrase); at the same time, a KV structured data is generated in the configuration file, the Key is the placeholder, and the Value is the translation of various languages.
[0064] ④Result file format: Select the internationalization configuration file as properties or json format. The properties file corresponds to the result of scanning java, vm, html and other codes, and the json format corresponds to the result of scanning javascript code.
[0065] After the system initialization phase is completed, the code file reading phase begins. The context reads the corresponding code file based on the root path in the input parameter configuration.
[0066] In addition, some code files under the root path are blacklisted files or directories, so file screening parameters can be set in the input parameter configuration, for example:
[0067] 1) Specify the code file or directory to be scanned;
[0068] 2) Blacklist file list, including files and folders, that is, a list of files that do not need to be scanned. When reading code files later, if a file or directory belonging to the blacklist is encountered, it will be automatically skipped and not read.
[0069] However, it should be noted that the specified files or directories must be scanned. For example, if there are three files abc in a directory, if a is configured in the blacklist, then only files b and c will be processed in subsequent scans. That is, the blacklist is used to exclude files that do not need to be scanned.
[0070] After the code file is read, the first language extraction phase is entered. Specifically, the first language extraction engine is called to identify the first language in the code file, and then the identified first language is extracted and stored in the memory.
[0071] It should be noted that all software operations of the present invention need to be loaded into the memory before operation. Specifically, the read code file is loaded into the memory. If the code file is operated, its operation information is saved on the disk.
[0072] Regarding step S102, after the first language character string is extracted from the code file, the multi-language translation phase is entered.
[0073] The context transmits the translation parameter configuration information to the multi-language translation interface. The multi-language translation interface calls the translation open platform corresponding to "first language->second language" according to the translation parameters to complete the translation work and obtain the translated second language string; wherein the second language is the language to be converted, such as English.
[0074] For step S103, after the multi-language translation phase is completed, the result output phase is entered. The result output phase mainly includes two directions: one is to replace the placeholder into the code, and the other is to write the Key-Value into the result file such as properties or json.
[0075] In order to support multiple languages, the first language in the code needs to be extracted and stored in a configuration file. Each word or sentence is represented by a Key. At the same time, the code no longer uses the first language, but uses Key as a placeholder. Different texts are displayed as the user selects a different language.
[0076] The configuration file example is as follows. The key is before the equal sign, and the value is after the equal sign.
[0077] Chinese configuration file
[0078] page.hello = Hello
[0079] page.bye=Goodbye
[0080] English configuration file
[0081] page.hello=hello
[0082] page.bye=goodbye
[0083] Japanese configuration file
[0084] page.hello=こんにちは
[0085] page.bye = goodbye
[0086] For example, first use "placeholder + key" to replace the corresponding Chinese character string. For example, use "#springMessage("com.jd.pop.order.query")" to replace the Chinese character string "query" in the code file.
[0087] Secondly, write the Key-Value1 content "com.jd.pop.order.1 = "The order you queried does not exist"" into the Chinese internationalization configuration file result file; write the content of Key-Value 2 "com.jd.pop.order.1 = "您查询的订单不存在"" into the English internationalization configuration file result file.
[0088] The method provided by the above embodiment can efficiently identify the first language strings in the code file, replacing the manual search method, avoiding information omission, reducing the requirements for the language ability of developers, and can be applied to multiple countries; using the translation platform to complete the translation work, effectively avoiding the writing of complex regular expressions, avoiding information omission, and not splitting a line of the first language into multiple keys.
[0089] See Figure 2 , which shows a schematic flowchart of an optional language conversion method applied to code strings according to an embodiment of the present invention, including the following steps:
[0090] S201: Read the code file according to the root path; wherein, the root path is the file storage path;
[0091] S202: Use the code highlighting method to identify the syntax elements in the code file according to the syntax structure of the programming language; wherein, the syntax elements include classes, methods, keywords, variables, strings, comments;
[0092] S203: Determine the range of characters corresponding to the first language. If the characters in the string are within the range, determine that the string is the first language string;
[0093] S204: Determine the second language to be converted, determine the translation platform based on the first language and the second language, and call the translation platform to translate the first language string to obtain the translated second language string;
[0094] S205: Obtain the key name corresponding to the first language string, generate a key-value pair based on the key name and the second language string, and store the key-value pair in the configuration file corresponding to the second language.
[0095] In the above embodiment, for steps S201, S204 and S205, see Figure 1 The description of steps S101 to S103 is not repeated here.
[0096] In the above implementation, for steps S202 and S203, the extraction of the first language string in the code file is the core stage of the system, which mainly uses a code highlighting plug-in, such as highlight.js.
[0097] Code highlighting refers to coloring the code according to the grammatical structure of the programming language, so as to give different colors to various grammatical elements (classes, methods, keywords, variables, strings, comments, etc.) in the code, which is convenient for code developers to read. Among them, programming languages are similar to human languages, with subject-predicate-object-attribute-adverb-complement structures, which can be easily used for grammatical element recognition.
[0098] highlight.js is an open source code highlighting plug-in that supports code highlighting in 185 programming languages and 89 styles. Its working principle can be decomposed into two steps: one is to identify various syntax elements in the code according to the syntax structure of the programming language; the other is to color different language elements according to the predetermined styles of different syntax elements.
[0099] The first language extraction engine of the present invention modifies the source code of highlight.js and reuses its ability to identify programming languages and various syntax elements in code files to extract all string elements. Furthermore, some comments also contain the first language. Through syntax element analysis, the first language string and the comment can be decomposed to avoid translation processing of the comment.
[0100] The modified first language extraction engine no longer colors the corresponding grammatical elements, but uses its ability to recognize strings to determine whether it is a first language string. If so, the first language string is stored in the system memory.
[0101] Since a character, whether in Chinese or other languages, is a code in the computer and has a certain range, it is possible to determine whether it is the first language, such as Chinese, by calculating the range of characters in the string.
[0102] The method provided in the above embodiment identifies the first language strings in various programming languages through code highlighting, translates them into corresponding multiple languages, and finally writes them into the internationalization configuration result file, which effectively improves the translation rate and avoids the translation of non-string information.
[0103] See also Figure 3, showing a schematic flow diagram of another alternative language conversion method applied to code strings according to an embodiment of the present invention, including the following steps:
[0104] S301: Read the code file according to the root path, call the first language extraction engine to extract the first language strings in the code file; wherein, the root path is the file storage path;
[0105] S302: Determine the second language to be converted, determine the translation platform based on the first language and the second language, and call the translation platform to translate the first language strings to obtain the translated second language strings;
[0106] S303: Obtain the identifier corresponding to the code file, and determine whether the length of the first language strings is within a predetermined length range;
[0107] S304: If so, generate a key name based on the identifier and the second language strings;
[0108] S305: If not, generate a key name based on the position of the first string in the code file and the identifier;
[0109] S306: Generate a key-value pair based on the key name and the second language strings, and store the key-value pair in the configuration file corresponding to the second language.
[0110] In the above embodiments, for steps S301, S302, and S306, reference may be made to Figure 1 the descriptions of steps S101 to S103 shown, which will not be elaborated here.
[0111] In the above embodiments, for steps S303 to S305, there are various situations for obtaining the key name. Taking the Chinese-to-English translation and the generated result file type being properties as an example for illustration.
[0112] Assume that the prefix of the key corresponding to the Chinese string is: com.jd.pop.order.. The prefix of the key is customized by the staff, and each system and module has its own prefix. In this embodiment, it can be determined as the prefix of the code file or the prefix of the system.
[0113] Scenario 1: If the length of the extracted Chinese string is within the preset length range (such as 4 Chinese characters), for example, "查询" (query), then two Key-Value (key-value pairs) will be generated in the memory:
[0114] Key-Value1: com.jd.pop.order.query = “查询”
[0115] Key-Value2: com.jd.pop.order.query = "Query"
[0116] As can be seen from the above, for the case where the length of the Chinese string is within the predetermined range, its key is equal to the combination of the artificially set prefix and the English translation result "query", and the values are the Chinese and English strings "查询" and "Query" respectively.
[0117] Scenario 2, if the length of the Chinese string exceeds the preset length range, such as "您查询的订单不存在", this situation will also generate two Key-Values in memory:
[0118] Key-Value1: com.jd.pop.order.1 = "您查询的订单不存在"
[0119] Key-Value2: com.jd.pop.order.1 = "The order you queried does not exist"
[0120] As can be seen from the above, the key at this time is equal to the combination of the prefix and the serial number, and the values are the Chinese and English contents "您查询的订单不存在" and "The order you queried does not exist" respectively. Since the English content is too long and not suitable to be combined with the prefix as the key name, secondary processing and naming are required.
[0121] Moreover, for multiple long Chinese strings, according to the order of appearance, such as their positions in the code file, the serial numbers are incrementally accumulated. For example, prefix + 1, prefix + 2, as long as they are not repeated. Further, in addition to the method of adding 1, other numerical accumulations can also be used, such as 1, 3, 5, 7.
[0122] Usually, one language will occupy one properties file. For example, Key-Value1 in the Chinese properties file: com.jd.pop.order.query = "查询" and Key-Value2 in the English properties file: com.jd.pop.order.query = "Query".
[0123] The method provided by the above embodiments determines whether the information combined with the prefix to generate the key is the translation result according to the length of the first language string in the code file, and simultaneously generates two versions of Key-Value for the first language and the second language.
[0124] See Figure 4As shown, the framework structure of the embodiment of the present invention is shown, which mainly includes four layers, namely, data layer, engine layer, control layer and result layer. The main responsibilities of each layer are as follows:
[0125] 1) Data layer: various codes that need to be converted into different languages, including but not limited to Java, JavaScript, HTML, Vue.js, Velocity templates, jQuery and other languages or language frameworks.
[0126] 2) Engine layer: includes a first language extraction engine and a multi-language translation interface; the first language engine is responsible for extracting the first language in the code file, such as Chinese, and the multi-language translation interface is responsible for translating the first language into the target language, i.e., the second language, such as English.
[0127] 3) Control layer: including input parameter configuration, translation parameter configuration, output parameter configuration, context, file reading and writing, etc.
[0128] 4) Result layer: It is the internationalization configuration file generated after the control layer calls the engine layer to scan the code. It includes properties and json. It is only used to store KV data and works in different software development languages.
[0129] See also Figure 5 , which shows a schematic diagram of main modules of a language conversion device 500 applied to a code string provided by an embodiment of the present invention, including:
[0130] The extraction module 501 is used to read the code file according to the root path, call the first language extraction engine, and extract the first language string in the code file; wherein the root path is the file storage path;
[0131] A translation module 502, configured to determine a second language to be converted, determine a translation platform based on the first language and the second language, and call the translation platform to translate the first language string to obtain a translated second language string;
[0132] The generating module 503 is used to obtain a key name corresponding to the first language string, generate a key-value pair based on the key name and the second language string, and store the key-value pair in a configuration file corresponding to the second language.
[0133] In the implementation device of the present invention, the extraction module 501 is also used to: obtain a blacklist file list, determine the code files in the blacklist file list in the root path as blacklist files, and then read the remaining code files.
[0134] In the implementation device of the present invention, the extraction module 501 is used to:
[0135] Using code highlighting, according to the syntax structure of the programming language, the syntax elements in the code file are identified; wherein the syntax elements include classes, devices, keywords, variables, strings, and comments;
[0136] A range of characters corresponding to the first language is determined, and if the characters in the character string are within the range, the character string is determined to be a character string in the first language.
[0137] In the implementation device of the present invention, the generating module 503 is used to:
[0138] Obtaining an identifier corresponding to the code file, and determining whether the length of the first language character string is within a predetermined length range;
[0139] If yes, generating a key name based on the identifier and the second language string;
[0140] If not, a key name is generated based on the position of the first string in the code file and the identifier.
[0141] In the implementation device of the present invention, the generating module 503 is used to: determine the serial number before the position, use the sum of the serial number and a preset value as the serial number of the first language string, and then generate a key name based on the identifier and the obtained serial number.
[0142] In addition, the specific implementation content of the device described in the embodiment of the present invention has been described in detail in the method described above, so the repeated content will not be described again here.
[0143] Figure 6 An exemplary system architecture 600 is shown in which embodiments of the present invention may be applied.
[0144] like Figure 6 As shown, the system architecture 600 may include terminal devices 601, 602, 603, a network 604 and a server 605 (just an example). The network 604 is used to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. The network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0145] The user can use the terminal devices 601, 602, 603 to interact with the server 605 through the network 604 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 601, 602, 603.
[0146] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0147] The server 605 may be a server that provides various services, such as a background management server that provides support for shopping websites browsed by users using the terminal devices 601 , 602 , and 603 (only as an example).
[0148] It should be noted that the method provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the device is generally set in the server 605 .
[0149] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0150] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0151] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0152] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0153] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.
[0154] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0155] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0156] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be arranged in a processor, for example, it may be described as: a processor includes an extraction module, a translation module, and a generation module. The names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the generation module may also be described as a "module for generating key-value pairs".
[0157] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0158] Read the code file according to the root path, call the first language extraction engine, and extract the first language string in the code file; wherein the root path is the file storage path;
[0159] Determine a second language to be converted, determine a translation platform based on the first language and the second language, and call the translation platform to translate the first language string to obtain a translated second language string;
[0160] A key name corresponding to the first language string is obtained, a key-value pair is generated based on the key name and the second language string, and the key-value pair is stored in a configuration file corresponding to the second language.
[0161] According to the technical solution of the embodiment of the present invention, the first language string in the code file can be efficiently identified, replacing the manual search method, reducing the requirements for the language ability of developers, and can be applicable to multiple countries; using the translation platform to complete the translation work, effectively avoiding complex regular expression writing, avoiding information omissions, and not splitting a line of the first language into multiple keys.
[0162] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A language conversion method applied to a code string, characterized in that: include: Reading a code file according to the root path, calling a first language extraction engine, and extracting a first language string in the code file, including: using a code highlighting method, according to the grammatical structure of the programming language, identifying grammatical elements in the code file; the grammatical elements include classes, methods, keywords, variables, strings, and comments; determining a range of characters corresponding to the first language, and if the characters in the string are within the range, determining that the string is the first language string; wherein the root path is a file storage path; Determine a second language to be converted, determine a translation platform based on the first language and the second language, and call the translation platform to translate the first language string to obtain a translated second language string; A key name corresponding to the first language string is obtained, a key-value pair is generated based on the key name and the second language string, and the key-value pair is stored in a configuration file corresponding to the second language.
2. The method according to claim 1, characterized in that The code file reading according to the root path also includes: A blacklist file list is obtained, and code files in the blacklist file list in the root path are determined as blacklist files, and then the remaining code files are read.
3. The method according to claim 1, characterized in that The obtaining of the key name corresponding to the first language character string includes: Obtaining an identifier corresponding to the code file, and determining whether the length of the first language character string is within a predetermined length range; If yes, generating a key name based on the identifier and the second language string; If not, a key name is generated based on the position of the first language string in the code file and the identifier.
4. The method according to claim 3, characterized in that The generating a key name based on the position of the first string in the code file and the identifier includes: A sequence number before the position is determined, a sum of the sequence number and a preset value is used as the sequence number of the first language string, and a key name is generated based on the identifier and the obtained sequence number.
5. A language conversion device for a code string, characterized in that: include: The extraction module is used to read the code file according to the root path, call the first language extraction engine, and extract the first language string in the code file, including: using the code highlighting method, according to the grammatical structure of the programming language, identifying the grammatical elements in the code file; the grammatical elements include classes, methods, keywords, variables, strings, and comments; determining the range of characters corresponding to the first language, and if the characters in the string are within the range, determining that the string is the first language string; wherein the root path is a file storage path; A translation module, configured to determine a second language to be converted, determine a translation platform based on the first language and the second language, and call the translation platform to translate the first language string to obtain a translated second language string; A generation module is used to obtain a key name corresponding to the first language string, generate a key-value pair based on the key name and the second language string, and store the key-value pair in a configuration file corresponding to the second language.
6. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.
7. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Mobile terminal character string internationalization process
CN101286147A
International multi-language implement method of configuration software
CN105138350A
Word display method, translation table generating method, file translation method and device
CN106776584A
A multi-language configuration file generating and displaying method and device and a medium
CN109284145A
Method for automatically generating code internationalized resources
CN110413574A
