CN110134397A - Code snippet interpretation method, device, computer equipment and storage medium - Google Patents

Code snippet interpretation method, device, computer equipment and storage medium Download PDF

Info

Publication number
CN110134397A
CN110134397A CN201910296127.5A CN201910296127A CN110134397A CN 110134397 A CN110134397 A CN 110134397A CN 201910296127 A CN201910296127 A CN 201910296127A CN 110134397 A CN110134397 A CN 110134397A
Authority
CN
China
Prior art keywords
code
translated
translation
code snippet
snippet
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
Application number
CN201910296127.5A
Other languages
Chinese (zh)
Inventor
邹檬帆
计波
方秉纲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
OneConnect Smart Technology Co Ltd
Original Assignee
OneConnect Smart Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by OneConnect Smart Technology Co Ltd filed Critical OneConnect Smart Technology Co Ltd
Priority to CN201910296127.5A priority Critical patent/CN110134397A/en
Priority to SG11201907251RA priority patent/SG11201907251RA/en
Priority to PCT/CN2019/091823 priority patent/WO2020206838A1/en
Publication of CN110134397A publication Critical patent/CN110134397A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Machine Translation (AREA)

Abstract

This application involves a kind of code snippet interpretation method, device, computer equipment and storage mediums.This method comprises: obtaining analysis result set to be translated;It include code snippet to be translated, and context code snippet corresponding with code snippet to be translated in analysis result set to be translated;It searches and the matched code processor of code snippet to be translated;By code processor based on context code snippet, the target language type and Translation Strategy of code snippet to be translated are identified;Translater interface is called by code processor, obtains the translation offspring's chip segment for the target language type corresponding with code snippet to be translated translated based on Translation Strategy.It, being capable of code internationalization translation process raising code translation result reliability using this method by code quality tool.

Description

