CN113139390A - Language conversion method and device applied to code character strings - Google Patents
Language conversion method and device applied to code character strings Download PDFInfo
- Publication number
- CN113139390A CN113139390A CN202010053402.3A CN202010053402A CN113139390A CN 113139390 A CN113139390 A CN 113139390A CN 202010053402 A CN202010053402 A CN 202010053402A CN 113139390 A CN113139390 A CN 113139390A
- Authority
- CN
- China
- Prior art keywords
- language
- character string
- code
- file
- determining
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 44
- 238000006243 chemical reaction Methods 0.000 title claims abstract description 27
- 238000013519 translation Methods 0.000 claims abstract description 55
- 238000000605 extraction Methods 0.000 claims abstract description 21
- 238000004590 computer program Methods 0.000 claims description 9
- 230000014509 gene expression Effects 0.000 abstract description 6
- 238000010586 diagram Methods 0.000 description 11
- 238000012545 processing Methods 0.000 description 8
- 238000004891 communication Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 6
- 230000008569 process Effects 0.000 description 5
- 230000003287 optical effect Effects 0.000 description 4
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 238000004040 coloring Methods 0.000 description 2
- 239000000835 fiber Substances 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 238000009825 accumulation Methods 0.000 description 1
- 239000003086 colorant Substances 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 238000012216 screening Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Landscapes
- Machine Translation (AREA)
Abstract
The invention discloses a language conversion method and a language conversion device applied to code character strings, and relates to the technical field of computers. One embodiment of the method comprises: reading the code file according to the root path, calling a first language extraction engine, and extracting a first language character string in the code file; 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 character string to obtain a translated second language character string; and acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language. The implementation method can efficiently identify the first language character string in the code file, replaces manual searching, and reduces the requirement on the language ability of developers; the translation platform is used for completing translation work, so that writing of complex regular expressions is effectively avoided, and information omission is avoided.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a language conversion method and a language conversion device applied to code character strings.
Background
At present, international business is gradually developed by many national internet or software companies, but software, network system interfaces, prompts and the like are all national languages, and code processing needs to be internationalized to support multiple languages so as to be suitable for different countries and regions.
Conventionally, a software engineer is usually relied on to manually find out a first language text from a code and write the first language text into a configuration file, and then the first language text is manually translated into a second language, so that the overall implementation efficiency is low, and the cost is high.
As an optimization method of the above method, a regular expression may be used to extract a first language text in a code, and then a worker with a language conversion capability converts the first language into a second language.
In the process of implementing the invention, the inventor finds that the prior art has at least the following disadvantages:
the regular expression cannot scan all first language texts in the codes, and omission easily exists; a sentence may be split into two or more keys (representing words or sentences), which are not beneficial for the translator to understand the context and have high requirements on the language ability of the staff.
Disclosure of Invention
In view of this, embodiments of the present invention provide a language conversion method and apparatus applied to a code string, which can at least solve the problem in the prior art that it is not easy to extract and translate chinese characters in a code.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a language conversion method applied to a code string, including:
reading a code file according to the root path, calling a first language extraction engine, and extracting a first language character string in the code file; wherein the root path is a file storage path;
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 character string to obtain a translated second language character string;
acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
Optionally, the reading the code file according to the root path further includes: and acquiring a blacklist file list, determining the code files in the blacklist file list in the root path as blacklist files, and further reading the residual code files.
Optionally, the invoking a first language extraction engine to extract the first language character string in the code file includes:
recognizing a syntax element in the code file according to a syntax structure of a programming language by using a code highlighting mode; wherein the grammar elements comprise classes, methods, keywords, variables, strings and annotations;
and determining the range of the character corresponding to the first language, and if the character in the character string is in the range, determining the character string as the first language character string.
Optionally, the obtaining a key name corresponding to the first language character string includes:
acquiring an identifier corresponding to the code file, and judging whether the length of the first language character string is within a preset length range;
if yes, generating a key name based on the identification and the second language character string;
and if not, generating a key name based on the position of the first character string in the code file and the identifier.
Optionally, the generating a key name based on the location of the first character string in the code file and the identifier includes: and determining a serial number positioned in front of the position, taking the sum of the serial number and a preset numerical value as the serial number of the first language character string, and further generating a key name based on the identification and the obtained serial number.
To achieve the above object, according to another aspect of the embodiments of the present invention, there is provided a language conversion apparatus applied to a code character string, including:
the extraction module is used for reading the code file according to the root path, calling a first language extraction engine and extracting a first language character string in the code file; wherein the root path is a file storage path;
the translation module is used for determining a second language to be converted, determining a translation platform based on the first language and the second language, calling the translation platform to translate the first language character string to obtain a translated second language character string;
and the generating module is used for acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
Optionally, the extracting module is further configured to: and acquiring a blacklist file list, determining the code files in the blacklist file list in the root path as blacklist files, and further reading the residual code files.
Optionally, the extracting module is configured to:
recognizing a syntax element in the code file according to a syntax structure of a programming language by using a code highlighting mode; wherein the grammar elements include classes, devices, keywords, variables, strings, annotations;
and determining the range of the character corresponding to the first language, and if the character in the character string is in the range, determining the character string as the first language character string.
Optionally, the generating module is configured to:
acquiring an identifier corresponding to the code file, and judging whether the length of the first language character string is within a preset length range;
if yes, generating a key name based on the identification and the second language character string;
and if not, generating a key name based on the position of the first character string in the code file and the identifier.
Optionally, the generating module is configured to: and determining a serial number positioned in front of the position, taking the sum of the serial number and a preset numerical value as the serial number of the first language character string, and further generating a key name based on the identification and the obtained serial number.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a language conversion electronic device applied to a code character string.
The electronic device of the embodiment of the invention comprises: one or more processors; a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement any of the above-described language conversion methods applied to code strings.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable medium on which a computer program is stored, the program implementing any one of the above-described language conversion methods applied to a code string when executed by a processor.
According to the scheme provided by the invention, one embodiment of the invention has the following advantages or beneficial effects: the first language character string in the code file can be efficiently identified, a manual searching mode is replaced, information omission is avoided, the requirement on the language ability of developers is reduced, and the method is suitable for multiple countries; the translation platform is used for completing translation work, so that writing of complex regular expressions is effectively avoided, information omission is avoided, and a line of first language cannot be divided into a plurality of keys.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic flow chart of a language conversion method applied to a code string according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating an alternative language conversion method applied to a code string according to an embodiment of the present invention;
FIG. 3 is a flow diagram illustrating an alternative language conversion method applied to a code string according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a frame structure of an embodiment of the present invention;
FIG. 5 is a schematic diagram of main blocks of a language conversion apparatus applied to a code string according to an embodiment of the present invention;
FIG. 6 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 7 is a schematic block diagram of a computer system suitable for use with a mobile device or server implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that, the embodiment of the present invention may implement the conversion of the first language in the code into the second language, for example, the conversion of chinese into foreign language or the conversion of appearance into chinese, and for convenience of describing the specific implementation process, the description is mainly given by taking the conversion of chinese into foreign language as an example.
Referring to fig. 1, a main flowchart of a language conversion method applied to a code string according to an embodiment of the present invention is shown, including the following steps:
s101: reading a code file according to the root path, calling a first language extraction engine, and extracting a first language character string in the code file; wherein the root path is a file storage path;
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 character string to obtain a translated second language character string;
s103: acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
In the foregoing embodiment, as for step S101, the present invention is a code language translation program, and the program operation depends on the computer system, so that the data processing in the code translation process is performed in the memory thereof, which is the memory of the computer system running the program of the present invention.
After the system is started, the input parameter configuration, the translation parameter configuration and the output parameter configuration are written into a context (representing a context, which is a context for code execution) according to the setting of a worker; wherein,
1) the input parameters mainly comprise a root path of the code engineering directory to be scanned. The root path is from the bottom layer of the website, and the root directory of the general website is a corresponding folder under the domain name and can be regarded as a reading path and a storage path;
2) the translation parameters include:
firstly, logging in an account and a password of a translation platform, but for a self-developed translation tool, the account and the password are not needed;
translating a source language, namely a first language, and explaining the source language by taking Chinese as an example;
and thirdly, a translation language, namely a second language, and the invention is explained by taking English as an example.
3) The output parameters include:
the result path is the saving path of the result file. The content of the result file is a Key-Value pair (Key-Value) and is stored in a properties file or a json file;
key prefix, namely the prefix of a result file Key;
the placeholder, namely the placeholder used for replacing the Chinese position in the code file of each development language; that is, the location in the original code file where the first language was written is replaced by a placeholder (which may be a word or phrase); meanwhile, data of a K-V structure is generated in a configuration file, Key is a placeholder, and Value is translation of various languages.
Fourthly, the format of the result file is as follows: the internationalized configuration file is selected to be in a properties or json format, the properties file corresponds to a result generated by scanning java, vm, html and other codes, and the json format corresponds to a result generated by scanning javascript codes.
And entering a code file reading stage after the system initialization stage is completed. And the context reads the corresponding code file according to the root path in the input parameter configuration.
In addition, some code files under the root path are files or directories belonging to a blacklist, so that file screening parameters can be set in the input parameter configuration, for example:
1) specifying a scanned code file or directory;
2) blacklisted file lists, including files and folders, i.e., lists of files that do not need to be scanned. When reading the code file, if the file or the directory belonging to the blacklist is encountered, the code file is automatically skipped over, and the code file is not read.
However, it should be noted that the specified file or directory must be scanned, for example, three files abc exist in a certain directory, if a is configured in the black list, then only two files b and c are processed in the subsequent scanning, that is, the black list is used to exclude the files that do not need to be scanned.
After the code file is read, a first language extraction stage is entered, specifically, a first language extraction engine is called to identify a first language in the code file, and then the identified first language is extracted into the memory for storage.
It should be noted that all software operations of the present invention need to be loaded into the memory for further operations, specifically, the read code file is loaded into the memory, and if the code file is operated, the operation information is saved on the disk.
For step S102, after the first language string in the code file is extracted, the multi-language translation stage is entered.
The context transmits the translation parameter configuration information to a multi-language translation interface, and the multi-language translation interface calls a translation open platform corresponding to the first language- > the second language to finish translation work according to the translation parameters to obtain a translated second language character string; wherein the second language is a language to be converted, such as english.
For step S103, after the multilingual translation phase is completed, the result output phase is entered. The result output stage mainly comprises two directions, namely, replacing a placeholder into a code, and writing Key-Value into a results file such as properties or json.
In order to support multiple languages, a first language in a code needs to be extracted, the first language is stored in a configuration file, and each vocabulary or statement is represented by a Key; meanwhile, the code is not occupied by the first language any more, but occupied by a Key, and different characters are displayed according to different languages selected by users.
An example of a profile is as follows, a constant number preceded by a Key and followed by a value.
Chinese configuration file
Hello ═ hello
Bye, bye
English configuration file
page.hello=hello
page.bye=goodbye
Japanese configuration file
page.hello=こんにちは
page.bye=さようなら
For example, the corresponding chinese string is first replaced with "placeholder + key", e.g., the chinese string "query" in the code file is replaced with "# springMessage (" com.
Secondly, writing the content "com.jd.pop.order.1 ═ of the query order of" Key-Value1 into a Chinese international configuration file result file; and writing The content "com.jd.pop.order.1 ═ The order you requested do not exist exists" of Key-Value2 into an English international configuration file result file.
The method provided by the embodiment can efficiently identify the first language character string in the code file, replaces a manual searching mode, avoids information omission, reduces the requirement on the language ability of developers, and is suitable for multiple countries; the translation platform is used for completing translation work, so that writing of complex regular expressions is effectively avoided, information omission is avoided, and a line of first language cannot be divided into a plurality of keys.
Referring to fig. 2, a flow chart of an optional language conversion method applied to a code character string according to an embodiment of the present invention is shown, including the following steps:
s201: reading the code file according to the root path; wherein the root path is a file storage path;
s202: recognizing a syntax element in the code file according to a syntax structure of a programming language by using a code highlighting mode; wherein the grammar elements comprise classes, methods, keywords, variables, strings and annotations;
s203: determining a range of characters corresponding to the first language, and if the characters in the character string are in the range, determining the character string as the first language character string;
s204: 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 character string to obtain a translated second language character string;
s205: acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
In the above embodiment, for steps S201, S204, and S205, reference may be made to the descriptions of steps S101 to S103 shown in fig. 1, and details are not repeated here.
In the above embodiment, for steps S202 and S203, the extraction of the first language character string in the code file is the core stage of the system, and it mainly uses a code highlight plug-in, such as highlight.
Code highlighting refers to coloring codes according to a syntactic structure of a programming language so as to apply different colors to various syntactic elements (classes, methods, keywords, variables, character strings, annotations and the like) in the codes, so that code developers can read the codes conveniently. The programming language is similar to human language, has a main and auxiliary object shape complementing structure, and can be conveniently used for identifying grammatical elements.
Js is an open source code highlight plug-in, and supports 185 programming languages, namely code highlight and 89 styles. The working principle can be decomposed into two steps, namely, various syntactic elements in the code are recognized according to the syntactic structure of the programming language; and secondly, coloring different language elements according to the preset patterns of different syntactic elements.
The first language extraction engine of the present invention modifies the source code of highlight. js, multiplexing its ability to recognize various syntax elements in the programming language and code files to extract all the string elements. Furthermore, some annotations also contain the first language, and through analysis of syntactic elements, the character strings of the first language can be separated from the annotations, so that translation processing of the annotations is avoided.
The modified first language extraction engine does not color the corresponding syntactic elements any more, but judges whether the syntactic elements are the first language character strings or not by utilizing the character string recognition capability of the syntactic elements, and stores the first language character strings into a system memory if the syntactic elements are the first language character strings.
Because a character, whether it is a Chinese character or other languages, is a code in a computer and has a certain range, it can be determined whether it is the first language, such as Chinese, by calculating the range of characters in the character string.
According to the method provided by the embodiment, the first language character strings in various programming languages are identified through code highlighting, translated into the corresponding multiple languages and finally written into the international configuration result file, so that the translation rate is effectively improved, and the translation condition of non-character string information is avoided.
Referring to fig. 3, a schematic flow chart of another alternative language conversion method applied to code strings according to an embodiment of the present invention is shown, including the following steps:
s301: reading a code file according to the root path, calling a first language extraction engine, and extracting a first language character string in the code file; wherein the root path is a file storage path;
s302: 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 character string to obtain a translated second language character string;
s303: acquiring an identifier corresponding to the code file, and judging whether the length of the first language character string is within a preset length range;
s304: if yes, generating a key name based on the identification and the second language character string;
s305: if not, generating a key name based on the position of the first character string in the code file and the identifier;
s306: and generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
In the above embodiment, for steps S301, S302, and S306, reference may be made to the description of steps S101 to S103 shown in fig. 1, and details are not repeated here.
In the above embodiment, there are many cases where the key name is acquired in steps S303 to S305. The description will be given by taking the example that Chinese is translated into English and the generated result file type is properties.
Assume that the prefix of the key corresponding to the Chinese character string is: com.jd.pop.order. The prefix of the key is customized by the staff, each system and module has the prefix, and the prefix can be determined to be the prefix of the code file or the prefix of the system in the embodiment.
Scene one: if the length of the extracted chinese character string is within a preset length range (e.g., 4 chinese characters), such as "query", two Key-values are generated in the memory:
Key-Value 1: com, jd, pop, order, query ═ query "
Key-Value2:com.jd.pop.order.query=“Query”
From the above, for the case that the length of the chinese character string is within the predetermined range, its key is equal to the combination of the prefix set by human and the english translation result Query, and the values are the chinese and english character strings "Query" and "Query", respectively.
In a second scenario, if the length of the chinese character string exceeds a preset length range, for example, "you inquire about an order does not exist", the case will also generate two Key-values in the memory:
Key-Value 1: com.jd.pop.order.1 ═ order for your query does not exist "
Key-Value2:com.jd.pop.order.1=“The order you queried does not exist”
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 "do not exist for The queried order" and "The order you queried for The orders not exist" respectively. Because the English content is too long and is not suitable for being combined with the prefix into a key name, secondary processing naming is needed.
And for a plurality of longer Chinese character strings, according to the appearance sequence, such as the positions of the Chinese character strings in the code file, the serial number accumulation processing is carried out in an increasing mode, such as prefix +1 and prefix +2, as long as no repetition is ensured. Further, in addition to adding 1, other values may be added, such as 1, 3, 5, and 7.
Typically, a language will occupy a property file, such as Key-Value1 in a chinese property file: com, jd, pop, order, query ═ query, "and Key-Value2 in the english properties file: com.jd.pop.order.query ═ Query.
The method provided by the above embodiment determines whether the information combined with the prefix to generate the Key is the translation result according to the length of the first language character string in the code file, and generates Key-Value of the first language version and the second language version at the same time.
Referring to fig. 4, a frame structure of an embodiment of the present invention is shown, which mainly includes four layers, namely a data layer, an engine layer, a control layer, and a result layer, and the main responsibilities of each layer are as follows:
1) and (3) a data layer: the various codes that need to be language converted include, but are not limited to, languages or language frameworks such as Java, JavaScript, HTML, Vue.
2) An engine layer: the system comprises a first language extraction engine and a multi-language translation interface; wherein the first language engine is responsible for extracting a first language, such as chinese, from the code file, and the multilingual translation interface is responsible for translating the first language into a target language, i.e., a second language, such as english.
3) A control layer: the method comprises the steps of input parameter configuration, translation parameter configuration, output parameter configuration, context, file reading and writing and the like.
4) Results layer: the system is an internationalized configuration file generated after a control layer calls an engine layer to scan codes, comprises properties and json, is only used for storing K-V data and acts on different software development languages.
Referring to fig. 5, a schematic diagram illustrating major modules of a language conversion apparatus 500 applied to a code string according to an embodiment of the present invention is shown, including:
the extraction module 501 is configured to read a code file according to a root path, call a first language extraction engine, and extract a first language character string in the code file; wherein the root path is a file storage path;
the translation module 502 is 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 character string to obtain a translated second language character string;
a generating module 503, configured to obtain 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.
In the apparatus for implementing the present invention, the extracting module 501 is further configured to: and acquiring a blacklist file list, determining the code files in the blacklist file list in the root path as blacklist files, and further reading the residual code files.
In the device for implementing the present invention, the extracting module 501 is configured to:
recognizing a syntax element in the code file according to a syntax structure of a programming language by using a code highlighting mode; wherein the grammar elements include classes, devices, keywords, variables, strings, annotations;
and determining the range of the character corresponding to the first language, and if the character in the character string is in the range, determining the character string as the first language character string.
In the device for implementing the present invention, the generating module 503 is configured to:
acquiring an identifier corresponding to the code file, and judging whether the length of the first language character string is within a preset length range;
if yes, generating a key name based on the identification and the second language character string;
and if not, generating a key name based on the position of the first character string in the code file and the identifier.
In the device for implementing the present invention, the generating module 503 is configured to: and determining a serial number positioned in front of the position, taking the sum of the serial number and a preset numerical value as the serial number of the first language character string, and further generating a key name based on the identification and the obtained serial number.
In addition, the detailed implementation of the device in the embodiment of the present invention has been described in detail in the above method, so that the repeated description is not repeated here.
FIG. 6 illustrates an exemplary system architecture 600 to which embodiments of the invention may be applied.
As shown in fig. 6, the system architecture 600 may include terminal devices 601, 602, 603, a network 604, and a server 605 (by way of example only). The network 604 serves to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. Network 604 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 601, 602, 603 to interact with the server 605 via the network 604 to receive or send messages or the like. Various communication client applications can be installed on the terminal devices 601, 602, 603.
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 605 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 601, 602, 603.
It should be noted that the method provided by the embodiment of the present invention is generally executed by the server 605, and accordingly, the apparatus is generally disposed in the server 605.
It should be understood that the number of terminal devices, networks, and servers in fig. 6 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary 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 bus 704.
The following components are connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. 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, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes an extraction module, a translation module, and a generation module. Where the names of these modules do not in some way constitute a limitation on the module itself, for example, a generating module may also be described as a "module that generates key-value pairs".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
reading a code file according to the root path, calling a first language extraction engine, and extracting a first language character string in the code file; wherein the root path is a file storage path;
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 character string to obtain a translated second language character string;
acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
According to the technical scheme of the embodiment of the invention, the first language character string in the code file can be efficiently identified, a manual searching mode is replaced, the requirement on the language ability of developers is reduced, and the method is suitable for multiple countries; the translation platform is used for completing translation work, so that writing of complex regular expressions is effectively avoided, information omission is avoided, and a line of first language cannot be divided into a plurality of keys.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (8)
1. A language conversion method applied to a code string, comprising:
reading a code file according to the root path, calling a first language extraction engine, and extracting a first language character string in the code file; wherein the root path is a file storage path;
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 character string to obtain a translated second language character string;
acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
2. The method of claim 1, wherein reading the code file according to the root path further comprises:
and acquiring a blacklist file list, determining the code files in the blacklist file list in the root path as blacklist files, and further reading the residual code files.
3. The method of claim 1, wherein said invoking a first language extraction engine to extract a first language string in the code file comprises:
recognizing a syntax element in the code file according to a syntax structure of a programming language by using a code highlighting mode; wherein the grammar elements comprise classes, methods, keywords, variables, strings and annotations;
and determining the range of the character corresponding to the first language, and if the character in the character string is in the range, determining the character string as the first language character string.
4. The method of claim 1, wherein obtaining the key name corresponding to the first language string comprises:
acquiring an identifier corresponding to the code file, and judging whether the length of the first language character string is within a preset length range;
if yes, generating a key name based on the identification and the second language character string;
and if not, generating a key name based on the position of the first character string in the code file and the identifier.
5. The method of claim 4, wherein generating a key name based on the location of the first string in the code file and the identification comprises:
and determining a serial number positioned in front of the position, taking the sum of the serial number and a preset numerical value as the serial number of the first language character string, and further generating a key name based on the identification and the obtained serial number.
6. A language conversion apparatus applied to a code character string, comprising:
the extraction module is used for reading the code file according to the root path, calling a first language extraction engine and extracting a first language character string in the code file; wherein the root path is a file storage path;
the translation module is used for determining a second language to be converted, determining a translation platform based on the first language and the second language, calling the translation platform to translate the first language character string to obtain a translated second language character string;
and the generating module is used for acquiring a key name corresponding to the first language character string, generating a key value pair based on the key name and the second language character string, and storing the key value pair into a configuration file corresponding to the second language.
7. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
8. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010053402.3A CN113139390A (en) | 2020-01-17 | 2020-01-17 | Language conversion method and device applied to code character strings |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010053402.3A CN113139390A (en) | 2020-01-17 | 2020-01-17 | Language conversion method and device applied to code character strings |
Publications (1)
Publication Number | Publication Date |
---|---|
CN113139390A true CN113139390A (en) | 2021-07-20 |
Family
ID=76809597
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010053402.3A Pending CN113139390A (en) | 2020-01-17 | 2020-01-17 | Language conversion method and device applied to code character strings |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113139390A (en) |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113760361A (en) * | 2021-08-17 | 2021-12-07 | 中科曙光国际信息产业有限公司 | Code file generation method, computer device and readable storage medium |
CN113778594A (en) * | 2021-08-24 | 2021-12-10 | 行云智网络科技(北京)有限公司 | Multi-language application package generation method and system |
CN113885882A (en) * | 2021-10-29 | 2022-01-04 | 四川效率源信息安全技术股份有限公司 | Method for restoring iOS type character string |
CN114138282A (en) * | 2021-11-30 | 2022-03-04 | 四川效率源信息安全技术股份有限公司 | Method and device for restoring pseudo code of iOS type code |
CN114371996A (en) * | 2021-12-30 | 2022-04-19 | 浙江中控技术股份有限公司 | JS file testing method and device |
CN114489839A (en) * | 2022-01-12 | 2022-05-13 | 海南车智易通信息技术有限公司 | Method and device for loading configuration data aiming at page and server |
CN116522966A (en) * | 2023-06-30 | 2023-08-01 | 天津华来科技股份有限公司 | Text translation method and system based on multilingual vocabulary entry |
CN117709362A (en) * | 2023-11-22 | 2024-03-15 | 赛力斯汽车有限公司 | Method, device, computer equipment and storage medium for modifying multilingual resources |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1506875A (en) * | 2002-12-12 | 2004-06-23 | 华为技术有限公司 | Characteristic character string extracting and substituting method in language localization |
CN101286147A (en) * | 2008-05-29 | 2008-10-15 | 中兴通讯股份有限公司 | Mobile terminal character string internationalization process |
US20120029902A1 (en) * | 2010-07-27 | 2012-02-02 | Fang Lu | Mode supporting multiple language input for entering text |
CN105138350A (en) * | 2015-07-29 | 2015-12-09 | 北京四方继保自动化股份有限公司 | International multi-language implement method of configuration software |
CN106776584A (en) * | 2016-11-24 | 2017-05-31 | 网易(杭州)网络有限公司 | Character displaying method, translation table generating method, document translation method and device |
CN109284145A (en) * | 2018-08-28 | 2019-01-29 | 北京城市网邻信息技术有限公司 | The generation of multilingual configuration file and methods of exhibiting and device, equipment and medium |
CN110413574A (en) * | 2019-07-30 | 2019-11-05 | 深圳市携众通科技有限公司 | A kind of method of automatic code generating internationalized resources |
-
2020
- 2020-01-17 CN CN202010053402.3A patent/CN113139390A/en active Pending
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1506875A (en) * | 2002-12-12 | 2004-06-23 | 华为技术有限公司 | Characteristic character string extracting and substituting method in language localization |
CN101286147A (en) * | 2008-05-29 | 2008-10-15 | 中兴通讯股份有限公司 | Mobile terminal character string internationalization process |
US20120029902A1 (en) * | 2010-07-27 | 2012-02-02 | Fang Lu | Mode supporting multiple language input for entering text |
CN105138350A (en) * | 2015-07-29 | 2015-12-09 | 北京四方继保自动化股份有限公司 | International multi-language implement method of configuration software |
CN106776584A (en) * | 2016-11-24 | 2017-05-31 | 网易(杭州)网络有限公司 | Character displaying method, translation table generating method, document translation method and device |
CN109284145A (en) * | 2018-08-28 | 2019-01-29 | 北京城市网邻信息技术有限公司 | The generation of multilingual configuration file and methods of exhibiting and device, equipment and medium |
CN110413574A (en) * | 2019-07-30 | 2019-11-05 | 深圳市携众通科技有限公司 | A kind of method of automatic code generating internationalized resources |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113760361A (en) * | 2021-08-17 | 2021-12-07 | 中科曙光国际信息产业有限公司 | Code file generation method, computer device and readable storage medium |
CN113778594A (en) * | 2021-08-24 | 2021-12-10 | 行云智网络科技(北京)有限公司 | Multi-language application package generation method and system |
CN113885882A (en) * | 2021-10-29 | 2022-01-04 | 四川效率源信息安全技术股份有限公司 | Method for restoring iOS type character string |
CN113885882B (en) * | 2021-10-29 | 2023-03-07 | 四川效率源信息安全技术股份有限公司 | Method for restoring iOS type character string |
CN114138282A (en) * | 2021-11-30 | 2022-03-04 | 四川效率源信息安全技术股份有限公司 | Method and device for restoring pseudo code of iOS type code |
CN114138282B (en) * | 2021-11-30 | 2023-03-31 | 四川效率源信息安全技术股份有限公司 | Method and device for restoring pseudo code of iOS type code |
CN114371996A (en) * | 2021-12-30 | 2022-04-19 | 浙江中控技术股份有限公司 | JS file testing method and device |
CN114489839A (en) * | 2022-01-12 | 2022-05-13 | 海南车智易通信息技术有限公司 | Method and device for loading configuration data aiming at page and server |
CN114489839B (en) * | 2022-01-12 | 2023-08-01 | 海南车智易通信息技术有限公司 | Method and device for loading configuration data on page and server |
CN116522966A (en) * | 2023-06-30 | 2023-08-01 | 天津华来科技股份有限公司 | Text translation method and system based on multilingual vocabulary entry |
CN116522966B (en) * | 2023-06-30 | 2023-09-15 | 天津华来科技股份有限公司 | Text translation method and system based on multilingual vocabulary entry |
CN117709362A (en) * | 2023-11-22 | 2024-03-15 | 赛力斯汽车有限公司 | Method, device, computer equipment and storage medium for modifying multilingual resources |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113139390A (en) | Language conversion method and device applied to code character strings | |
CN107832045B (en) | Method and apparatus for cross programming language interface conversion | |
CN107402746B (en) | Method and device for automatically generating code file | |
CN111831384B (en) | Language switching method, device, equipment and storage medium | |
US20190042792A1 (en) | Technique used in text analysis in a safe manner | |
CN113010181A (en) | Deployment method and device of operators in deep learning framework and electronic equipment | |
CN111736840A (en) | Compiling method and running method of applet, storage medium and electronic equipment | |
CN107526742B (en) | Method and apparatus for processing multilingual text | |
US11994980B2 (en) | Method, device and computer program product for application testing | |
US20190188004A1 (en) | Software application dynamic linguistic translation system and methods | |
US10282174B2 (en) | Software layout processing localization | |
US8788257B1 (en) | Unified cross platform input method framework | |
CN111639504A (en) | Multi-language translation method, device and equipment for webpage | |
KR102531507B1 (en) | Method, device, equipment and storage medium for outputting information | |
CN113641433A (en) | Multi-language page conversion method and unit of front-end internationalized multi-language file based on i18n technology | |
CN111443979B (en) | Document processing method, device, computer equipment and storage medium | |
US20230153550A1 (en) | Machine Translation Method and Apparatus, Device and Storage Medium | |
CN113760274B (en) | Front-end assembly logic injection method and device | |
US11966562B2 (en) | Generating natural languages interface from graphic user interfaces | |
CN110765097A (en) | Data processing method and device, computer storage medium and electronic equipment | |
CN113361286B (en) | Information prompting method and device | |
CN111279350B (en) | System and method for providing globalization features in service management application interfaces | |
CN115618887B (en) | Dynamic long text internationalization method, device, equipment and storage medium | |
CN113296754B (en) | Script language conversion method, editor, equipment and storage medium based on xml | |
CN114416035A (en) | Data processing method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |