create project

This commit is contained in:
ismailsosic
2022-12-27 12:05:56 +01:00
parent 2a33a2d3de
commit cd2143287c
16035 changed files with 2489703 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
import type { DomainLocale } from '../../../server/config-shared';
export declare function detectDomainLocale(domainItems?: DomainLocale[], hostname?: string, detectedLocale?: string): DomainLocale | undefined;

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.detectDomainLocale = detectDomainLocale;
function detectDomainLocale(domainItems, hostname, detectedLocale) {
let domainItem;
if (domainItems) {
if (detectedLocale) {
detectedLocale = detectedLocale.toLowerCase();
}
for (const item of domainItems){
var ref, ref1;
// remove port if present
const domainHostname = (ref = item.domain) == null ? void 0 : ref.split(':')[0].toLowerCase();
if (hostname === domainHostname || detectedLocale === item.defaultLocale.toLowerCase() || ((ref1 = item.locales) == null ? void 0 : ref1.some((locale)=>locale.toLowerCase() === detectedLocale))) {
domainItem = item;
break;
}
}
}
return domainItem;
}
//# sourceMappingURL=detect-domain-locale.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/i18n/detect-domain-locale.ts"],"names":["detectDomainLocale","domainItems","hostname","detectedLocale","domainItem","toLowerCase","item","domainHostname","domain","split","defaultLocale","locales","some","locale"],"mappings":"AAAA;;;;QAEgBA,kBAAkB,GAAlBA,kBAAkB;AAA3B,SAASA,kBAAkB,CAChCC,WAA4B,EAC5BC,QAAiB,EACjBC,cAAuB,EACvB;IACA,IAAIC,UAAU,AAA0B;IAExC,IAAIH,WAAW,EAAE;QACf,IAAIE,cAAc,EAAE;YAClBA,cAAc,GAAGA,cAAc,CAACE,WAAW,EAAE;SAC9C;QAED,KAAK,MAAMC,IAAI,IAAIL,WAAW,CAAE;gBAEPK,GAAW,EAIhCA,IAAY;YALd,yBAAyB;YACzB,MAAMC,cAAc,GAAGD,CAAAA,GAAW,GAAXA,IAAI,CAACE,MAAM,SAAO,GAAlBF,KAAAA,CAAkB,GAAlBA,GAAW,CAAEG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAACJ,WAAW,EAAE;YAC/D,IACEH,QAAQ,KAAKK,cAAc,IAC3BJ,cAAc,KAAKG,IAAI,CAACI,aAAa,CAACL,WAAW,EAAE,KACnDC,CAAAA,IAAY,GAAZA,IAAI,CAACK,OAAO,SAAM,GAAlBL,KAAAA,CAAkB,GAAlBA,IAAY,CAAEM,IAAI,CAAC,CAACC,MAAM,GAAKA,MAAM,CAACR,WAAW,EAAE,KAAKF,cAAc,CAAC,CAAA,EACvE;gBACAC,UAAU,GAAGE,IAAI;gBACjB,MAAK;aACN;SACF;KACF;IAED,OAAOF,UAAU,CAAA;CAClB"}

View File

@@ -0,0 +1,3 @@
/// <reference types="node" />
import { IncomingMessage } from 'http';
export declare function detectLocaleCookie(req: IncomingMessage, locales: string[]): string | undefined;

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.detectLocaleCookie = detectLocaleCookie;
function detectLocaleCookie(req, locales) {
const { NEXT_LOCALE } = req.cookies || {};
return NEXT_LOCALE ? locales.find((locale)=>NEXT_LOCALE.toLowerCase() === locale.toLowerCase()) : undefined;
}
//# sourceMappingURL=detect-locale-cookie.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/i18n/detect-locale-cookie.ts"],"names":["detectLocaleCookie","req","locales","NEXT_LOCALE","cookies","find","locale","toLowerCase","undefined"],"mappings":"AAAA;;;;QAEgBA,kBAAkB,GAAlBA,kBAAkB;AAA3B,SAASA,kBAAkB,CAACC,GAAoB,EAAEC,OAAiB,EAAE;IAC1E,MAAM,EAAEC,WAAW,CAAA,EAAE,GAAG,AAACF,GAAG,CAASG,OAAO,IAAI,EAAE;IAClD,OAAOD,WAAW,GACdD,OAAO,CAACG,IAAI,CACV,CAACC,MAAc,GAAKH,WAAW,CAACI,WAAW,EAAE,KAAKD,MAAM,CAACC,WAAW,EAAE,CACvE,GACDC,SAAS,CAAA;CACd"}

