File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,11 @@ export class AiToolsService {
81
81
text : string
82
82
) {
83
83
try {
84
+ const urlRegex = / ( h t t p s ? : \/ \/ [ ^ \s ] + ) | ( w w w \. [ ^ \s ] + ) / g;
85
+ const urls = text . match ( urlRegex ) || [ ] ;
86
+
87
+ const placeHolder = "9kBjf325" //placeholder which stays the same across languages after translation
88
+ const textWithoutUrls = text . replace ( urlRegex , placeHolder )
84
89
let config = {
85
90
"language" : {
86
91
"sourceLanguage" : source ,
@@ -89,7 +94,7 @@ export class AiToolsService {
89
94
}
90
95
let bhashiniConfig : any = await this . getBhashiniConfig ( 'translation' , config )
91
96
92
- let textArray = text . split ( "\n" )
97
+ let textArray = textWithoutUrls . split ( "\n" )
93
98
for ( let i = 0 ; i < textArray . length ; i ++ ) {
94
99
let response : any = await this . computeBhashini (
95
100
bhashiniConfig ?. pipelineInferenceAPIEndPoint ?. inferenceApiKey ?. value ,
@@ -112,8 +117,9 @@ export class AiToolsService {
112
117
}
113
118
textArray [ i ] = response ?. pipelineResponse [ 0 ] ?. output [ 0 ] ?. target
114
119
}
120
+ const translatedText = textArray . join ( '\n' ) . replace ( new RegExp ( placeHolder , 'g' ) , ( ) => urls . shift ( ) || '' ) ;
115
121
return {
116
- text : textArray . join ( '\n' ) ,
122
+ text : translatedText ,
117
123
error : null
118
124
}
119
125
} catch ( error ) {
You can’t perform that action at this time.
0 commit comments