chore: [app dir bootstrapping 6] server-side translations (#11995)
Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
139a7c8249
commit
c7b1e4dfa1
7 files changed
+78
-12
No files matched your search
@@ -1,7 +1,11 @@
|
||||
import { parse } from "accept-language-parser";
|
||||
import { lookup } from "bcp-47-match";
|
||||
import type { GetTokenParams } from "next-auth/jwt";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
//@ts-expect-error no type definitions
|
||||
import { i18n } from "@calcom/web/next-i18next.config";
|
||||
|
||||
/**
|
||||
* This is a slimmed down version of the `getServerSession` function from
|
||||
* `next-auth`.
|
||||
@@ -40,5 +44,9 @@ export const getLocale = async (req: GetTokenParams["req"]): Promise<string> =>
|
||||
// the regex underneath is more permissive
|
||||
const testedRegion = /^[a-zA-Z0-9]+$/.test(region) ? region : "";
|
||||
|
||||
return `${testedCode}${testedRegion !== "" ? "-" : ""}${testedRegion}`;
|
||||
const requestedLocale = `${testedCode}${testedRegion !== "" ? "-" : ""}${testedRegion}`;
|
||||
|
||||
// use fallback to closest supported locale.
|
||||
// for instance, es-419 will be transformed to es
|
||||
return lookup(i18n.locales, requestedLocale) ?? requestedLocale;
|
||||
};
|
||||
Reference in new issue
Block a user