From d6fbbab15fa1e577f72a2b26f366eb133a35b056 Mon Sep 17 00:00:00 2001 From: twobiers <22715034+twobiers@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:59:36 +0100 Subject: [PATCH] Add support for punctuations in deoida --- src/storage/model/AustrianTranslation.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/storage/model/AustrianTranslation.ts b/src/storage/model/AustrianTranslation.ts index 0b6d793d..7139f805 100644 --- a/src/storage/model/AustrianTranslation.ts +++ b/src/storage/model/AustrianTranslation.ts @@ -49,10 +49,24 @@ export default class AustrianTranslation extends Model { ): Promise { return AustrianTranslation.findOne({ where: { - austrian: { - // we want like to be case-insensitive, we don't need a placeholder - [Op.like]: austrian.trim().toLowerCase(), - }, + [Op.or]: [ + { + // we want like to be case-insensitive, we don't need a placeholder + // We might have translations with punctuations in it, so we simply try to match the whole string against it + austrian: { + [Op.like]: austrian.trim().toLowerCase(), + }, + }, + { + // If we couldn't find a translation with the punctuations in it, we remove the special chars + austrian: { + [Op.like]: austrian + .trim() + .toLowerCase() + .replace(/[^\w\s]/gu, ""), + }, + }, + ], }, }); }