Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
20 lines
830 B
Plaintext
20 lines
830 B
Plaintext
import { upsertPreferences } from '@payloadcms/ui/rsc';
|
|
import { findLocaleFromCode } from '@payloadcms/ui/shared';
|
|
import { getPreferences } from './getPreferences.js';
|
|
export async function getRequestLocale({
|
|
req
|
|
}) {
|
|
if (req.payload.config.localization) {
|
|
const localeFromParams = req.query.locale;
|
|
if (req.user && localeFromParams) {
|
|
await upsertPreferences({
|
|
key: 'locale',
|
|
req,
|
|
value: localeFromParams
|
|
});
|
|
}
|
|
return req.user && findLocaleFromCode(req.payload.config.localization, localeFromParams || (await getPreferences('locale', req.payload, req.user.id, req.user.collection))?.value) || findLocaleFromCode(req.payload.config.localization, req.payload.config.localization.defaultLocale || 'en');
|
|
}
|
|
return undefined;
|
|
}
|
|
//# sourceMappingURL=getRequestLocale.js.map |