21 lines
611 B
TypeScript

// use server is required
'use server';
import { defaultLocale } from './config';
import { type Locale } from './types';
import { cookies } from 'next/headers';
// In this example the locale is read from a cookie. You could alternatively
// also read it from a database, backend service, or any other source.
const COOKIE_NAME = 'NEXT_LOCALE';
const getLocale = async () => {
return (await cookies()).get(COOKIE_NAME)?.value || defaultLocale;
};
const setLocale = async (locale?: string) => {
(await cookies()).set(COOKIE_NAME, (locale as Locale) || defaultLocale);
};
export { getLocale, setLocale };