remove comments
This commit is contained in:
parent
f921ecaa96
commit
adcc4e85ac
|
@ -4,14 +4,10 @@ import { i18n } from "next-i18next.config";
|
||||||
import { getToken } from "next-auth/jwt";
|
import { getToken } from "next-auth/jwt";
|
||||||
import { prisma } from "../api/db";
|
import { prisma } from "../api/db";
|
||||||
|
|
||||||
// Keep this in a separate file, it's for logged out users
|
|
||||||
// For logged in users, we'll use their preferred language from the database (default: en)
|
|
||||||
const getServerSideProps: GetServerSideProps = async (ctx) => {
|
const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
const acceptLanguageHeader = ctx.req.headers["accept-language"];
|
const acceptLanguageHeader = ctx.req.headers["accept-language"];
|
||||||
const availableLanguages = i18n.locales;
|
const availableLanguages = i18n.locales;
|
||||||
|
|
||||||
// Check if it's a logged in user
|
|
||||||
// If it is, get the user's preferred language from the database
|
|
||||||
const token = await getToken({ req: ctx.req });
|
const token = await getToken({ req: ctx.req });
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
|
@ -30,17 +26,14 @@ const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the accept-language header to get an array of languages
|
|
||||||
const acceptedLanguages = acceptLanguageHeader
|
const acceptedLanguages = acceptLanguageHeader
|
||||||
?.split(",")
|
?.split(",")
|
||||||
.map((lang) => lang.split(";")[0]);
|
.map((lang) => lang.split(";")[0]);
|
||||||
|
|
||||||
// Find the best match between the accepted languages and available languages
|
|
||||||
let bestMatch = acceptedLanguages?.find((lang) =>
|
let bestMatch = acceptedLanguages?.find((lang) =>
|
||||||
availableLanguages.includes(lang)
|
availableLanguages.includes(lang)
|
||||||
);
|
);
|
||||||
|
|
||||||
// If no direct match, find the best partial match
|
|
||||||
if (!bestMatch) {
|
if (!bestMatch) {
|
||||||
acceptedLanguages?.some((acceptedLang) => {
|
acceptedLanguages?.some((acceptedLang) => {
|
||||||
const partialMatch = availableLanguages.find((lang) =>
|
const partialMatch = availableLanguages.find((lang) =>
|
||||||
|
|
Ŝarĝante…
Reference in New Issue