refactor: use 'lang' instead of 'target_language'

This commit is contained in:
P. Reis 2024-10-08 14:35:51 -03:00
parent a3bc5ec5c3
commit f76ee000b0

View file

@ -8,8 +8,7 @@ import { getEvent } from '@/queries.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts';
const translateSchema = z.object({ const translateSchema = z.object({
//lang: languageSchema, // Correct property name, as stated by Mastodon docs lang: languageSchema,
target_language: languageSchema, // Property name soapbox sends
}); });
const translateController: AppController = async (c) => { const translateController: AppController = async (c) => {
@ -25,8 +24,7 @@ const translateController: AppController = async (c) => {
return c.json({ error: 'No translator configured.' }, 500); return c.json({ error: 'No translator configured.' }, 500);
} }
const { target_language } = result.data; const { lang } = result.data;
const targetLang = target_language;
const id = c.req.param('id'); const id = c.req.param('id');
const event = await getEvent(id, { signal }); const event = await getEvent(id, { signal });
@ -36,13 +34,13 @@ const translateController: AppController = async (c) => {
const viewerPubkey = await c.get('signer')?.getPublicKey(); const viewerPubkey = await c.get('signer')?.getPublicKey();
if (targetLang.toLowerCase() === event?.language?.toLowerCase()) { if (lang.toLowerCase() === event?.language?.toLowerCase()) {
return c.json({ error: 'Source and target languages are the same. No translation needed.' }, 400); return c.json({ error: 'Source and target languages are the same. No translation needed.' }, 400);
} }
const status = await renderStatus(event, { viewerPubkey }); const status = await renderStatus(event, { viewerPubkey });
const translatedId = `${target_language}-${id}` as dittoTranslationsKey; const translatedId = `${lang}-${id}` as dittoTranslationsKey;
const translationCache = dittoTranslations.get(translatedId); const translationCache = dittoTranslations.get(translatedId);
if (translationCache) { if (translationCache) {
@ -63,7 +61,7 @@ const translateController: AppController = async (c) => {
mediaAttachments, mediaAttachments,
null, null,
event.language, event.language,
targetLang, lang,
{ signal }, { signal },
); );
dittoTranslations.set(translatedId, translation); dittoTranslations.set(translatedId, translation);