Code snippet interpretation method, device, computer equipment and storage medium
Technical field
This application involves field of computer technology, set more particularly to a kind of code snippet interpretation method, device, computer Standby and storage medium.
Background technique
With international increasingly deep development, developed software systems can face the various regions and nations that meet the needs of the world Demand, it is therefore desirable to the source code of software systems is translated as language-specific from source language.In traditional approach, usually by Business analyst collects translation demand and document is written, and application developer is then given to repair according to document to source code Change.However traditional code internationalization translation process needs business analyst and developer to cooperate completion, the time at This and human cost are high, and when developer implements to the translation thinking of business analyst in practice, to be easy to appear translation wrong Accidentally, by manually carrying out a large amount of translations, it is difficult to guarantee the uniformity of code translation, so as to cause translation result reliability Difference.
Summary of the invention
Based on this, it is necessary in view of the above technical problems, provide a kind of generation that can be improved code translation result reliability Chip segment interpretation method, device, computer equipment and storage medium.
A kind of code snippet interpretation method, which comprises obtain analysis result set to be translated;The analysis to be translated It include code snippet to be translated, and context code snippet corresponding with the code snippet to be translated in result set;Search with The matched code processor of code snippet to be translated;By the code processor according to the context code snippet, Identify the target language type and Translation Strategy of code snippet to be translated;Translater is called to connect by the code processor Mouthful, obtain the translation offspring's chip for the target language type corresponding with code snippet to be translated translated based on the Translation Strategy Section.
It is described in one of the embodiments, to obtain analysis result set to be translated, comprising: to obtain source code text to be translated Part;Read the source code directory in the source code file to be translated;Comprising multiple initial in the source code directory to be translated Filename;The corresponding initial code subfile of each original document name is traversed, code subfile to be translated is filtered out;It is described Code subfile to be translated matches with preset language type;Search the resolver with the preset language type matching;Pass through The resolver parses the code subfile to be translated, obtains analysis result set to be translated;The analysis to be translated In result set comprising in the code subfile to be translated code snippet to be translated and it is corresponding with code snippet to be translated on Hereafter code snippet.
It in one of the embodiments, also include segment location information in the analysis result set to be translated;Described logical The code processor is crossed according to the context code snippet, the target language type of code snippet to be translated is identified and turns over After translating strategy, further includes: determine translating operation according to the Translation Strategy;When the translating operation is replacement operation, base It, will be to be translated in the corresponding replacement source code file to be translated of translation offspring's chip segment in the segment location information Code snippet;Source code file after the translation of output target language type.
The lookup and the matched code processor of code snippet to be translated in one of the embodiments, comprising: Identify the programming language type of the code snippet to be translated;Search code processor collection corresponding with the programming language type It closes;By the code snippet to be translated matching condition progress corresponding with each code processor in code processor set Match;By the corresponding code processor of matched matching condition, as with the matched code processor of code snippet to be translated.
It is described in one of the embodiments, that translater interface is called by the code processor, it obtains based on described Translation offspring's chip segment of the target language type corresponding with code snippet to be translated of Translation Strategy translation, comprising: obtain and use Family mark;It is raw according to the user identifier, code snippet, the target language type and the Translation Strategy to be translated At translation request;The translation request is sent to translating server by translater interface;The translation request is used to indicate The translating server is after being verified the user identifier, using the Translation Strategy by the code piece to be translated Section is translated as the target language type;Receive the translation offspring's chip for the target language type that the translating server returns Section.
In one of the embodiments, it is described according to the user identifier, code snippet to be translated, target language type with And Translation Strategy generates translation request;By the user identifier, code snippet to be translated, target language type and Translation Strategy Splicing generates init string;The init string is encrypted, request character string is obtained;According to the request word Symbol concatenates into translation request.
A kind of code snippet translating equipment, described device include: acquisition module, for obtaining analysis result set to be translated; It include code snippet to be translated, and context generation corresponding with the code snippet to be translated in the analysis result set to be translated Chip segment;Searching module, for searching and the matched code processor of code snippet to be translated;Identification module, for leading to The code processor is crossed according to the context code snippet, the target language type of code snippet to be translated is identified and turns over Translate strategy;Translation module obtains translating based on the Translation Strategy for calling translater interface by the code processor Target language type corresponding with code snippet to be translated translation offspring's chip segment.
The searching module is also used to identify the programming language of the code snippet to be translated in one of the embodiments, Type;Search code processor set corresponding with the programming language type;At the code snippet to be translated and code The corresponding matching condition of each code processor in reason device set is matched;At the corresponding code of matched matching condition Manage device, as with the matched code processor of code snippet to be translated.
A kind of computer equipment, including memory and processor, the memory are stored with computer program, the processing The step of device realizes above-mentioned each code snippet interpretation method as described in the examples when executing the computer program.
A kind of computer readable storage medium, is stored thereon with computer program, and the computer program is held by processor The step of above-mentioned each code snippet interpretation method as described in the examples is realized when row.
Above-mentioned code snippet interpretation method, device, computer equipment and storage medium, code server obtain to be translated point After analysing result set, the matched code processor of code snippet to be translated for including in analysis result set to be translated can be searched, and By the corresponding context code snippet of code snippet to be translated, identifies the target language type of code snippet to be translated and turn over Translate strategy.Code server can by code processor call translater interface, obtain based on Translation Strategy translate with wait turn over Translate translation offspring's chip segment of the corresponding target language type of code snippet.In conjunction with the grammer of code snippet to be translated itself, lead to It crosses default targetedly code processor and treats interpreter code segment and handled, obtain targetedly Translation Strategy, so as to It is enough to be translated by calling translater interface to realize that the automation of code snippet to be translated is unified, it ensure that the reliable of translation result Property.
Detailed description of the invention
Fig. 1 is the application scenario diagram of code snippet interpretation method in one embodiment;
Fig. 2 is the flow diagram of code snippet interpretation method in one embodiment;
Fig. 3 is the flow diagram of code snippet interpretation method in another embodiment;
Fig. 4 is the structural block diagram of code snippet translating equipment in one embodiment;
Fig. 5 is the internal structure chart of computer equipment in one embodiment.
Specific embodiment
It is with reference to the accompanying drawings and embodiments, right in order to which the objects, technical solutions and advantages of the application are more clearly understood The application is further elaborated.It should be appreciated that specific embodiment described herein is only used to explain the application, not For limiting the application.
Code snippet interpretation method provided by the present application, can be applied in application environment as shown in Figure 1.Wherein, generation Code server 102 is communicated with translating server 104 by network.Wherein, code server 102 and translating server 104 It can be realized with the server cluster of the either multiple server compositions of independent server.Code server 102 obtains packet After analysis result set to be translated containing code snippet to be translated and context code snippet corresponding with code snippet to be translated, It can search and the matched code processor of code snippet to be translated.Based on context code server 102 passes through code processor Code snippet identifies the target language type and Translation Strategy of code snippet to be translated.Code server 102 passes through at code It manages device and calls translater interface, code snippet to be translated can be sent to the corresponding translating server 104 of translater and translated, Obtain the translation offspring's chip segment for the target language type corresponding with code snippet to be translated translated based on Translation Strategy.
In one embodiment, as shown in Fig. 2, providing a kind of code snippet interpretation method, it is applied to Fig. 1 in this way In code server 102 for be illustrated, comprising the following steps:
Step 202, analysis result set to be translated is obtained;It include code snippet to be translated in analysis result set to be translated, and Context code snippet corresponding with code snippet to be translated.
Analysis result set to be translated, which refers to treat after translation source code file is parsed, to be obtained, include with it is multiple to The set of the corresponding corresponding analysis result to be translated of interpreter code segment.Analysis result to be translated includes source generation to be translated Code snippet to be translated and its relevant information in code file.It may include one or more generations to be translated in analysis result set to be translated Chip segment.Source code file to be translated refers to the source code file translated.Source code file refer to it is uncompiled by According to the text file of certain programming language specification writing.Code snippet to be translated refers in source code file to be translated Source language type, the code snippet that needs to translate into target language type.Context code snippet refers to code to be translated The code snippet of segment front and back preset characters length in source code file to be translated.Such as available code to be translated The code snippet of 50 character lengths in front and back of segment, the context code snippet as code snippet to be translated.
Step 204, it searches and the matched code processor of code snippet to be translated.
Code processor, which refers to, carries out grammer identification, risk identification, translation processing and shape for treating interpreter code segment The processor of the operations such as state mark.Can the code snippet to be translated in advance to different programming language types be arranged at different codes Device is managed, is accurately operated so that code processor can more targetedly treat interpreter code segment, to realize More accurately code snippet is translated.
In one embodiment, it searches and the matched code processor of code snippet to be translated, comprising: identify generation to be translated The programming language type of chip segment;Search code processor set corresponding with programming language type;By code snippet to be translated Matching condition corresponding with each code processor in code processor set is matched;Matched matching condition is corresponding Code processor, as with the matched code processor of code snippet to be translated.
Programming language type includes but is not limited to that (JavaScript XML, one kind is in React by JS (JavaScript), JSX Set up the class XML grammer of internal build label) etc., it is without being limited thereto.Code snippet to be translated can be identified based on regular expression Become language form.Regular expression is a kind of logical formula to string operation, is exactly with more predefined The combination of specific character and these specific characters forms one " regular character string ", this " regular character string " can be used to express To a kind of filter logic of character string.Each programming language type has corresponding one or more regular expressions.
Corresponding code processor set can be predefined for each programming language type.Each code processor There is customized matching condition.Matching condition include but is not limited to code snippet to be translated be related to character string type condition, Code snippet to be translated is related to the condition of service logic and code snippet to be translated is related to configuration item attribute in configuration file Condition, it is without being limited thereto.According to matching condition, the code with interpreter code fragment match can be found from code processor set Processor.
Step 206, by code processor based on context code snippet, the object language of code snippet to be translated is identified Type and Translation Strategy.
Code processor is analyzed in combination with the grammer that context code snippet treats interpreter code segment, to identify Translation Strategy corresponding to code snippet to be translated.Different Translation Strategies can be preset for different code snippets to be translated. Translation Strategy includes whether to be replaced operation, carries out different translating operations corresponding to the code snippets to be translated of different grammers Deng.Interpreter code segment, which can be more accurately treated, by obtained context code snippet carries out syntactic analysis.
In one embodiment, Translation Strategy includes whether to be replaced operation.For example, when code snippet to be translated When for service logic correlative code, for example it is related to Rule of judgment (if/switch) and splits service logics such as (split) Code snippet to be translated, without replacement operation.When code snippet to be translated is correlative code meaningless for user, than When exporting the code snippet to be translated being related to such as code annotation and console, without replacement operation.Translation Strategy may also include Code snippet to be translated corresponding to different grammers carries out different interpretative systems, for example for the string type in JS, uses Double quotation marks includes, and for the character string template and JSX TEXT type in JS, include without double quotation marks.Translation survey strategy may be used also Interpretative system is carried out based on configuration item attribute in configuration file is related to.Such as when the directReplace of configuration file setting matches Set an attribute be true when, illustrate by the way of directly modifying source code file to be translated;When configuration item attribute is false When, illustrate then to use pre-customized Translation Strategy, for example offspring will be translated using not replacing directly using translation dictionary mode Chip segment is stored into resource distribution file.Also Translation Strategy can be determined based on third side plug, such as react (JSX) Code snippet to be translated, using react-intl-universal plug-in unit provide Translation Strategy, by customizing replacement in advance Rule, so that replaced translation offspring's chip segment meets the corresponding syntax rule of third side plug.
Step 208, by code processor call translater interface, obtain based on Translation Strategy translate with generation to be translated Translation offspring's chip segment of the corresponding target language type of chip segment.
Translater interface refers to interface that translator system provides, can be used for realizing interpretative function by calling.Translation Device system can be deployed on translating server.Translator system include but is not limited to Baidu's translater or Google's translater etc. wherein It is one or more.Code snippet to be translated can be translated as corresponding target language type based on Translation Strategy by translator system Translate offspring's chip segment.Target language type including but not limited to Chinese, Khmer, Thai, Burmese and Laotian etc. is wherein One or more language forms.
In above-mentioned code snippet interpretation method, after code server obtains analysis result set to be translated, it can search wait turn over The matched code processor of code snippet to be translated for including in analysis result set is translated, and corresponding by code snippet to be translated Context code snippet identifies the target language type and Translation Strategy of code snippet to be translated.Code server can pass through Code processor calls translater interface, obtains the object language corresponding with code snippet to be translated translated based on Translation Strategy Translation offspring's chip segment of type.In conjunction with the grammer of code snippet to be translated itself, pass through default targetedly code processor It treats interpreter code segment to be handled, obtains targetedly Translation Strategy, so as to by calling translater interface to realize The automation of code snippet to be translated is unified to translate, and ensure that the reliability of translation result.
In one embodiment, analysis result set to be translated is obtained, comprising: obtain source code file to be translated;Read to Translate the source code directory in source code file;It include multiple original document names in source code directory to be translated;Traversal is each just The corresponding initial code subfile of beginning filename, filters out code subfile to be translated;Code subfile to be translated and default language Speech type matches;Search the resolver with preset language type matching;Interpreter code subfile is treated by resolver to carry out Parsing, obtains analysis result set to be translated;Include the generation to be translated in code subfile to be translated in analysis result set to be translated Chip segment and context code snippet corresponding with code snippet to be translated.
Source code to be translated can be pre-stored in the database of code server, and code server can be directly from local data base It is middle to obtain source code file to be translated;Code server also can receive the code file to be translated or other servers that terminal uploads The source code file to be translated sent.Initial code subfile refers to minimum particle size, Wu Fajin in source code file to be translated The source code file of one step expansion.Code subfile to be translated refer to it is matching with preset language type, need to translate into mesh Mark the initial code subfile of language form.Interpreter code subfile can be treated by resolver to be parsed, to generation to be translated Code to be processed in numeral file carries out syntactic analysis, and the code snippet to be translated in code to be processed can be obtained.
In one embodiment, code server can detect the code snippet to be translated in code subfile to be translated;It draws Divide segment location information of the code snippet to be translated in code subfile to be translated;Segment location information includes start bit confidence Breath and end position information;Based on start position information and end position information extraction code snippet to be translated;According to be translated Code snippet, start position information and end position information generate analysis result set to be translated.It can in analysis result set to be translated Include multiple code snippets to be translated and segment location information corresponding with each code snippet to be translated.Each generation to be translated Chip segment and segment location information corresponding with accordingly code snippet to be translated can be used as an analysis result to be translated.
It in one embodiment, also include segment location information in analysis result set to be translated;Passing through code processor Based on context code snippet, after the target language type and Translation Strategy that identify code snippet to be translated, further includes: root Translating operation is determined according to Translation Strategy;When operation of serving as interpreter is replacement operation, it is based on segment location information, offspring's chip will be translated The corresponding code snippet to be translated replaced in source code file to be translated of section;Source code is literary after exporting the translation of target language type Part.
Translating operation, which refers to, treats the operation that the code snippet to be translated in translation source code file is handled.Translation behaviour Make to be the one or more of them such as replacement operation, labeling operation.Code server can be based in corresponding analysis result to be translated The segments such as location information in corresponding code subfile to be translated of source code file path to be translated, code snippet to be translated Translation offspring's chip segment information is treated the code snippet to be translated translated in source code file and is replaced by location information, with Realize the translation of source code file to be translated;Source code file after the corresponding translation of target language type after output translation.
In one embodiment, by code processor call translater interface, obtain based on Translation Strategy translate with Translation offspring's chip segment of the corresponding target language type of code snippet to be translated, comprising: obtain user identifier;It is marked according to user Knowledge, code snippet to be translated, target language type and Translation Strategy generate translation request;Translation request is connect by translater Mouth is sent to translating server;Translation request is used to indicate translating server after being verified to user identifier, using turning over It translates strategy and code snippet to be translated is translated as target language type;Receive turning over for the target language type that translating server returns Translate offspring's chip segment.
User identifier refers to that the mark for authentication code server identity, user identifier include but is not limited to code service The user account that device side registers in translator system.After code server generates translation request, translater interface is called, is made Translating server can be treated interpreter code segment and carried out translation processing based on translation request.Translating server can will be according to translation The translation offspring's chip segment for the target language type that policy transformation obtains is back to code server.
In one embodiment, raw according to user identifier, code snippet to be translated, target language type and Translation Strategy At translation request;User identifier, code snippet to be translated, target language type and Translation Strategy are spliced and generate original character String;Init string is encrypted, request character string is obtained;According to request text string generation translation request.
Such as init string can be encrypted according to MD5 (Message-Digest Algorithm, informative abstract) Algorithm is encrypted, to prevent the disclosure risk of init string, guarantees the safety of init string.When analysis to be translated When in result set including multiple code snippets to be translated, a translation request can be generated according to each code snippet to be translated, Translating server is sent to one by one to be translated.Translation request can also be generated according to multiple code snippets to be translated, to reduce The calling quantity of overall translation request improves the execution stability to multiple code snippet translations to be translated.
In one embodiment, it after code processor handles each section of matched code snippet to be translated, can all generate One unique processing step mark, can also mark in analysis result set to be translated that treated by processing step mark Code snippet to be translated, in order to the inquiry of subsequent processing step.For example, can then be searched when getting search key The corresponding unique search result of search key.Processing step mark can for by letter, number, punctuation mark etc. one of which or The character string of a variety of compositions.For example processing step mark can be started with P, centre is progressive whole number, is ended up with E.It can with E ending To improve the efficiency of search.For example, then search result can be P10, P101, P1000 etc. when search key is P10, this Search efficiency will be reduced.But when search key is P10E, then search result is single P10E.
In one embodiment, by executing code processor to the code snippet to be translated in analysis result set to be translated After being handled, can the translation result to every section of code snippet to be translated carry out risk class assessment, can also be to processing State is recorded.According to the corresponding customized risk rule of the code processor of selection, this section of code translation result is carried out Risk class assessment.
Risk class includes but is not limited to low risk level, potential risk grade and high-risk grade etc..When process pair Context code snippet finds that this section of code snippet to be translated is a part of some string-concatenation after being checked, then says Bright automatic translation in this case is often incorrect, the code snippet to be translated can be labeled as potential risk grade.Or work as It still include the character string of source language type in discovery translation offspring's chip segment after checking translation result, then explanation is turned over It translates device system and does not carry out accurate translation, which can be labeled as potential risk grade.It is translated when detecting Device interface malloc failure malloc causes to translate when not completing, and the code snippet to be translated can be labeled as high-risk grade.Or it ought be not When finding code processor matched with code snippet to be translated, which can be labeled as high risk etc. Grade.
Processing status includes but is not limited to untreated state, does not replace state, alert status and processed state etc..Not Processing status includes not finding the matched code processor of code snippet to be translated.The state of replacing does not include code piece to be translated Section is that code annotation and console export, without being replaced operation.Alert status includes that code snippet to be translated is related to industry Business logic, can not be replaced operation easily.Processed state includes that translation, replacement behaviour has been carried out in code snippet to be translated Make.
In one embodiment, processing can be labeled to translation offspring's chip segment.Each section is handled by processor The translation offspring's chip segment crossed can translate offspring's chip segment to this section and be labeled, and mark can use the hand of code annotation Section, to achieve the purpose that prompt and quickly position.The information of mark includes but is not limited to processing step mark, code processor mark The information such as knowledge, processing status and risk class.By the annotation, developer can quickly be helped to understand translation offspring's chip segment Processing pass through.
In one embodiment, it can also carry out the ending processing of customization after translation.It can be directed to different programming languages in advance The source code file to be translated of speech type presets different ending processing.Such as react (JSX) language, can execute with Under ending processing: according to parameter be passed to value judge whether the customized solution using resource file, if it is not, not dealing with then; If so, preset resource file is written according to scheduled path, each resource file corresponds to a kind of language form, resource file Inside it is stored with all translation offspring's chip segments.Resource file can be two, and one corresponds to source language type, and another pair is answered In source language type.
In one embodiment, it all translates when by multiple code snippets to be translated in analysis result set to be translated and obtains mesh After the translation offspring's chip segment for marking language form, source code text after the translation of target language type can be exported according to translation result Part and translation detail report.Translating in detail report may include the corresponding context code piece of each code snippet to be translated Section, translation offspring's chip segment, risk class, processing status etc..
In one embodiment, as shown in figure 3, providing another code snippet interpretation method, it is applied in this way It is illustrated for code server 102 in Fig. 1, comprising the following steps:
Step 302, source code file to be translated is obtained.
Step 304, the source code directory in source code file to be translated is read;Comprising multiple in source code directory to be translated Original document name.
Step 306, the corresponding initial code subfile of each original document name is traversed, code Ziwen to be translated is filtered out Part;Code subfile to be translated matches with preset language type.
Step 308, the resolver with preset language type matching is searched.
Step 310, interpreter code subfile is treated by resolver to be parsed, obtain analysis result set to be translated;To Comprising code snippet to be translated in code subfile to be translated and corresponding with code snippet to be translated in translation analysis result set Context code snippet.
Step 312, the programming language type of code snippet to be translated is identified.
Step 314, code processor set corresponding with programming language type is searched.
Step 316, by code snippet to be translated matching corresponding with each code processor in code processor set Condition is matched.
Step 318, by the corresponding code processor of matched matching condition, as with code snippet to be translated matched generation Code processor.
Step 320, by code processor based on context code snippet, the object language of code snippet to be translated is identified Type and Translation Strategy.
Step 322, by code processor call translater interface, obtain based on Translation Strategy translate with generation to be translated Translation offspring's chip segment of the corresponding target language type of chip segment.
In above-mentioned code snippet interpretation method, after code server source code file to be translated, pass through matched parsing Device treats interpreter code subfile and is parsed to obtain the analysis result set to be translated comprising code snippet to be translated.According to wait turn over The programming language type for translating code snippet, from code processor set search with it is to be translated analyze result set in include wait turn over The matched code processor of code snippet is translated, and by the corresponding context code snippet of code snippet to be translated, is identified wait turn over Translate the target language type and Translation Strategy of code snippet.Code server can call translater to connect by code processor Mouthful, obtain the translation offspring's chip segment for the target language type corresponding with code snippet to be translated translated based on Translation Strategy. In conjunction with the grammer of code snippet to be translated itself, treated at interpreter code segment by default targetedly code processor Reason, obtains targetedly Translation Strategy, so as to by calling translater interface to realize the automation of code snippet to be translated Unified translation, ensure that the reliability of translation result.
It should be understood that although each step in the flow chart of Fig. 2 and 3 is successively shown according to the instruction of arrow, It is these steps is not that the inevitable sequence according to arrow instruction successively executes.Unless expressly stating otherwise herein, these steps There is no stringent sequences to limit for rapid execution, these steps can execute in other order.Moreover, in Fig. 2 and 3 at least A part of step may include that perhaps these sub-steps of multiple stages or stage are not necessarily in same a period of time to multiple sub-steps Quarter executes completion, but can execute at different times, the execution in these sub-steps or stage be sequentially also not necessarily according to Secondary progress, but in turn or can replace at least part of the sub-step or stage of other steps or other steps Ground executes.
In one embodiment, as shown in figure 4, providing a kind of code snippet translating equipment 400, comprising: obtain module 402, for obtaining analysis result set to be translated;In analysis result set to be translated include code snippet to be translated, and with it is to be translated The corresponding context code snippet of code snippet;Searching module 404, at lookup and the matched code of code snippet to be translated Manage device;Identification module 406 identifies the mesh of code snippet to be translated for passing through code processor based on context code snippet Mark language form and Translation Strategy;Translation module 408 is based on for calling translater interface by code processor Translation offspring's chip segment of the target language type corresponding with code snippet to be translated of Translation Strategy translation.
In one embodiment, it obtains module 402 and is also used to obtain source code file to be translated;Read source code to be translated Source code directory in file;It include multiple original document names in source code directory to be translated;It is right to traverse each original document name The initial code subfile answered filters out code subfile to be translated;Code subfile to be translated and preset language type phase Match;Search the resolver with preset language type matching;Interpreter code subfile is treated by resolver to be parsed, obtain to Translation analysis result set;In analysis result set to be translated comprising in code subfile to be translated code snippet to be translated and with to The corresponding context code snippet of interpreter code segment.
It in one embodiment, also include segment location information in analysis result set to be translated;The device further includes output Module, for determining translating operation according to Translation Strategy;When operation of serving as interpreter is replacement operation, it is based on segment location information, it will Translate the corresponding code snippet to be translated replaced in source code file to be translated of offspring's chip segment;Output target language type is turned over Translate rear source code file.
In one embodiment, searching module 404 is also used to identify the programming language type of code snippet to be translated;It searches Code processor set corresponding with programming language type;By each generation in code snippet to be translated and code processor set The corresponding matching condition of code processor is matched;By the corresponding code processor of matched matching condition, as with it is to be translated The matched code processor of code snippet.
In one embodiment, translation module 408 is also used to obtain user identifier;According to user identifier, code to be translated Segment, target language type and Translation Strategy generate translation request;Translation request is sent to translation by translater interface Server;Translation request is used to indicate translating server after being verified to user identifier, will be wait turn over using Translation Strategy It translates code snippet and is translated as target language type;Receive the translation offspring's chip for the target language type that translating server returns Section.
In one embodiment, translation module 408 is also used to user identifier, code snippet to be translated, object language class Type and Translation Strategy splicing generate init string;Init string is encrypted, request character string is obtained;According to Request text string generation translation request.
Specific about code snippet translating equipment limits the limit that may refer to above for code snippet interpretation method Fixed, details are not described herein.Modules in above-mentioned code snippet translating equipment can fully or partially through software, hardware and its Combination is to realize.Above-mentioned each module can be embedded in the form of hardware or independently of in the processor in computer equipment, can also be with It is stored in the memory in computer equipment in a software form, in order to which processor calls the above modules of execution corresponding Operation.
In one embodiment, a kind of computer equipment is provided, which can be server, internal junction Composition can be as shown in Figure 5.The computer equipment include by system bus connect processor, memory, network interface and Database.Wherein, the processor of the computer equipment is for providing calculating and control ability.The memory packet of the computer equipment Include non-volatile memory medium, built-in storage.The non-volatile memory medium is stored with operating system, computer program and data Library.The built-in storage provides environment for the operation of operating system and computer program in non-volatile memory medium.The calculating The database of machine equipment is for storing the data such as analysis result set to be translated.The network interface of the computer equipment is used for and outside Terminal by network connection communication.To realize a kind of code snippet interpretation method when the computer program is executed by processor.
It will be understood by those skilled in the art that structure shown in Fig. 5, only part relevant to application scheme is tied The block diagram of structure does not constitute the restriction for the computer equipment being applied thereon to application scheme, specific computer equipment It may include perhaps combining certain components or with different component layouts than more or fewer components as shown in the figure.
In one embodiment, another computer equipment, including memory and processor, memory storage are provided There is computer program, which realizes the code snippet interpretation method in above-mentioned each embodiment when executing computer program Step.
In one embodiment, another computer readable storage medium is provided, computer program is stored thereon with, is counted Calculation machine program realizes the step of code snippet interpretation method in above-mentioned each embodiment when being executed by processor.
Those of ordinary skill in the art will appreciate that realizing all or part of the process in above-described embodiment method, being can be with Relevant hardware is instructed to complete by computer program, the computer program can be stored in a non-volatile computer In read/write memory medium, the computer program is when being executed, it may include such as the process of the embodiment of above-mentioned each method.Wherein, To any reference of memory, storage, database or other media used in each embodiment provided herein, Including non-volatile and/or volatile memory.Nonvolatile memory may include read-only memory (ROM), programming ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM) or flash memory.Volatile memory may include Random access memory (RAM) or external cache.By way of illustration and not limitation, RAM is available in many forms, Such as static state RAM (SRAM), dynamic ram (DRAM), synchronous dram (SDRAM), double data rate sdram (DDRSDRAM), enhancing Type SDRAM (ESDRAM), synchronization link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic ram (DRDRAM) and memory bus dynamic ram (RDRAM) etc..
Each technical characteristic of above embodiments can be combined arbitrarily, for simplicity of description, not to above-described embodiment In each technical characteristic it is all possible combination be all described, as long as however, the combination of these technical characteristics be not present lance Shield all should be considered as described in this specification.
The several embodiments of the application above described embodiment only expresses, the description thereof is more specific and detailed, but simultaneously It cannot therefore be construed as limiting the scope of the patent.It should be pointed out that coming for those of ordinary skill in the art It says, without departing from the concept of this application, various modifications and improvements can be made, these belong to the protection of the application Range.Therefore, the scope of protection shall be subject to the appended claims for the application patent.

