21 lines
595 B
TypeScript
21 lines
595 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 cookies().get(COOKIE_NAME)?.value || defaultLocale;
|
|
};
|
|
|
|
const setLocale = async (locale?: string) => {
|
|
cookies().set(COOKIE_NAME, (locale as Locale) || defaultLocale);
|
|
};
|
|
|
|
export { getLocale, setLocale };
|