added fonts
This commit is contained in:
1 parent
4134e3a234
commit
142d2986b6
9079 files changed
+1498421
-2
No files matched your search
+2
@@ -0,0 +1,2 @@
|
||||
import type { DomainLocale } from '../../../server/config-shared';
|
||||
export declare function detectDomainLocale(domainItems?: readonly DomainLocale[], hostname?: string, detectedLocale?: string): DomainLocale | undefined;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "detectDomainLocale", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return detectDomainLocale;
|
||||
}
|
||||
});
|
||||
function detectDomainLocale(domainItems, hostname, detectedLocale) {
|
||||
if (!domainItems) return;
|
||||
if (detectedLocale) {
|
||||
detectedLocale = detectedLocale.toLowerCase();
|
||||
}
|
||||
for (const item of domainItems){
|
||||
var _item_domain, _item_locales;
|
||||
// remove port if present
|
||||
const domainHostname = (_item_domain = item.domain) == null ? void 0 : _item_domain.split(':', 1)[0].toLowerCase();
|
||||
if (hostname === domainHostname || detectedLocale === item.defaultLocale.toLowerCase() || ((_item_locales = item.locales) == null ? void 0 : _item_locales.some((locale)=>locale.toLowerCase() === detectedLocale))) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=detect-domain-locale.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/i18n/detect-domain-locale.ts"],"sourcesContent":["import type { DomainLocale } from '../../../server/config-shared'\n\nexport function detectDomainLocale(\n domainItems?: readonly DomainLocale[],\n hostname?: string,\n detectedLocale?: string\n) {\n if (!domainItems) return\n\n if (detectedLocale) {\n detectedLocale = detectedLocale.toLowerCase()\n }\n\n for (const item of domainItems) {\n // remove port if present\n const domainHostname = item.domain?.split(':', 1)[0].toLowerCase()\n if (\n hostname === domainHostname ||\n detectedLocale === item.defaultLocale.toLowerCase() ||\n item.locales?.some((locale) => locale.toLowerCase() === detectedLocale)\n ) {\n return item\n }\n }\n}\n"],"names":["detectDomainLocale","domainItems","hostname","detectedLocale","toLowerCase","item","domainHostname","domain","split","defaultLocale","locales","some","locale"],"mappings":";;;;+BAEgBA;;;eAAAA;;;AAAT,SAASA,mBACdC,WAAqC,EACrCC,QAAiB,EACjBC,cAAuB;IAEvB,IAAI,CAACF,aAAa;IAElB,IAAIE,gBAAgB;QAClBA,iBAAiBA,eAAeC,WAAW;IAC7C;IAEA,KAAK,MAAMC,QAAQJ,YAAa;YAEPI,cAIrBA;QALF,yBAAyB;QACzB,MAAMC,kBAAiBD,eAAAA,KAAKE,MAAM,qBAAXF,aAAaG,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAACJ,WAAW;QAChE,IACEF,aAAaI,kBACbH,mBAAmBE,KAAKI,aAAa,CAACL,WAAW,QACjDC,gBAAAA,KAAKK,OAAO,qBAAZL,cAAcM,IAAI,CAAC,CAACC,SAAWA,OAAOR,WAAW,OAAOD,kBACxD;YACA,OAAOE;QACT;IACF;AACF"}
|
||||
+21
@@ -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 {};
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "getLocaleRedirect", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return getLocaleRedirect;
|
||||
}
|
||||
});
|
||||
const _acceptheader = require("../../../server/accept-header");
|
||||
const _denormalizepagepath = require("../page-path/denormalize-page-path");
|
||||
const _detectdomainlocale = require("./detect-domain-locale");
|
||||
const _formaturl = require("../router/utils/format-url");
|
||||
const _getcookieparser = require("../../../server/api-utils/get-cookie-parser");
|
||||
function getLocaleFromCookie(i18n, headers) {
|
||||
if (headers === void 0) headers = {};
|
||||
var _getCookieParser_NEXT_LOCALE, _getCookieParser;
|
||||
const nextLocale = (_getCookieParser = (0, _getcookieparser.getCookieParser)(headers || {})()) == null ? void 0 : (_getCookieParser_NEXT_LOCALE = _getCookieParser.NEXT_LOCALE) == null ? void 0 : _getCookieParser_NEXT_LOCALE.toLowerCase();
|
||||
return nextLocale ? i18n.locales.find((locale)=>nextLocale === locale.toLowerCase()) : undefined;
|
||||
}
|
||||
function detectLocale(param) {
|
||||
let { i18n, headers, domainLocale, preferredLocale, pathLocale } = param;
|
||||
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(param) {
|
||||
let { defaultLocale, domainLocale, pathLocale, headers, nextConfig, urlParsed } = param;
|
||||
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)({
|
||||
...urlParsed,
|
||||
pathname: (nextConfig.basePath || '') + "/" + detectedLocale + (nextConfig.trailingSlash ? '/' : '')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=get-locale-redirect.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/i18n/get-locale-redirect.ts"],"sourcesContent":["import type { DomainLocale } from '../../../server/config'\nimport type { I18NConfig } from '../../../server/config-shared'\nimport { acceptLanguage } from '../../../server/accept-header'\nimport { denormalizePagePath } from '../page-path/denormalize-page-path'\nimport { detectDomainLocale } from './detect-domain-locale'\nimport { formatUrl } from '../router/utils/format-url'\nimport { getCookieParser } from '../../../server/api-utils/get-cookie-parser'\n\ninterface Options {\n defaultLocale: string\n domainLocale?: DomainLocale\n headers?: { [key: string]: string | string[] | undefined }\n nextConfig: {\n basePath?: string\n i18n?: I18NConfig | null\n trailingSlash?: boolean\n }\n pathLocale?: string\n urlParsed: { hostname?: string | null; pathname: string }\n}\n\nfunction getLocaleFromCookie(\n i18n: I18NConfig,\n headers: { [key: string]: string | string[] | undefined } = {}\n) {\n const nextLocale = getCookieParser(\n headers || {}\n )()?.NEXT_LOCALE?.toLowerCase()\n return nextLocale\n ? i18n.locales.find((locale) => nextLocale === locale.toLowerCase())\n : undefined\n}\n\nfunction detectLocale({\n i18n,\n headers,\n domainLocale,\n preferredLocale,\n pathLocale,\n}: {\n i18n: I18NConfig\n preferredLocale?: string\n headers?: { [key: string]: string | string[] | undefined }\n domainLocale?: DomainLocale\n pathLocale?: string\n}) {\n return (\n pathLocale ||\n domainLocale?.defaultLocale ||\n getLocaleFromCookie(i18n, headers) ||\n preferredLocale ||\n i18n.defaultLocale\n )\n}\n\nfunction getAcceptPreferredLocale(\n i18n: I18NConfig,\n headers?: { [key: string]: string | string[] | undefined }\n) {\n if (\n headers?.['accept-language'] &&\n !Array.isArray(headers['accept-language'])\n ) {\n try {\n return acceptLanguage(headers['accept-language'], i18n.locales)\n } catch (err) {}\n }\n}\n\nexport function getLocaleRedirect({\n defaultLocale,\n domainLocale,\n pathLocale,\n headers,\n nextConfig,\n urlParsed,\n}: Options) {\n if (\n nextConfig.i18n &&\n nextConfig.i18n.localeDetection !== false &&\n denormalizePagePath(urlParsed.pathname) === '/'\n ) {\n const preferredLocale = getAcceptPreferredLocale(nextConfig.i18n, headers)\n const detectedLocale = detectLocale({\n i18n: nextConfig.i18n,\n preferredLocale,\n headers,\n pathLocale,\n domainLocale,\n })\n\n const preferredDomain = detectDomainLocale(\n nextConfig.i18n.domains,\n undefined,\n preferredLocale\n )\n\n if (domainLocale && preferredDomain) {\n const isPDomain = preferredDomain.domain === domainLocale.domain\n const isPLocale = preferredDomain.defaultLocale === preferredLocale\n if (!isPDomain || !isPLocale) {\n const scheme = `http${preferredDomain.http ? '' : 's'}`\n const rlocale = isPLocale ? '' : preferredLocale\n return `${scheme}://${preferredDomain.domain}/${rlocale}`\n }\n }\n\n if (detectedLocale.toLowerCase() !== defaultLocale.toLowerCase()) {\n return formatUrl({\n ...urlParsed,\n pathname: `${nextConfig.basePath || ''}/${detectedLocale}${\n nextConfig.trailingSlash ? '/' : ''\n }`,\n })\n }\n }\n}\n"],"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","trailingSlash"],"mappings":";;;;+BAqEgBA;;;eAAAA;;;8BAnEe;qCACK;oCACD;2BACT;iCACM;AAehC,SAASC,oBACPC,IAAgB,EAChBC,OAA8D;IAA9DA,IAAAA,oBAAAA,UAA4D,CAAC;QAE1CC,8BAAAA;IAAnB,MAAMC,cAAaD,mBAAAA,IAAAA,gCAAe,EAChCD,WAAW,CAAC,0BADKC,+BAAAA,iBAEdE,WAAW,qBAFGF,6BAEDG,WAAW;IAC7B,OAAOF,aACHH,KAAKM,OAAO,CAACC,IAAI,CAAC,CAACC,SAAWL,eAAeK,OAAOH,WAAW,MAC/DI;AACN;AAEA,SAASC,aAAa,KAYrB;IAZqB,IAAA,EACpBV,IAAI,EACJC,OAAO,EACPU,YAAY,EACZC,eAAe,EACfC,UAAU,EAOX,GAZqB;IAapB,OACEA,eACAF,gCAAAA,aAAcG,aAAa,KAC3Bf,oBAAoBC,MAAMC,YAC1BW,mBACAZ,KAAKc,aAAa;AAEtB;AAEA,SAASC,yBACPf,IAAgB,EAChBC,OAA0D;IAE1D,IACEA,CAAAA,2BAAAA,OAAS,CAAC,kBAAkB,KAC5B,CAACe,MAAMC,OAAO,CAAChB,OAAO,CAAC,kBAAkB,GACzC;QACA,IAAI;YACF,OAAOiB,IAAAA,4BAAc,EAACjB,OAAO,CAAC,kBAAkB,EAAED,KAAKM,OAAO;QAChE,EAAE,OAAOa,KAAK,CAAC;IACjB;AACF;AAEO,SAASrB,kBAAkB,KAOxB;IAPwB,IAAA,EAChCgB,aAAa,EACbH,YAAY,EACZE,UAAU,EACVZ,OAAO,EACPmB,UAAU,EACVC,SAAS,EACD,GAPwB;IAQhC,IACED,WAAWpB,IAAI,IACfoB,WAAWpB,IAAI,CAACsB,eAAe,KAAK,SACpCC,IAAAA,wCAAmB,EAACF,UAAUG,QAAQ,MAAM,KAC5C;QACA,MAAMZ,kBAAkBG,yBAAyBK,WAAWpB,IAAI,EAAEC;QAClE,MAAMwB,iBAAiBf,aAAa;YACLine truncated
|
||||
+14
@@ -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?: readonly string[]): PathLocale;
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "normalizeLocalePath", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return normalizeLocalePath;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* A cache of lowercased locales for each list of locales. This is stored as a
|
||||
* WeakMap so if the locales are garbage collected, the cache entry will be
|
||||
* removed as well.
|
||||
*/ const cache = new WeakMap();
|
||||
function normalizeLocalePath(pathname, locales) {
|
||||
// If locales is undefined, return the pathname as is.
|
||||
if (!locales) return {
|
||||
pathname
|
||||
};
|
||||
// Get the cached lowercased locales or create a new cache entry.
|
||||
let lowercasedLocales = cache.get(locales);
|
||||
if (!lowercasedLocales) {
|
||||
lowercasedLocales = locales.map((locale)=>locale.toLowerCase());
|
||||
cache.set(locales, lowercasedLocales);
|
||||
}
|
||||
let detectedLocale;
|
||||
// The first segment will be empty, because it has a leading `/`. If
|
||||
// there is no further segment, there is no locale (or it's the default).
|
||||
const segments = pathname.split('/', 2);
|
||||
// If there's no second segment (ie, the pathname is just `/`), there's no
|
||||
// locale.
|
||||
if (!segments[1]) return {
|
||||
pathname
|
||||
};
|
||||
// The second segment will contain the locale part if any.
|
||||
const segment = segments[1].toLowerCase();
|
||||
// See if the segment matches one of the locales. If it doesn't, there is
|
||||
// no locale (or it's the default).
|
||||
const index = lowercasedLocales.indexOf(segment);
|
||||
if (index < 0) return {
|
||||
pathname
|
||||
};
|
||||
// Return the case-sensitive locale.
|
||||
detectedLocale = locales[index];
|
||||
// Remove the `/${locale}` part of the pathname.
|
||||
pathname = pathname.slice(detectedLocale.length + 1) || '/';
|
||||
return {
|
||||
pathname,
|
||||
detectedLocale
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=normalize-locale-path.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/i18n/normalize-locale-path.ts"],"sourcesContent":["export interface PathLocale {\n detectedLocale?: string\n pathname: string\n}\n\n/**\n * A cache of lowercased locales for each list of locales. This is stored as a\n * WeakMap so if the locales are garbage collected, the cache entry will be\n * removed as well.\n */\nconst cache = new WeakMap<readonly string[], readonly string[]>()\n\n/**\n * For a pathname that may include a locale from a list of locales, it\n * removes the locale from the pathname returning it alongside with the\n * detected locale.\n *\n * @param pathname A pathname that may include a locale.\n * @param locales A list of locales.\n * @returns The detected locale and pathname without locale\n */\nexport function normalizeLocalePath(\n pathname: string,\n locales?: readonly string[]\n): PathLocale {\n // If locales is undefined, return the pathname as is.\n if (!locales) return { pathname }\n\n // Get the cached lowercased locales or create a new cache entry.\n let lowercasedLocales = cache.get(locales)\n if (!lowercasedLocales) {\n lowercasedLocales = locales.map((locale) => locale.toLowerCase())\n cache.set(locales, lowercasedLocales)\n }\n\n let detectedLocale: string | undefined\n\n // The first segment will be empty, because it has a leading `/`. If\n // there is no further segment, there is no locale (or it's the default).\n const segments = pathname.split('/', 2)\n\n // If there's no second segment (ie, the pathname is just `/`), there's no\n // locale.\n if (!segments[1]) return { pathname }\n\n // The second segment will contain the locale part if any.\n const segment = segments[1].toLowerCase()\n\n // See if the segment matches one of the locales. If it doesn't, there is\n // no locale (or it's the default).\n const index = lowercasedLocales.indexOf(segment)\n if (index < 0) return { pathname }\n\n // Return the case-sensitive locale.\n detectedLocale = locales[index]\n\n // Remove the `/${locale}` part of the pathname.\n pathname = pathname.slice(detectedLocale.length + 1) || '/'\n\n return { pathname, detectedLocale }\n}\n"],"names":["normalizeLocalePath","cache","WeakMap","pathname","locales","lowercasedLocales","get","map","locale","toLowerCase","set","detectedLocale","segments","split","segment","index","indexOf","slice","length"],"mappings":";;;;+BAqBgBA;;;eAAAA;;;AAhBhB;;;;CAIC,GACD,MAAMC,QAAQ,IAAIC;AAWX,SAASF,oBACdG,QAAgB,EAChBC,OAA2B;IAE3B,sDAAsD;IACtD,IAAI,CAACA,SAAS,OAAO;QAAED;IAAS;IAEhC,iEAAiE;IACjE,IAAIE,oBAAoBJ,MAAMK,GAAG,CAACF;IAClC,IAAI,CAACC,mBAAmB;QACtBA,oBAAoBD,QAAQG,GAAG,CAAC,CAACC,SAAWA,OAAOC,WAAW;QAC9DR,MAAMS,GAAG,CAACN,SAASC;IACrB;IAEA,IAAIM;IAEJ,oEAAoE;IACpE,yEAAyE;IACzE,MAAMC,WAAWT,SAASU,KAAK,CAAC,KAAK;IAErC,0EAA0E;IAC1E,UAAU;IACV,IAAI,CAACD,QAAQ,CAAC,EAAE,EAAE,OAAO;QAAET;IAAS;IAEpC,0DAA0D;IAC1D,MAAMW,UAAUF,QAAQ,CAAC,EAAE,CAACH,WAAW;IAEvC,yEAAyE;IACzE,mCAAmC;IACnC,MAAMM,QAAQV,kBAAkBW,OAAO,CAACF;IACxC,IAAIC,QAAQ,GAAG,OAAO;QAAEZ;IAAS;IAEjC,oCAAoC;IACpCQ,iBAAiBP,OAAO,CAACW,MAAM;IAE/B,gDAAgD;IAChDZ,WAAWA,SAASc,KAAK,CAACN,eAAeO,MAAM,GAAG,MAAM;IAExD,OAAO;QAAEf;QAAUQ;IAAe;AACpC"}
|
||||
Reference in new issue
Block a user