CN110134401A - Code snippet localization method, device, computer equipment and storage medium - Google Patents
Code snippet localization method, device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN110134401A CN110134401A CN201910296105.9A CN201910296105A CN110134401A CN 110134401 A CN110134401 A CN 110134401A CN 201910296105 A CN201910296105 A CN 201910296105A CN 110134401 A CN110134401 A CN 110134401A
- Authority
- CN
- China
- Prior art keywords
- code
- translated
- subfile
- snippet
- file
- 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 40
- 230000004807 localization Effects 0.000 title claims abstract description 21
- 238000004458 analytical method Methods 0.000 claims abstract description 52
- 238000013519 translation Methods 0.000 claims abstract description 34
- 230000014509 gene expression Effects 0.000 claims description 23
- 238000004590 computer program Methods 0.000 claims description 17
- 238000012545 processing Methods 0.000 claims description 12
- 238000012216 screening Methods 0.000 claims description 9
- 238000000605 extraction Methods 0.000 claims description 7
- 230000005540 biological transmission Effects 0.000 claims description 4
- 235000013399 edible fruits Nutrition 0.000 claims description 2
- 239000000284 extract Substances 0.000 claims 1
- 230000008569 process Effects 0.000 abstract description 5
- 230000007306 turnover Effects 0.000 description 7
- 238000010586 diagram Methods 0.000 description 5
- 238000001514 detection method Methods 0.000 description 4
- 238000001914 filtration Methods 0.000 description 3
- 230000004069 differentiation Effects 0.000 description 2
- 238000011835 investigation Methods 0.000 description 2
- 238000013459 approach Methods 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 239000003086 colorant Substances 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000002708 enhancing effect Effects 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 230000005055 memory storage Effects 0.000 description 1
- 239000000203 mixture Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 239000002245 particle Substances 0.000 description 1
- 230000007480 spreading Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/43—Checking; Contextual analysis
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 localization method, device, computer equipment and storage mediums.This method comprises: reading the source code directory in source code file to be translated;It include multiple original document names in source code directory to be translated;The corresponding initial code subfile of each original document name is traversed, code subfile to be translated is filtered out;Code subfile to be translated matches with preset language type;Search the resolver with preset language type matching;Interpreter code subfile is treated by resolver to be parsed, and analysis destination file is obtained;It include code snippet to be translated and the segment location information corresponding with code snippet to be translated in code subfile to be translated in analysis destination file.Using this method by code quality tool, the code snippet that can be translated in efficient location code in internationalization translation process.
Description
Technical field
This application involves field of computer technology, set more particularly to a kind of code snippet localization 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 the case where, it is therefore desirable to the source code of software systems is translated as language-specific from source language.In traditional approach, lead to
It is often to collect translation demand by business analyst and document is written, then gives software developer according to document to source code
It modifies.However traditional code internationalization translation process needs business analyst to cooperate with software developer
At time cost and human cost are high, and software developer is needed manually to search what needs were translated from extensive source code
Code snippet, positions the larger workload of code snippet to be translated from source code and investigation difficulty is higher, is easy to appear code
Situations such as segment is omitted, it is difficult to efficiently location code segment.
Summary of the invention
Based on this, it is necessary to which in view of the above technical problems, providing one kind can efficiently position in internationalization translation process
Code snippet localization method, device, computer equipment and the storage medium for the code snippet translated in code.
A kind of code snippet localization method, which comprises obtain source code file to be translated;It reads described to be translated
Source code directory in source code file;It include multiple original document names in the source code directory to be translated;Traverse each institute
The corresponding initial code subfile of original document name is stated, code subfile to be translated is filtered out;The code subfile to be translated
Match with preset language type;Search the resolver with the preset language type matching;By the resolver to described
Code subfile to be translated is parsed, and analysis destination file is obtained;It include the generation to be translated in the analysis destination file
Code snippet to be translated and segment location information corresponding with code snippet to be translated in numeral file.
It is described in one of the embodiments, to traverse the corresponding initial code subfile of each original document name, sieve
Select code subfile to be translated, comprising: obtain the corresponding regular expression of a variety of preset language types;Traverse each institute
The corresponding initial code subfile of original document name is stated, the regular expression and the progress of each initial code subfile are passed through
Match;The matched preset language type of each initial code subfile is determined according to matched regular expression;It filters out comprising appointing
The initial code subfile for a kind of preset language type of anticipating, as code subfile to be translated.
It is described in one of the embodiments, that the code subfile to be translated is parsed by the resolver,
Obtain analysis destination file, comprising: detect the code snippet to be translated in code subfile to be translated;Divide the generation to be translated
Segment location information of the chip segment in the code subfile to be translated;The segment location information includes start position information
With end position information;Based on code snippet to be translated described in the start position information and the end position information extraction;
Analysis destination file is generated according to code snippet, the start position information and the end position information to be translated.
Code snippet to be translated in the detection code subfile to be translated in one of the embodiments, comprising: obtain
Modulus plate character string;The template character string is matched with code subfile to be translated, determines that the template character string exists
Engaged position information in the code subfile to be translated;It is determined according to the engaged position information of the template character string wait turn over
Translate code snippet.
The start position information and the end position information extraction institute are based on described in one of the embodiments,
After stating code snippet to be translated, further includes: be based on the start position information and the end position information, obtain it is described to
The code snippet of the front and back preset characters length of interpreter code segment, as context code snippet;In conjunction with the context generation
Chip segment is treated interpreter code segment and is parsed, and obtains and the matched syntactic information of code snippet to be translated;It will be described
Context code snippet and the syntactic information are added in the analysis destination file.
The code subfile to be translated is solved by the resolver described in one of the embodiments,
Analysis, after obtaining analysis destination file, further includes: according to the multinomial data flow of analysis destination file generation;By multinomial data
Stream is sent to translating server in a manner of parallel transmission and carries out translation processing;Receive the translation offspring that the translating server returns
Chip segment;Code snippet to be translated corresponding in the code subfile to be translated is carried out according to the translation offspring chip segment
Replacement obtains translation post code subfile.
A kind of code snippet positioning device, described device includes: acquisition module, for obtaining source code file to be translated;
Read module, user read the source code directory in the source code file to be translated;Comprising multiple in the source code directory
Original document name;Screening module is filtered out for traversing the corresponding initial code subfile of each original document name wait turn over
Translate code subfile;The code subfile to be translated matches with preset language type;Searching module, for search with it is described
The resolver of preset language type matching;Parsing module, for by the resolver to the code subfile to be translated into
Row parsing obtains analysis destination file;Comprising to be translated in the code subfile to be translated in the analysis destination file
Code snippet and segment location information corresponding with code snippet to be translated.
It is corresponding just to be also used to obtain a variety of preset language types for the screening module in one of the embodiments,
Then expression formula;The corresponding initial code subfile of each original document name is traversed, by the regular expression and each
Initial code subfile is matched;The matched default language of each initial code subfile is determined according to matched regular expression
Say type;The initial code subfile comprising any one preset language type is filtered out, as code subfile 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 localization 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 localization method as described in the examples is realized when row.
Above-mentioned code snippet localization method, device, computer equipment and storage medium, code server obtain source to be translated
After code file, the source code directory in source code file to be translated can be read.Pass through preset regular expression ergodic source
The corresponding initial code subfile of multiple original document names for including in code directory can screen to obtain and preset language type phase
Matched code subfile to be translated.After searching the resolver with preset language type matching, it can be treated and be turned over by resolver
It translates code subfile to be parsed, the analysis result text comprising code snippet to be translated and respective segments location information can be obtained
Part.By filtering out the code subfile to be translated to match with preset language type, so as to according to matched resolver
Interpreter code subfile is more targetedly treated to be parsed, so as to automate accurately and efficiently investigation orient to
Code snippet to be translated in interpreter code subfile.
Detailed description of the invention
Fig. 1 is the application scenario diagram of code snippet localization method in one embodiment;
Fig. 2 is the flow diagram of code snippet localization method in one embodiment;
Fig. 3 is the flow diagram of code snippet localization method in another embodiment;
Fig. 4 is the structural block diagram of code snippet positioning device 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 localization 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 obtain to
After translating source code file, the source code directory in source code file to be translated can be read.Code server 102 passes through traversal
The corresponding initial code subfile of multiple original document names for including in source code directory, screening obtain and preset language type phase
Matched code subfile to be translated.Code server 102 passes through solution by searching for the resolver with preset language type matching
Parser is treated interpreter code subfile and is parsed, and point comprising code snippet to be translated and respective segments location information can be obtained
Analyse destination file.Analysis destination file can be also sent to translating server 104 with data-stream form and carried out by code server 102
Translation processing.
In one embodiment, as shown in Fig. 2, providing a kind of code snippet localization method, it is applied to Fig. 1 in this way
In code server 102 for be illustrated, comprising the following steps:
Step 202, source code file to be translated is obtained.
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.Source code to be translated can be pre-stored in the database of code server
In, code server can directly obtain source code file to be translated from local data base;Code server also can receive terminal
The source code file to be translated that the code file to be translated uploaded or other servers are sent.
Step 204, 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.
After the configuration file for reading source code file to be translated, preliminary examination first can be carried out to the configuration parameter in configuration file
It looks into.After preliminary examination passes through, the source code directory in configuration file can be read.Multiple initial codes are housed in configuration file
The source code directory that the original document name of subfile generates.It can also be hierarchical structure in source code directory, be gone back in source code directory
It may include subdirectory, then source code directory can be all unfolded, the filename listed in the source code directory after expansion is all made
For original document name.
Step 206, 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.
Source code that initial code subfile refers to minimum particle size in source code file to be translated, can not further spreading out
File.Code subfile to be translated refer to it is matching with preset language type, need to translate into target language type it is initial
Code subfile.It include code snippet to be translated in code subfile to be translated.By that only will include code snippet to be translated
Code subfile to be translated screen, avoid carrying out invalidation to without the initial code subfile translated, with
Save system resource.
In one embodiment, it is based on source code directory, the corresponding file object of each original document name is obtained, by file
Object is placed in file array.Then it is unfolded by recursive mode by traversing file array when file object is subdirectory
The corresponding file object of subdirectory;When file object is initial code subfile, then directly detection and initial code subfile
Matched preset language type.
In one embodiment, when detecting initial code subfile not with any one preset language type matching,
It is processed state that the initial code subfile, which can then be marked, and the original document name of the initial code subfile is written and is analyzed
Destination file.
Step 208, the resolver with preset language type matching is searched.
Preset in code server multiple resolvers corresponding with various preset language types can be installed, pass through matching
Resolver treat interpreter code subfile and handled.Code server, which can also call, to be deployed in other computer equipments
Resolver, such as, preset on each resolution server in a kind of corresponding resolver of preset language type, generation, can be installed
Code server can be sent to corresponding resolution server and carry out by code subfile to be translated according to matched preset language type
Processing.Preset language type includes but is not limited to that Chinese, Thai, Burmese, Kampuchean and Laotian etc. are one of or more
Kind.Resolver can be self-existent application program, or operate in the plug-in unit under particular system platform.Such as resolver
It can be Babel parser (a kind of JavaScript source code resolver).
In one embodiment, the code subfile to be translated of different file format types, preset different solution can be directed to
Parser.It, can be based on the file name suffix of code subfile to be translated after the file name suffix for detecting code subfile to be translated
Corresponding file format type searches multiple resolver set corresponding with the file format type of code subfile to be translated,
The resolver with the preset language type matching of code subfile to be translated is analytically searched in device set.Such as it can distinguish
It is " .js " (JavaScript, a kind of literal translation formula scripting language) and " .jsx " (JavaScript XML, Yi Zhong for suffix
React establishment internal build label class XML grammer) the preset different resolver of code subfile to be translated.
In one embodiment, when not finding the resolver with preset language type matching, then this can be marked initial
Code subfile is untreated state, and analysis destination file is written in the original document name of the initial code subfile.
Step 210, interpreter code subfile is treated by resolver to be parsed, obtain analysis destination file;Analysis knot
In fruit file comprising in code subfile to be translated code snippet to be translated and segment corresponding with code snippet to be translated it is fixed
Position information.
Interpreter code subfile can be treated by resolver to be parsed, and the generation to be processed in interpreter code subfile is treated
Code carries out syntactic analysis, and the code snippet to be translated in code to be processed can be obtained.The code piece to be translated obtained according to analysis
Section, divides segment location information of the code snippet to be translated in code to be processed in code to be processed.For example, specific syntax
Code snippet to be translated be corresponding with specific initial character string and terminator-string, initial character string can be detected respectively wait locate
Starting location information and terminator-string in reason code, will starting positioning letter in the end location information in code to be processed
Breath and end location information are as segment location information.It can also be divided in code to be processed in advance and position multiple code pieces
Section, for example using the code of preset characters length in code to be processed as a code snippet, wrapped when detecting in code snippet
It when containing specific character string, then can be using the code snippet as code snippet to be translated.
In above-mentioned code snippet localization method, after code server obtains source code file to be translated, it can be read wait turn over
Translate the source code directory in source code file.It is corresponding initial by the multiple original document names for including in traversal source code directory
Code subfile, screening obtain the code subfile to be translated to match with preset language type.It searches and preset language type
After matched resolver, interpreter code subfile can be treated by resolver and is parsed, can obtain including code to be translated
The analysis destination file of segment and respective segments location information.By identify filter out with preset language type match wait turn over
Code subfile is translated, is parsed so as to more targetedly treat interpreter code subfile according to matched resolver,
So as to automatic high-efficiency check the code snippet to be translated oriented in code subfile to be translated.
In one embodiment, the corresponding initial code subfile of each original document name is traversed, generation to be translated is filtered out
Numeral file, comprising: obtain the corresponding regular expression of a variety of preset language types;It is corresponding to traverse each original document name
Initial code subfile, matched by regular expression with each initial code subfile;According to matched canonical table
The matched preset language type of each initial code subfile is determined up to formula;It filters out comprising any one preset language type
Initial code subfile, as code subfile to be translated.
Regular expression is a kind of logical formula to string operation, is exactly with predefined some specific words
The combination of symbol and these specific characters forms one " regular character string ", this " regular character string " can be used to express to character
A kind of filter logic of string.Each preset language type has corresponding one or more regular expressions, passes through canonical table
Up to formula it is known that in code to be processed whether the code snippet to be translated in need for carrying out translation processing, to avoid to not wrapping
Initial code subfile containing to be translated code segment is parsed, and the workload of parsing is reduced, and improves analyzing efficiency.
In one embodiment, interpreter code subfile is treated by resolver to be parsed, obtain analysis destination file,
It include: the code snippet to be translated in detection code subfile to be translated;Code snippet to be translated is divided in code to be translated
Segment location information in file;Segment location information includes start position information and end position information;Based on initial position
Information and end position information extraction code snippet to be translated;According to code snippet to be translated, start position information and stop bits
Confidence breath generates analysis destination file.
Analysis destination file is that the code in entire source code file to be translated is analyzed by language form and by parsing
The destination file generated after the syntactic analysis of device.Based on analysis, code snippet, start position information and end to be translated are extracted
Location information generates analysis destination file.It can be accurately positioned in source code file to be translated wait turn over based on analysis destination file
Code snippet is translated, carries out further code translation processing and code replacement processing so as to file based on the analysis results.
In one embodiment, the code snippet to be translated in code subfile to be translated is detected, comprising: obtain template word
Symbol string;Template character string is matched with code subfile to be translated, determines template character string in code subfile to be translated
In engaged position information;Code snippet to be translated is determined according to the engaged position information of template character string.
Code snippet to be translated can for JS String type, ES6 template type (ECMAScript 6, template character string),
A kind of one of which such as JSX text type (JavaScript XML, class XML grammer for setting up internal build label in React)
Or a plurality of types of code snippets.For example, template character string can be the corresponding character string of string object properties, such as
" constructor ", " length " etc.;Template character string can also be the corresponding character string of string object method, such as
Various characters string after " anchor () ", " fontcolor () " and " link () " etc. is one of.Due to the code of these types
Segment is related to the display of the great amount of terminals page, it is therefore desirable to using the code snippet of those types as code snippet to be translated.
In one embodiment, in addition to filtering out code snippet to be translated, can also to without translation code snippet into
Line flag.Such as by template string matching, detection if/switch Rule of judgment type, split split type etc. and are related to by force
The code snippet of the code snippet type of service logic can also detect code annotation, console output etc. without influence part
Code snippet checks differentiation so that developer is subsequent by being marked those code snippets without translation.It can be with
It is distinguished for different types of code snippet by the label of different colours, makes it possible to more intuitive differentiation and need to carry out not
With the code snippet of processing.
In one embodiment, after based on start position information and end position information extraction code snippet to be translated,
Further include: it is based on start position information and end position information, obtains the front and back preset characters length of code snippet to be translated
Code snippet, as context code snippet;Interpreter code segment is treated in conjunction with context code snippet to be parsed, obtain with
The matched syntactic information of code snippet to be translated;Context code snippet and syntactic information are added in analysis destination file.
Such as the code snippet of 50 character lengths in front and back of available code snippet to be translated, as to be translated
The context code snippet of code snippet.Interpreter code segment can be more accurately treated by obtained context code snippet
Syntactic analysis is carried out, and it is also possible that developer more intuitively understands the location information of code snippet to be translated, therefore
It is also based on context code snippet and repartitions code snippet to be translated, avoid the occurrence of the incompleteness of code snippet.It can basis
Code snippet to be translated after repartitioning redefines the start position information and stop bits confidence of code snippet to be translated
Breath.
In one embodiment, it is parsed treating interpreter code subfile by resolver, obtains analysis result text
After part, further includes: the multinomial data flow of file generated based on the analysis results;Multinomial data flow is sent in a manner of parallel transmission
Translating server carries out translation processing;Receive translation offspring's chip segment that translating server returns;According to translation offspring's chip segment
It treats corresponding code snippet to be translated in interpreter code subfile to be replaced, obtains translation post code subfile.
It may include multiple code snippets to be translated and corresponding with each code snippet to be translated for analyzing in destination file
Segment location information.Each code snippet to be translated and segment location information corresponding with accordingly code snippet to be translated can be made
For an analysis result.Each code snippet to be translated and its corresponding segment location information can be generated into an item data
Stream, multiple code snippets to be translated can then respectively correspond an item data stream.It can also be by the code snippet to be translated of predetermined number
And its corresponding segment location information one item data stream of comprehensive generation, the code snippet to be translated of predetermined number can then correspond to one
Item data stream.Segment location information include but is not limited to source code file path to be translated, code snippet to be translated accordingly to
Location information etc. in interpreter code subfile.Analysis result in also may include it is corresponding with each code snippet to be translated other
Relevant information, the context code snippet of code snippet including but not limited to be translated, code snippet to be translated are after parsing
The one or more of them such as the code syntax type of obtained respective code syntactic type and code father node to be translated.
Formed data flow after, code server can to each analysis result carry out condition matching, search with each wait turn over
The translating server of fragment match is translated, code processor can be deployed on translating server, and code snippet to be translated is upper and lower
Literary code snippet meets the alternative condition of translating server;Translating server carries out each analysis result by code processor
Processing, identifies the target language type translated into needed for source code file to be translated;Translating server is called by interface and is translated
Device obtains the translation result of target language type corresponding with each code snippet to be translated;After generating translation according to translation result
Code snippet;Translation offspring's chip segment can be back to code server by translating server.Code server can be based on corresponding point
The position of the source code file path to be translated in result, code snippet to be translated in corresponding code subfile to be translated is analysed to believe
The segments location informations such as breath will translate offspring's chip segment information and treat the code snippet to be translated progress translated in source code file
Replacement, to realize the translation of source code file to be translated;Source code after the corresponding translation of target language type after output translation
File.
In one embodiment, as shown in figure 3, providing a kind of code snippet localization method, it is applied to Fig. 1 in this way
In code server 102 for be illustrated, 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 regular expression of a variety of preset language types is obtained.
Step 308, the corresponding initial code subfile of each original document name is traversed, it is by regular expression and each first
Beginning code subfile is matched.
Step 310, the matched preset language type of each initial code subfile is determined according to matched regular expression.
Step 312, the initial code subfile comprising any one preset language type is filtered out, as code to be translated
Subfile.
Step 314, the resolver with preset language type matching is searched.
Step 316, the code snippet to be translated in code subfile to be translated is detected by resolver.
Step 318, segment location information of the code snippet to be translated in code subfile to be translated is divided;Segment positioning
Information includes start position information and end position information.
Step 320, start position information and end position information extraction code snippet to be translated are based on.
Step 322, analysis result text is generated according to code snippet to be translated, start position information and end position information
Part.
In above-mentioned code snippet localization method, after code server obtains source code file to be translated, it can be read wait turn over
Translate the source code directory in source code file.It is multiple initial by include in preset regular expression traversal source code directory
The corresponding initial code subfile of filename can screen to obtain the code subfile to be translated to match with preset language type.
After searching the resolver with preset language type matching, interpreter code subfile can be treated by resolver and is parsed, it can
Obtain the analysis destination file comprising code snippet to be translated and respective segments location information.By filtering out and preset language class
The code subfile to be translated that type matches, so as to more targetedly treat interpreter code according to matched resolver
File is parsed, so as to automate the generation to be translated accurately and efficiently checked and oriented in code subfile to be translated
Chip segment.
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 positioning device 400, comprising: obtain module
402, for obtaining source code file to be translated;Read module 404, user read the source code mesh in source code file to be translated
Record;It include multiple original document names in source code directory;Screening module 406, it is corresponding just for traversing each original document name
Beginning code subfile filters out code subfile to be translated;Code subfile to be translated matches with preset language type;It searches
Module 408, for searching and the resolver of preset language type matching;Parsing module 410, for passing through resolver to be translated
Code subfile is parsed, and analysis destination file is obtained;Analyze in destination file comprising in code subfile to be translated to
Interpreter code segment and segment location information corresponding with code snippet to be translated.
In one embodiment, screening module 406 is also used to obtain the corresponding canonical table of a variety of preset language types
Up to formula;The corresponding initial code subfile of each original document name is traversed, regular expression and each initial code Ziwen are passed through
Part is matched;The matched preset language type of each initial code subfile is determined according to matched regular expression;Screening
It out include the initial code subfile of any one preset language type, as code subfile to be translated.
In one embodiment, parsing module 410 is also used to detect the code piece to be translated in code subfile to be translated
Section;Divide segment location information of the code snippet to be translated in code subfile to be translated;Segment location information includes starting
Location information and end position information;Based on start position information and end position information extraction code snippet to be translated;According to
Code snippet, start position information and end position information to be translated generate analysis destination file.
In one embodiment, parsing module 410 is also used to obtain template character string;By template character string and generation to be translated
Numeral file is matched, and determines engaged position information of the template character string in code subfile to be translated;According to template word
The engaged position information of symbol string determines code snippet to be translated.
In one embodiment, parsing module 410 is also used to based on start position information and end position information, obtain to
The code snippet of the front and back preset characters length of interpreter code segment, as context code snippet;In conjunction with context code piece
Section is treated interpreter code segment and is parsed, and obtains and the matched syntactic information of code snippet to be translated;By context code piece
Section and syntactic information are added in analysis destination file.
In one embodiment, which further includes translation module, for the multinomial data of file generated based on the analysis results
Stream;Multinomial data flow is sent to translating server in a manner of parallel transmission and carries out translation processing;Translating server is received to return
Translation offspring's chip segment;According to translation offspring's chip segment treat in interpreter code subfile corresponding code snippet to be translated into
Row replacement obtains translation post code subfile.
Specific about code snippet positioning device limits the limit that may refer to above for code snippet localization method
Fixed, details are not described herein.Modules in above-mentioned code snippet positioning device 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 code server, in
Portion's structure chart can be as shown in Figure 5.The computer equipment includes that the processor, memory, network connected by system bus connects
Mouth and database.Wherein, the processor of the computer equipment is for providing calculating and control ability.The storage of the computer equipment
Device includes non-volatile memory medium, built-in storage.The non-volatile memory medium be stored with operating system, computer program and
Database.The built-in storage provides environment for the operation of operating system and computer program in non-volatile memory medium.It should
The database of computer equipment is for storing the data such as source code file to be translated.The network interface of the computer equipment be used for
External terminal passes through network connection communication.To realize a kind of code snippet positioning side when the computer program is executed by processor
Method.
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 localization 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 localization 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 localization method, which comprises
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 destination file;The analysis knot
Include the code snippet to be translated and piece corresponding with code snippet to be translated in the code subfile to be translated in fruit file
Section location information.
2. the method according to claim 1, wherein each original document name of traversal is corresponding initial
Code subfile filters out code subfile to be translated, comprising:
Obtain the corresponding regular expression of a variety of preset language types;
The corresponding initial code subfile of each original document name is traversed, the regular expression and each initial generation are passed through
Numeral file is matched;
The matched preset language type of each initial code subfile is determined according to matched regular expression;
The initial code subfile comprising any one preset language type is filtered out, as code subfile to be translated.
3. the method according to claim 1, wherein described sub to the code to be translated by the resolver
File is parsed, and analysis destination file is obtained, comprising:
Detect the code snippet to be translated in code subfile to be translated;
Divide segment location information of the code snippet to be translated in the code subfile to be translated;The segment positioning
Information includes start position information and end position information;
Based on code snippet to be translated described in the start position information and the end position information extraction;
Analysis result text is generated according to code snippet, the start position information and the end position information to be translated
Part.
4. according to the method described in claim 3, it is characterized in that, the generation to be translated detected in code subfile to be translated
Chip segment, comprising:
Obtain template character string;
The template character string is matched with code subfile to be translated, determines the template character string described to be translated
Engaged position information in code subfile;
Code snippet to be translated is determined according to the engaged position information of the template character string.
5. according to the method described in claim 3, it is characterized in that, being based on the start position information and the end described
Location information extracts after the code snippet to be translated, further includes:
Based on the start position information and the end position information, the front and back predetermined word of the code snippet to be translated is obtained
The code snippet for according with length, as context code snippet;
Interpreter code segment is treated in conjunction with the context code snippet to be parsed, and is obtained and the code snippet to be translated
The syntactic information matched;
The context code snippet and the syntactic information are added in the analysis destination file.
6. the method according to claim 1, wherein it is described by the resolver to the code to be translated
Subfile is parsed, obtain analysis destination file after, further includes:
Multinomial data flow is generated according to the analysis destination file;
Multinomial data flow is sent to translating server in a manner of parallel transmission and carries out translation processing;
Receive translation offspring's chip segment that the translating server returns;
Code snippet to be translated corresponding in the code subfile to be translated is replaced according to the translation offspring chip segment
It changes, obtains translation post code subfile.
7. a kind of code snippet positioning device, which is characterized in that described device includes:
Module is obtained, for obtaining source code file to be translated;
Read module, user read the source code directory in the source code file to be translated;Include in the source code directory
Multiple original document names;
Screening module filters out code to be translated for traversing the corresponding initial code subfile of each original document name
Subfile;The code subfile to be translated matches with preset language type;
Searching module, for searching and the resolver of the preset language type matching;
Parsing module obtains analysis result text for parsing by the resolver to the code subfile to be translated
Part;In the analysis destination file comprising in the code subfile to be translated code snippet to be translated and with code to be translated
The corresponding segment location information of segment.
8. device according to claim 7, which is characterized in that the screening module is also used to obtain a variety of preset language classes
The corresponding regular expression of type;
The corresponding initial code subfile of each original document name is traversed, the regular expression and each initial generation are passed through
Numeral file is matched;
The matched preset language type of each initial code subfile is determined according to matched regular expression;
The initial code subfile comprising any one preset language type is filtered out, as code subfile to be translated.
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.
Priority Applications (3)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910296105.9A CN110134401A (en) | 2019-04-12 | 2019-04-12 | Code snippet localization method, device, computer equipment and storage medium |
PCT/CN2019/091811 WO2020206837A1 (en) | 2019-04-12 | 2019-06-19 | Code segment positioning method and device, computer apparatus, and storage medium |
SG11201907512PA SG11201907512PA (en) | 2019-04-12 | 2019-06-19 | Methods and apparatuses for locating code snippet, computer devices and storage mediums |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910296105.9A CN110134401A (en) | 2019-04-12 | 2019-04-12 | Code snippet localization method, device, computer equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN110134401A true CN110134401A (en) | 2019-08-16 |
Family
ID=67569729
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910296105.9A Pending CN110134401A (en) | 2019-04-12 | 2019-04-12 | Code snippet localization method, device, computer equipment and storage medium |
Country Status (3)
Country | Link |
---|---|
CN (1) | CN110134401A (en) |
SG (1) | SG11201907512PA (en) |
WO (1) | WO2020206837A1 (en) |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111966358A (en) * | 2020-07-30 | 2020-11-20 | 上海泛微网络科技股份有限公司 | Code packaging method and device, electronic equipment and computer readable storage medium |
CN112527265A (en) * | 2019-09-19 | 2021-03-19 | 深圳Tcl数字技术有限公司 | Method for automatically injecting logs and computer equipment |
CN112527320A (en) * | 2020-12-18 | 2021-03-19 | 成都泛微网络科技有限公司 | Method, device and storage medium for deploying application system based on browser |
CN112631603A (en) * | 2020-12-30 | 2021-04-09 | 文思海辉智科科技有限公司 | Word string analysis method and system and electronic equipment |
CN112784143A (en) * | 2020-12-29 | 2021-05-11 | 金蝶软件(中国)有限公司 | Data processing method and system based on visual computing engine and computer equipment |
CN113011201A (en) * | 2021-03-19 | 2021-06-22 | 北京沃东天骏信息技术有限公司 | Code file processing method and device |
CN113296789A (en) * | 2021-06-16 | 2021-08-24 | 北京有竹居网络技术有限公司 | Code generation method, device, equipment and storage medium |
CN113420569A (en) * | 2021-06-22 | 2021-09-21 | 康键信息技术(深圳)有限公司 | Code translation method, device, equipment and storage medium |
CN113806321A (en) * | 2021-09-02 | 2021-12-17 | 北京天融信网络安全技术有限公司 | Log processing method and system |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101253476A (en) * | 2005-08-10 | 2008-08-27 | 微软公司 | Syntactic program language translation |
CN103617046A (en) * | 2013-12-12 | 2014-03-05 | 用友软件股份有限公司 | Method and device for scanning and extracting resources to be translated in target system source codes |
CN104317788A (en) * | 2014-11-03 | 2015-01-28 | 上海鼎讯电子有限公司 | Android multi-language translation method and device |
CN104391730A (en) * | 2014-08-03 | 2015-03-04 | 浙江网新恒天软件有限公司 | Software source code language translation system and method |
CN105242932A (en) * | 2015-10-21 | 2016-01-13 | 宁波三星医疗电气股份有限公司 | Automatic translation method of software developed on the basis of DELPHI tool |
Family Cites Families (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103309647A (en) * | 2012-03-08 | 2013-09-18 | 鸿富锦精密工业(深圳)有限公司 | Application program multi-language support system and method |
CN104899010B (en) * | 2014-03-04 | 2018-12-21 | 北京金山云网络技术有限公司 | The multi-lingual opinion on public affairs method and system of source code |
US20180032510A1 (en) * | 2015-03-27 | 2018-02-01 | Amazon Technologies, Inc. | Automated translation of source code |
CN107402746B (en) * | 2016-05-20 | 2020-08-04 | 阿里巴巴集团控股有限公司 | Method and device for automatically generating code file |
CN107329957B (en) * | 2017-05-18 | 2020-08-18 | 网易(杭州)网络有限公司 | Method for replacing code Chinese character string and computer readable storage medium |
CN107346303B (en) * | 2017-06-19 | 2020-10-16 | 上海青橙实业有限公司 | Character string data translation processing method and device |
-
2019
- 2019-04-12 CN CN201910296105.9A patent/CN110134401A/en active Pending
- 2019-06-19 WO PCT/CN2019/091811 patent/WO2020206837A1/en active Application Filing
- 2019-06-19 SG SG11201907512PA patent/SG11201907512PA/en unknown
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101253476A (en) * | 2005-08-10 | 2008-08-27 | 微软公司 | Syntactic program language translation |
CN103617046A (en) * | 2013-12-12 | 2014-03-05 | 用友软件股份有限公司 | Method and device for scanning and extracting resources to be translated in target system source codes |
CN104391730A (en) * | 2014-08-03 | 2015-03-04 | 浙江网新恒天软件有限公司 | Software source code language translation system and method |
CN104317788A (en) * | 2014-11-03 | 2015-01-28 | 上海鼎讯电子有限公司 | Android multi-language translation method and device |
CN105242932A (en) * | 2015-10-21 | 2016-01-13 | 宁波三星医疗电气股份有限公司 | Automatic translation method of software developed on the basis of DELPHI tool |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112527265A (en) * | 2019-09-19 | 2021-03-19 | 深圳Tcl数字技术有限公司 | Method for automatically injecting logs and computer equipment |
CN111966358A (en) * | 2020-07-30 | 2020-11-20 | 上海泛微网络科技股份有限公司 | Code packaging method and device, electronic equipment and computer readable storage medium |
CN111966358B (en) * | 2020-07-30 | 2022-06-07 | 上海泛微网络科技股份有限公司 | Code packaging method and device, electronic equipment and computer readable storage medium |
CN112527320A (en) * | 2020-12-18 | 2021-03-19 | 成都泛微网络科技有限公司 | Method, device and storage medium for deploying application system based on browser |
CN112784143A (en) * | 2020-12-29 | 2021-05-11 | 金蝶软件(中国)有限公司 | Data processing method and system based on visual computing engine and computer equipment |
CN112784143B (en) * | 2020-12-29 | 2023-12-29 | 金蝶软件(中国)有限公司 | Data processing method, system and computer equipment based on visual computing engine |
CN112631603A (en) * | 2020-12-30 | 2021-04-09 | 文思海辉智科科技有限公司 | Word string analysis method and system and electronic equipment |
CN113011201A (en) * | 2021-03-19 | 2021-06-22 | 北京沃东天骏信息技术有限公司 | Code file processing method and device |
CN113296789A (en) * | 2021-06-16 | 2021-08-24 | 北京有竹居网络技术有限公司 | Code generation method, device, equipment and storage medium |
CN113420569A (en) * | 2021-06-22 | 2021-09-21 | 康键信息技术(深圳)有限公司 | Code translation method, device, equipment and storage medium |
CN113806321A (en) * | 2021-09-02 | 2021-12-17 | 北京天融信网络安全技术有限公司 | Log processing method and system |
CN113806321B (en) * | 2021-09-02 | 2023-11-10 | 北京天融信网络安全技术有限公司 | Log processing method and system |
Also Published As
Publication number | Publication date |
---|---|
SG11201907512PA (en) | 2020-11-27 |
WO2020206837A1 (en) | 2020-10-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110134401A (en) | Code snippet localization method, device, computer equipment and storage medium | |
CN110134404A (en) | Code translation method, apparatus, computer equipment and storage medium | |
CN104536797B (en) | A kind of java applet precompile method and pre compiler | |
CN109800258B (en) | Data file deployment method, device, computer equipment and storage medium | |
CN110134397A (en) | Code snippet interpretation method, device, computer equipment and storage medium | |
US9182953B2 (en) | Hybrid dynamic code compiling device, method, and service system thereof | |
US10261967B2 (en) | Data extraction | |
CN109542412A (en) | Interface message generation method, device, computer equipment and storage medium | |
US9223570B2 (en) | Migration assistance using compiler metadata | |
CN111367595B (en) | Data processing method, program running method, device and processing equipment | |
CN103678109A (en) | Dump document analysis method, device and system | |
CN111190807B (en) | Buried point testing method and equipment | |
CN111124870A (en) | Interface testing method and device | |
CN112882713B (en) | Log analysis method, device, medium and computer equipment | |
CN111522583A (en) | Method and device for generating configuration file, computer equipment and storage medium | |
CN109491884A (en) | Code method for testing performance, device, computer equipment and medium | |
CN109471637B (en) | Circuit diagram examination script debugging method | |
CN106033338A (en) | Method and device for importing and analyzing source code based on FOG data | |
CN115221047A (en) | Automatic test case generation method and electronic equipment | |
CN113342657A (en) | Method and device for detecting code exception | |
KR102095703B1 (en) | An apparatus, method and recording medium for Markup parsing | |
CN113760291A (en) | Log output method and device | |
CN110321130A (en) | The not reproducible compiling localization method of log is called based on system | |
CN112148581A (en) | Code specification checking method, device, system and storage medium | |
CN110806896A (en) | Method for realizing internationalized information extraction in software development based on maven plug-in |
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 | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20190816 |
|
WD01 | Invention patent application deemed withdrawn after publication |