View File

@@ -0,0 +1,21 @@
import type { DomainLocale } from '../../../server/config';
import type { I18NConfig } from '../../../server/config-shared';
interface Options {
defaultLocale: string;
domainLocale?: DomainLocale;
headers?: {
[key: string]: string | string[] | undefined;
};
nextConfig: {
basePath?: string;
i18n?: I18NConfig | null;
trailingSlash?: boolean;
};
pathLocale?: string;
urlParsed: {
hostname?: string | null;
pathname: string;
};
}
export declare function getLocaleRedirect({ defaultLocale, domainLocale, pathLocale, headers, nextConfig, urlParsed, }: Options): string | undefined;
export {};

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLocaleRedirect = getLocaleRedirect;
var _extends = require("@swc/helpers/lib/_extends.js").default;
var _acceptHeader = require("../../../server/accept-header");
var _denormalizePagePath = require("../page-path/denormalize-page-path");
var _detectDomainLocale = require("./detect-domain-locale");
var _formatUrl = require("../router/utils/format-url");
var _apiUtils = require("../../../server/api-utils");
function getLocaleFromCookie(i18n, headers = {}) {
var ref, ref1;
const nextLocale = (ref = (0, _apiUtils).getCookieParser(headers || {})()) == null ? void 0 : (ref1 = ref.NEXT_LOCALE) == null ? void 0 : ref1.toLowerCase();
return nextLocale ? i18n.locales.find((locale)=>nextLocale === locale.toLowerCase()) : undefined;
}
function detectLocale({ i18n , headers , domainLocale , preferredLocale , pathLocale }) {
return pathLocale || (domainLocale == null ? void 0 : domainLocale.defaultLocale) || getLocaleFromCookie(i18n, headers) || preferredLocale || i18n.defaultLocale;
}
function getAcceptPreferredLocale(i18n, headers) {
if ((headers == null ? void 0 : headers['accept-language']) && !Array.isArray(headers['accept-language'])) {
try {
return (0, _acceptHeader).acceptLanguage(headers['accept-language'], i18n.locales);
} catch (err) {}
}
}
function getLocaleRedirect({ defaultLocale , domainLocale , pathLocale , headers , nextConfig , urlParsed }) {
if (nextConfig.i18n && nextConfig.i18n.localeDetection !== false && (0, _denormalizePagePath).denormalizePagePath(urlParsed.pathname) === '/') {
const preferredLocale = getAcceptPreferredLocale(nextConfig.i18n, headers);
const detectedLocale = detectLocale({
i18n: nextConfig.i18n,
preferredLocale,
headers,
pathLocale,
domainLocale
});
const preferredDomain = (0, _detectDomainLocale).detectDomainLocale(nextConfig.i18n.domains, undefined, preferredLocale);
if (domainLocale && preferredDomain) {
const isPDomain = preferredDomain.domain === domainLocale.domain;
const isPLocale = preferredDomain.defaultLocale === preferredLocale;
if (!isPDomain || !isPLocale) {
const scheme = `http${preferredDomain.http ? '' : 's'}`;
const rlocale = isPLocale ? '' : preferredLocale;
return `${scheme}://${preferredDomain.domain}/${rlocale}`;
}
}
if (detectedLocale.toLowerCase() !== defaultLocale.toLowerCase()) {
return (0, _formatUrl).formatUrl(_extends({}, urlParsed, {
pathname: `${nextConfig.basePath || ''}/${detectedLocale}`
}));
}
}
}
//# sourceMappingURL=get-locale-redirect.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/i18n/get-locale-redirect.ts"],"names":["getLocaleRedirect","getLocaleFromCookie","i18n","headers","getCookieParser","nextLocale","NEXT_LOCALE","toLowerCase","locales","find","locale","undefined","detectLocale","domainLocale","preferredLocale","pathLocale","defaultLocale","getAcceptPreferredLocale","Array","isArray","acceptLanguage","err","nextConfig","urlParsed","localeDetection","denormalizePagePath","pathname","detectedLocale","preferredDomain","detectDomainLocale","domains","isPDomain","domain","isPLocale","scheme","http","rlocale","formatUrl","basePath"],"mappings":"AAAA;;;;QAqEgBA,iBAAiB,GAAjBA,iBAAiB;;AAnEF,IAAA,aAA+B,WAA/B,+BAA+B,CAAA;AAC1B,IAAA,oBAAoC,WAApC,oCAAoC,CAAA;AACrC,IAAA,mBAAwB,WAAxB,wBAAwB,CAAA;AACjC,IAAA,UAA4B,WAA5B,4BAA4B,CAAA;AACtB,IAAA,SAA2B,WAA3B,2BAA2B,CAAA;AAe3D,SAASC,mBAAmB,CAC1BC,IAAgB,EAChBC,OAAyD,GAAG,EAAE,EAC9D;QACmBC,GAEhB;IA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AAC,aACZd,SAAS;gBACZG,QAAQ,EAAE,CAAC,EAAEJ,UAAU,CAACgB,QAAQ,IAAI,EAAE,CAAC,CAAC,EAAEX,cAAc,CAAC,CAAC;cAC3D,CAAC,CAAA;SACH;KACF;CACF"}

