feat: Title - AI translation for booking pages (#17794)

* feat: AI description - DB model + frontend + backend (fetch only)

* fix types and add validation to backend

* improve log

* improve

* import type

* add EventTypeTranslationRepository

* fix replexica error

* fix replexica error

* fix

* fix test

* wip

* wip

* add createManyDescriptionTranslations method

* improve logic

* refactor

* update replexica type

* improve typing

* Renamed descriptionTranslations to fieldTranslations

* log errors in replexica service

* handle translations in background

* don't create, upsert instead

* make sure that description is updated

* simplify

* fix

* Update packages/trpc/server/routers/viewer/eventTypes/update.handler.ts

* improve filter logic in frontend

* implement background job using Tasker

* update schema

* update schema again

* rename

* rename id to uid

* add migration

* fix type

* update

* update schema and migration sql

* fix migration

* fix type check

* fix type check 2

* improve find logic in EventMeta

* add more validation

* add logger

* rename

* upgrade replexica/sdk to 0.7.0

* upgrade replexica to 0.7.0

* use batchLocalizeText

* add comments

* override browser locale if user is a signed in calcom user

* fix type in replexica

* fix migration sql

* fix type

* use dynamic import

* do not use batchLocalizeText

* chore: drop sourceLang, targetLang and id columns

* fix

* wip

* add more validations

* fix type error

* address comment

* refactor

* update booking page to use translated title

* fix type error

* fix

* revert yarn.lock changes

* remove unused import

* remove duplication migrate.sql file

* fix test

* remove test tags

* fix function name

* refactor

* fix type check

* use Promise.all

* remove unneeded code

---------

Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
Benny JooandKeith Williams authored and GitHub committed 2024-12-11 14:18:32 +01:00
1 parent dd3505ad8b
commit 6739ed3a87
14 files changed
+190 -111

No files matched your search

@@ -79,6 +79,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
isRRWeightsEnabled,
autoTranslateDescriptionEnabled,
description: newDescription,
title: newTitle,
...rest
} = input;
@@ -173,6 +174,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
// autoTranslate feature is allowed for org users only
autoTranslateDescriptionEnabled: !!(ctx.user.organizationId && autoTranslateDescriptionEnabled),
description: newDescription,
title: newTitle,
bookingFields,
isRRWeightsEnabled,
rrSegmentQueryValue:
@@ -497,21 +499,21 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
}
// Logic for updating `fieldTranslations`
// user has no description translations OR user is changing the description
const descriptionTranslationsNeeded =
// user has no translations OR user is changing the field
const hasNoDescriptionTranslations =
eventType.fieldTranslations.filter((trans) => trans.field === EventTypeAutoTranslatedField.DESCRIPTION)
.length === 0 || newDescription;
const description = newDescription ?? eventType.description;
.length === 0;
const description = newDescription ?? (hasNoDescriptionTranslations ? eventType.description : undefined);
const hasNoTitleTranslations =
eventType.fieldTranslations.filter((trans) => trans.field === EventTypeAutoTranslatedField.TITLE)
.length === 0;
const title = newTitle ?? (hasNoTitleTranslations ? eventType.title : undefined);
if (
ctx.user.organizationId &&
autoTranslateDescriptionEnabled &&
descriptionTranslationsNeeded &&
description
) {
await tasker.create("translateEventTypeDescription", {
if (ctx.user.organizationId && autoTranslateDescriptionEnabled && (title || description)) {
await tasker.create("translateEventTypeData", {
eventTypeId: id,
description,
title,
userLocale: ctx.user.locale,
userId: ctx.user.id,
});