feat: replace links in status after translated (#2385)
Co-authored-by: patak <matias.capeletto@gmail.com>zio/stable
parent
ca0afe585d
commit
e9f274f304
|
@ -65,6 +65,7 @@ export async function translateText(text: string, from: string | null | undefine
|
||||||
error: '',
|
error: '',
|
||||||
text: '',
|
text: '',
|
||||||
})
|
})
|
||||||
|
const regex = /<a[^>]*>.*?<\/a>/g
|
||||||
try {
|
try {
|
||||||
const response = await ($fetch as any)(config.public.translateApi, {
|
const response = await ($fetch as any)(config.public.translateApi, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -77,7 +78,11 @@ export async function translateText(text: string, from: string | null | undefine
|
||||||
},
|
},
|
||||||
}) as TranslationResponse
|
}) as TranslationResponse
|
||||||
status.success = true
|
status.success = true
|
||||||
status.text = response.translatedText
|
// replace the translated links with the original
|
||||||
|
status.text = response.translatedText.replace(regex, (match) => {
|
||||||
|
const tagLink = regex.exec(text)
|
||||||
|
return tagLink ? tagLink[0] : match
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
// TODO: improve type
|
// TODO: improve type
|
||||||
|
|
Loading…
Reference in New Issue