View File

@@ -0,0 +1,14 @@
export interface PathLocale {
detectedLocale?: string;
pathname: string;
}
/**
* For a pathname that may include a locale from a list of locales, it
* removes the locale from the pathname returning it alongside with the
* detected locale.
*
* @param pathname A pathname that may include a locale.
* @param locales A list of locales.
* @returns The detected locale and pathname without locale
*/
export declare function normalizeLocalePath(pathname: string, locales?: string[]): PathLocale;

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.normalizeLocalePath = normalizeLocalePath;
function normalizeLocalePath(pathname, locales) {
let detectedLocale;
// first item will be empty string from splitting at first char
const pathnameParts = pathname.split('/');
(locales || []).some((locale)=>{
if (pathnameParts[1] && pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
detectedLocale = locale;
pathnameParts.splice(1, 1);
pathname = pathnameParts.join('/') || '/';
return true;
}
return false;
});
return {
pathname,
detectedLocale
};
}
//# sourceMappingURL=normalize-locale-path.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../shared/lib/i18n/normalize-locale-path.ts"],"names":["normalizeLocalePath","pathname","locales","detectedLocale","pathnameParts","split","some","locale","toLowerCase","splice","join"],"mappings":"AAAA;;;;QAcgBA,mBAAmB,GAAnBA,mBAAmB;AAA5B,SAASA,mBAAmB,CACjCC,QAAgB,EAChBC,OAAkB,EACN;IACZ,IAAIC,cAAc,AAAoB;IACtC,+DAA+D;IAC/D,MAAMC,aAAa,GAAGH,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC,AAExC;IAAA,CAACH,OAAO,IAAI,EAAE,CAAC,CAACI,IAAI,CAAC,CAACC,MAAM,GAAK;QAChC,IACEH,aAAa,CAAC,CAAC,CAAC,IAChBA,aAAa,CAAC,CAAC,CAAC,CAACI,WAAW,EAAE,KAAKD,MAAM,CAACC,WAAW,EAAE,EACvD;YACAL,cAAc,GAAGI,MAAM;YACvBH,aAAa,CAACK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;YAC1BR,QAAQ,GAAGG,aAAa,CAACM,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG;YACzC,OAAO,IAAI,CAAA;SACZ;QACD,OAAO,KAAK,CAAA;KACb,CAAC;IAEF,OAAO;QACLT,QAAQ;QACRE,cAAc;KACf,CAAA;CACF"}