Claims (10)

1. a kind of code snippet interpretation method, which comprises
Obtain analysis result set to be translated;In the analysis result set to be translated include code snippet to be translated, and with it is described to The corresponding context code snippet of interpreter code segment;
It searches and the matched code processor of code snippet to be translated;
By the code processor according to the context code snippet, the target language type of code snippet to be translated is identified And Translation Strategy;
By the code processor call translater interface, obtain based on the Translation Strategy translate with code piece to be translated Translation offspring's chip segment of the corresponding target language type of section.
2. the method according to claim 1, wherein described obtain analysis result set to be translated, comprising:
Obtain source code file to be translated;
Read the source code directory in the source code file to be translated;Comprising multiple initial in the source code directory to be translated Filename;
The corresponding initial code subfile of each original document name is traversed, code subfile to be translated is filtered out;It is described to Interpreter code subfile matches with preset language type;
Search the resolver with the preset language type matching;
The code subfile to be translated is parsed by the resolver, obtains analysis result set to be translated;It is described to In translation analysis result set comprising in the code subfile to be translated code snippet to be translated and with code snippet to be translated Corresponding context code snippet.
3. according to the method described in claim 2, it is characterized in that, also being positioned comprising segment in the analysis result set to be translated Information;It is described by the code processor according to the context code snippet, identify the target of code snippet to be translated After language form and Translation Strategy, further includes:
Translating operation is determined according to the Translation Strategy;
When the translating operation is replacement operation, it is based on the segment location information, translation offspring's chip segment is corresponding Replace the code snippet to be translated in the source code file to be translated;
Source code file after the translation of output target language type.
4. the method according to claim 1, wherein the lookup and the code snippet matched generation to be translated Code processor, comprising:
Identify the programming language type of the code snippet to be translated;
Search code processor set corresponding with the programming language type;
The code snippet to be translated matching condition corresponding with each code processor in code processor set is carried out Matching;
By the corresponding code processor of matched matching condition, as with the matched code process of code snippet to be translated Device.
5. the method according to claim 1, wherein described call translater to connect by the code processor Mouthful, obtain the translation offspring's chip for the target language type corresponding with code snippet to be translated translated based on the Translation Strategy Section, comprising:
Obtain user identifier;
It is generated according to the user identifier, code snippet, the target language type and the Translation Strategy to be translated Translation request;
The translation request is sent to translating server by translater interface;The translation request is used to indicate the translation The code snippet to be translated is translated as by server after being verified to the user identifier, using the Translation Strategy The target language type;
Receive the translation offspring's chip segment for the target language type that the translating server returns.
6. according to the method described in claim 5, it is characterized in that, it is described according to the user identifier, code snippet to be translated, Target language type and Translation Strategy generate translation request;
The user identifier, code snippet to be translated, target language type and Translation Strategy are spliced and generate init string;
The init string is encrypted, request character string is obtained;
According to the request text string generation translation request.
7. a kind of code snippet translating equipment, which is characterized in that described device includes:
Module is obtained, for obtaining analysis result set to be translated;It include code piece to be translated in the analysis result set to be translated Section, and context code snippet corresponding with the code snippet to be translated;
Searching module, for searching and the matched code processor of code snippet to be translated;
Identification module, for, according to the context code snippet, identifying code snippet to be translated by the code processor Target language type and Translation Strategy;
Translation module is obtained for calling translater interface by the code processor based on Translation Strategy translation Translation offspring's chip segment of target language type corresponding with code snippet to be translated.
8. device according to claim 7, which is characterized in that the searching module is also used to identify the code to be translated The programming language type of segment;
Search code processor set corresponding with the programming language type;
The code snippet to be translated matching condition corresponding with each code processor in code processor set is carried out Matching;
By the corresponding code processor of matched matching condition, as with the matched code process of code snippet to be translated Device.
9. a kind of computer equipment, including memory and processor, the memory are stored with computer program, feature exists In the step of processor realizes any one of claims 1 to 6 the method when executing the computer program.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the computer program The step of method described in any one of claims 1 to 6 is realized when being executed by processor.
CN201910296127.5A 2019-04-12 2019-04-12 Code snippet interpretation method, device, computer equipment and storage medium Pending CN110134397A (en)

