A processor implemented method for translation of codes based on a semantic similarity, the method comprising: providing, via a user interface, a source code for translation as an input; parsing, via one or more hardware processors, the source code using a parser; creating, via the one or more hardware processors, a program flow graph using the parsed source code, wherein the program flow graph is used to establish a set of relations between a plurality of statements present in the source code; creating, via the one or more hardware processors, a matrix of the established set of relations between the plurality of statements; splitting, via the one or more hardware processors, the source code into a plurality of blocks using the created matrix; training, via the one or more hardware processors, a semantically enhanced encoder with a context of a semantic equivalence between the plurality of blocks of the source code irrespective of a manner in which the plurality of blocks is syntactically coded; identifying, via the one or more hardware processors, semantically similar statements out of the plurality of blocks using the semantically enhanced encoder; selecting, via the user interface, a target language in which the source code needs to be translated; translating, via the one or more hardware processors, the source code into the target language using a decoder based on the identified semantically similar statements, wherein the decoder is a pretrained machine learning model, wherein the encoder and decoder represent a transformer model, wherein the transformer model is fine-tuned on a supervised data set to generate one or more similar vectors for semantically similar but syntactically different statements, wherein similar vectors are mathematically close, and wherein the transformer model understands and encapsulates code semantics and translates a semantic equivalent code, wherein an attention mechanism in the transformer model learns patterns to produce one or more mathematically closer vectors, and the decoder utilizes the generated vectors to translate the generated vectors into the target language; and eliminating, via the one or more hardware processors, during translation at least one of unused and duplicate codes from the source code using the set of relations and by semantic equivalence analysis. providing, via a user interface, a source code for translation as an input; parsing, via one or more hardware processors, the source code using a parser; creating, via the one or more hardware processors, a program flow graph using the parsed source code, wherein the program flow graph is used to establish a set of relations between a plurality of statements present in the source code; creating, via the one or more hardware processors, a matrix of the established set of relations between the plurality of statements; splitting, via the one or more hardware processors, the source code into a plurality of blocks using the created matrix; training, via the one or more hardware processors, a semantically enhanced encoder with a context of a semantic equivalence between the plurality of blocks of the source code irrespective of a manner in which the plurality of blocks is syntactically coded; identifying, via the one or more hardware processors, semantically similar statements out of the plurality of blocks using the semantically enhanced encoder; selecting, via the user interface, a target language in which the source code needs to be translated; translating, via the one or more hardware processors, the source code into the target language using a decoder based on the identified semantically similar statements, wherein the decoder is a pretrained machine learning model, wherein the encoder and decoder represent a transformer model, wherein the transformer model is fine-tuned on a supervised data set to generate one or more similar vectors for semantically similar but syntactically different statements, wherein similar vectors are mathematically close, and wherein the transformer model understands and encapsulates code semantics and translates a semantic equivalent code, wherein an attention mechanism in the transformer model learns patterns to produce one or more mathematically closer vectors, and the decoder utilizes the generated vectors to translate the generated vectors into the target language; and eliminating, via the one or more hardware processors, during translation at least one of unused and duplicate codes from the source code using the set of relations and by semantic equivalence analysis.