🐛 Fix slug page and refactor server side translations code

This commit is contained in:
Manuel Ruwe
2022-12-30 16:51:53 +01:00
parent 0565d444d2
commit fe662ab166
4 changed files with 59 additions and 47 deletions

View File

@@ -0,0 +1,19 @@
import { getCookie } from 'cookies-next';
import { IncomingMessage, ServerResponse } from 'http';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
export const getServerSideTranslations = async (
req: IncomingMessage,
res: ServerResponse,
namespaces: string[],
requestLocale?: string
) => {
const configLocale = getCookie('config-locale', { req, res });
const translations = await serverSideTranslations(
(configLocale ?? requestLocale ?? 'en') as string,
namespaces
);
return translations;
};