fix: restore getMessage compatibility and finalize build
This commit is contained in:
@@ -121,6 +121,36 @@ export async function getMessages(locale: string): Promise<Record<string, string
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single message by key from Directus
|
||||
*/
|
||||
export async function getMessage(key: string, locale: string): Promise<string | null> {
|
||||
const directusLocale = toDirectusLocale(locale);
|
||||
const query = `
|
||||
query {
|
||||
messages(filter: {key: {_eq: "${key}"}}, limit: 1) {
|
||||
key
|
||||
translations {
|
||||
value
|
||||
languages_code { code }
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
try {
|
||||
const result = await directusRequest('', { body: { query } });
|
||||
const messages = (result as any)?.messages;
|
||||
if (!messages || messages.length === 0) return null;
|
||||
|
||||
const translations = messages[0]?.translations || [];
|
||||
const translation = translations.find((t: any) => t.languages_code?.code === directusLocale);
|
||||
return translation?.value || null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getContentPage(
|
||||
slug: string,
|
||||
locale: string
|
||||
|
||||
Reference in New Issue
Block a user