Priority Applications (3)

Application Number Priority Date Filing Date Title
CN201910296127.5A CN110134397A (en) 2019-04-12 2019-04-12 Code snippet interpretation method, device, computer equipment and storage medium
SG11201907251RA SG11201907251RA (en) 2019-04-12 2019-06-19 Methods and apparatuses for code snippet translation, computer devices and storage mediums
PCT/CN2019/091823 WO2020206838A1 (en) 2019-04-12 2019-06-19 Code snippet translation method and apparatus, computer device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910296127.5A CN110134397A (en) 2019-04-12 2019-04-12 Code snippet interpretation method, device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN110134397A true CN110134397A (en) 2019-08-16

Family

ID=67569805

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910296127.5A Pending CN110134397A (en) 2019-04-12 2019-04-12 Code snippet interpretation method, device, computer equipment and storage medium

Country Status (3)

Country Link
CN (1) CN110134397A (en)
SG (1) SG11201907251RA (en)
WO (1) WO2020206838A1 (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110704042A (en) * 2019-10-15 2020-01-17 恩亿科(北京)数据科技有限公司 Program code processing method and device, server and storage medium
CN112015430A (en) * 2020-09-07 2020-12-01 平安国际智慧城市科技股份有限公司 JavaScript code translation method and device, computer equipment and storage medium
CN113190233A (en) * 2021-04-15 2021-07-30 中国海洋大学 Intelligent source code translation method and system for multi-source heterogeneous programming language
CN113342437A (en) * 2021-06-10 2021-09-03 网易(杭州)网络有限公司 Software translation method and device
CN113420569A (en) * 2021-06-22 2021-09-21 康键信息技术(深圳)有限公司 Code translation method, device, equipment and storage medium
CN113687883A (en) * 2020-05-18 2021-11-23 阿里巴巴集团控股有限公司 Data display method and device, electronic equipment and computer readable storage medium
WO2024148612A1 (en) * 2023-01-13 2024-07-18 华为技术有限公司 Translator generation method and apparatus, and device and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101253476A (en) * 2005-08-10 2008-08-27 微软公司 Syntactic program language translation
CN107451128A (en) * 2017-08-04 2017-12-08 深圳Tcl新技术有限公司 Multilingual code adaptation method, equipment and storage medium
CN109284145A (en) * 2018-08-28 2019-01-29 北京城市网邻信息技术有限公司 The generation of multilingual configuration file and methods of exhibiting and device, equipment and medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104899010B (en) * 2014-03-04 2018-12-21 北京金山云网络技术有限公司 The multi-lingual opinion on public affairs method and system of source code
CN107391499A (en) * 2017-08-03 2017-11-24 深圳Tcl新技术有限公司 It is automatically imported interpretation method, text importing terminal and computer-readable recording medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101253476A (en) * 2005-08-10 2008-08-27 微软公司 Syntactic program language translation
CN107451128A (en) * 2017-08-04 2017-12-08 深圳Tcl新技术有限公司 Multilingual code adaptation method, equipment and storage medium
CN109284145A (en) * 2018-08-28 2019-01-29 北京城市网邻信息技术有限公司 The generation of multilingual configuration file and methods of exhibiting and device, equipment and medium

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110704042A (en) * 2019-10-15 2020-01-17 恩亿科(北京)数据科技有限公司 Program code processing method and device, server and storage medium
CN113687883A (en) * 2020-05-18 2021-11-23 阿里巴巴集团控股有限公司 Data display method and device, electronic equipment and computer readable storage medium
CN112015430A (en) * 2020-09-07 2020-12-01 平安国际智慧城市科技股份有限公司 JavaScript code translation method and device, computer equipment and storage medium
CN113190233A (en) * 2021-04-15 2021-07-30 中国海洋大学 Intelligent source code translation method and system for multi-source heterogeneous programming language
CN113190233B (en) * 2021-04-15 2023-06-20 中国海洋大学 Intelligent source code translation method and system for multi-source heterogeneous programming language
CN113342437A (en) * 2021-06-10 2021-09-03 网易(杭州)网络有限公司 Software translation method and device
CN113420569A (en) * 2021-06-22 2021-09-21 康键信息技术(深圳)有限公司 Code translation method, device, equipment and storage medium
WO2024148612A1 (en) * 2023-01-13 2024-07-18 华为技术有限公司 Translator generation method and apparatus, and device and storage medium

Also Published As

Publication number Publication date
SG11201907251RA (en) 2020-11-27
WO2020206838A1 (en) 2020-10-15

Similar Documents

Publication Publication Date Title
CN110134397A (en) Code snippet interpretation method, device, computer equipment and storage medium
CN108932122B (en) Interface document generation method, device, computer equipment and storage medium
CN102804147B (en) Perform the code check executive system of the code check of ABAP source code
WO2020206840A1 (en) Code translation method and apparatus, computer device, and storage medium
CN106951228B (en) Method and device for processing differences in version iteration
US8850415B2 (en) Generating a transition system for use with model checking
CN109800258B (en) Data file deployment method, device, computer equipment and storage medium
WO2020206837A1 (en) Code segment positioning method and device, computer apparatus, and storage medium
CN106843840B (en) Source code version evolution annotation multiplexing method based on similarity analysis
CN109542412A (en) Interface message generation method, device, computer equipment and storage medium
CN108984612B (en) Method and device for acquiring target SQL statement, computer equipment and storage medium
CN106371997B (en) Code checking method and device
CN107346284B (en) Application program detection method and detection device
CN104156314A (en) Code reuse method applied to test system
CN112988595A (en) Dynamic synchronization test method, device, equipment and storage medium
CN113282498A (en) Test case generation method, device, equipment and storage medium
CN115640316A (en) Paging method, interceptor, plug-in and server for data query
CN103761095A (en) Method for generating universal header data information of upgraded file
CN113778852A (en) Code analysis method based on regular expression
CN111240790B (en) Multi-language adaptation method, device, client and storage medium for application
CN113778888B (en) Code automatic test method, system, equipment and storage medium
CN110806896B (en) Method for realizing internationalized information extraction in software development based on maven extension plug-in
CN107577476A (en) A kind of Android system source code difference analysis method, server and medium based on Module Division
CN113760291A (en) Log output method and device
CN112632109A (en) Information extraction method and device, electronic equipment and readable 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