
* feat: add crowdin and supported languages * fix: main branch name * feat: test crowdin integration * feat: add crowdin config skeleton * feat: update crowdin.yml * fix: remove ro translation * test: en translation * test: en translation * New Crowdin translations by Github Action (#735) Co-authored-by: Crowdin Bot <support+bot@crowdin.com> * test: en translation * fix: separate upload/download workflows * wip * New Crowdin translations by Github Action (#738) Co-authored-by: Crowdin Bot <support+bot@crowdin.com> * wip * wip * wip * wip * wip * typo * wip * wip * update crowdin config * update * chore: support i18n de,es,fr,it,pt,ru,ro,en * chore: extract i18n strings * chore: extract booking components strings for i18n * wip * extract more strings * wip * fallback to getServerSideProps for now * New Crowdin translations by Github Action (#874) Co-authored-by: Crowdin Bot <support+bot@crowdin.com> * fix: minor fixes on the datepicker * fix: add dutch lang * fix: linting issues * fix: string * fix: update GHA * cleanup trpc * fix linting Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Crowdin Bot <support+bot@crowdin.com> Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
78 lines
1.6 KiB
TypeScript
78 lines
1.6 KiB
TypeScript
import parser from "accept-language-parser";
|
|
import { IncomingMessage } from "http";
|
|
|
|
import { getSession } from "@lib/auth";
|
|
import prisma from "@lib/prisma";
|
|
|
|
import { i18n } from "../../../next-i18next.config";
|
|
|
|
export const getOrSetUserLocaleFromHeaders = async (req: IncomingMessage) => {
|
|
const session = await getSession({ req });
|
|
const preferredLocale = parser.pick(i18n.locales, req.headers["accept-language"]);
|
|
|
|
if (session?.user?.id) {
|
|
const user = await prisma.user.findUnique({
|
|
where: {
|
|
id: session.user.id,
|
|
},
|
|
select: {
|
|
locale: true,
|
|
},
|
|
});
|
|
|
|
if (user?.locale) {
|
|
return user.locale;
|
|
}
|
|
|
|
if (preferredLocale) {
|
|
await prisma.user.update({
|
|
where: {
|
|
id: session.user.id,
|
|
},
|
|
data: {
|
|
locale: preferredLocale,
|
|
},
|
|
});
|
|
} else {
|
|
await prisma.user.update({
|
|
where: {
|
|
id: session.user.id,
|
|
},
|
|
data: {
|
|
locale: i18n.defaultLocale,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
if (preferredLocale) {
|
|
return preferredLocale;
|
|
}
|
|
|
|
return i18n.defaultLocale;
|
|
};
|
|
|
|
interface localeType {
|
|
[locale: string]: string;
|
|
}
|
|
|
|
export const localeLabels: localeType = {
|
|
en: "English",
|
|
fr: "French",
|
|
it: "Italian",
|
|
ru: "Russian",
|
|
es: "Spanish",
|
|
de: "German",
|
|
pt: "Portuguese",
|
|
ro: "Romanian",
|
|
nl: "Dutch",
|
|
};
|
|
|
|
export type OptionType = {
|
|
value: string;
|
|
label: string;
|
|
};
|
|
|
|
export const localeOptions: OptionType[] = i18n.locales.map((locale) => {
|
|
return { value: locale, label: localeLabels[locale] };
|
|
});
|