From 354c309bd1f11c67d4dd33fb0993dedeb94665f9 Mon Sep 17 00:00:00 2001 From: kh4l1d64 Date: Mon, 26 Feb 2024 20:39:27 +0530 Subject: [PATCH] Fix for url translation --- src/modules/aiTools/ai-tools.service.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/aiTools/ai-tools.service.ts b/src/modules/aiTools/ai-tools.service.ts index 332fdd0..16b0e04 100644 --- a/src/modules/aiTools/ai-tools.service.ts +++ b/src/modules/aiTools/ai-tools.service.ts @@ -81,6 +81,11 @@ export class AiToolsService { text: string ) { try { + const urlRegex = /(https?:\/\/[^\s]+)|(www\.[^\s]+)/g; + const urls = text.match(urlRegex) || []; + + const placeHolder = "9kBjf325" //placeholder which stays the same across languages after translation + const textWithoutUrls = text.replace(urlRegex, placeHolder) let config = { "language": { "sourceLanguage": source, @@ -89,7 +94,7 @@ export class AiToolsService { } let bhashiniConfig: any = await this.getBhashiniConfig('translation',config) - let textArray = text.split("\n") + let textArray = textWithoutUrls.split("\n") for(let i=0;i urls.shift() || ''); return { - text: textArray.join('\n'), + text: translatedText, error: null } } catch(error){