feat(i18n): improve ai chat and settings localization
This commit is contained in:
@@ -1,14 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import { getSqliteConnection } from "@/server/db/client";
|
||||
import { ContentTranslationService, getContentFallbackLocale } from "@/server/i18n/content";
|
||||
import { resolveFreelancerLocale } from "@/server/i18n/resolver";
|
||||
import { requireFreelancerBackend } from "@/server/web/freelancer";
|
||||
|
||||
export async function listChatSessionsAction() {
|
||||
const { actor, service } = await requireFreelancerBackend();
|
||||
return service.listChatSessions(actor).map((session) => ({
|
||||
id: session.id,
|
||||
title: session.title,
|
||||
created_at: session.createdAt.toISOString(),
|
||||
}));
|
||||
const { context, actor, service } = await requireFreelancerBackend();
|
||||
const locale = await resolveFreelancerLocale(context);
|
||||
const content = new ContentTranslationService(getSqliteConnection().db);
|
||||
const localization = content.getLocalizationContext(actor);
|
||||
const sessions = service.listChatSessions(actor);
|
||||
const translations = content.listBatch("chat_session", sessions.map((session) => session.id));
|
||||
|
||||
return sessions.map((session) => {
|
||||
const resolved = content.resolveEntity("chat_session", session, {
|
||||
locale: locale.locale,
|
||||
fallbackLocale: getContentFallbackLocale(locale.locale, localization),
|
||||
defaultLocale: localization.defaultLocale,
|
||||
translations: translations.get(session.id) ?? [],
|
||||
});
|
||||
|
||||
return {
|
||||
id: session.id,
|
||||
title: resolved.title,
|
||||
created_at: session.createdAt.toISOString(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export async function listChatMessagesAction(sessionId: string) {
|
||||
@@ -17,12 +35,18 @@ export async function listChatMessagesAction(sessionId: string) {
|
||||
id: message.id,
|
||||
role: message.role,
|
||||
content: message.content,
|
||||
source_locale: message.sourceLocale,
|
||||
}));
|
||||
}
|
||||
|
||||
export async function createChatSessionAction(title: string) {
|
||||
const { actor, service } = await requireFreelancerBackend();
|
||||
const { context, actor, service } = await requireFreelancerBackend();
|
||||
const locale = await resolveFreelancerLocale(context);
|
||||
const session = service.createChatSession(actor, { title });
|
||||
const content = new ContentTranslationService(getSqliteConnection().db);
|
||||
content.upsertEntityTranslations("chat_session", session.id, {
|
||||
[locale.locale]: { title },
|
||||
});
|
||||
return {
|
||||
id: session.id,
|
||||
title: session.title,
|
||||
|
||||
Reference in New Issue
Block a user