gt-tanstack-start 11.0.13 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/index.client.d.mts +97 -3
- package/dist/index.client.d.mts.map +1 -1
- package/dist/index.client.mjs +57 -2
- package/dist/index.client.mjs.map +1 -1
- package/dist/index.server.d.mts +97 -3
- package/dist/index.server.d.mts.map +1 -1
- package/dist/index.server.mjs +42 -5
- package/dist/index.server.mjs.map +1 -1
- package/dist/server.mjs +2 -2
- package/dist/server.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# gt-tanstack-start
|
|
2
2
|
|
|
3
|
+
## 11.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1974](https://github.com/generaltranslation/gt/pull/1974) [`bbf4eb0`](https://github.com/generaltranslation/gt/commit/bbf4eb0cf77160baa615776619acd7afe35697ba) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add opt-in locale routing for TanStack Start. Setting `localeRouting` in `gt.config.json` makes `gtMiddleware` prioritize locale path prefixes and updates client locale changes to keep the pathname in sync while leaving the default locale unprefixed.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`bbf4eb0`](https://github.com/generaltranslation/gt/commit/bbf4eb0cf77160baa615776619acd7afe35697ba), [`f53bb5e`](https://github.com/generaltranslation/gt/commit/f53bb5ea4b4989a2a4ad3aebf464011f01e029ad)]:
|
|
12
|
+
- generaltranslation@9.0.4
|
|
13
|
+
- gt-i18n@1.0.8
|
|
14
|
+
- gt-react@11.1.0
|
|
15
|
+
- @generaltranslation/react-core@11.1.0
|
|
16
|
+
|
|
3
17
|
## 11.0.13
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.client.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT as initializeGT$1, mFallback, msg, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations } from "gt-react";
|
|
1
|
+
import { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, createOrUpdateBrowserConditionStore, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT as initializeGT$1, mFallback, msg, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations } from "gt-react";
|
|
2
2
|
import { GTFunctionType, MFunctionType, Message, TFunctionType } from "gt-i18n/types";
|
|
3
3
|
|
|
4
4
|
//#region src/functions/parseLocale.d.ts
|
|
@@ -11,6 +11,101 @@ import { GTFunctionType, MFunctionType, Message, TFunctionType } from "gt-i18n/t
|
|
|
11
11
|
*/
|
|
12
12
|
declare function parseLocale(): string;
|
|
13
13
|
//#endregion
|
|
14
|
+
//#region ../format/dist/types-COaQnqVZ.d.cts
|
|
15
|
+
//#region src/locales/customLocaleMapping.d.ts
|
|
16
|
+
type CustomMapping = Record<string, string | Partial<LocaleProperties>>; //#endregion
|
|
17
|
+
//#region src/locales/getLocaleProperties.d.ts
|
|
18
|
+
type LocaleProperties = {
|
|
19
|
+
code: string;
|
|
20
|
+
name: string;
|
|
21
|
+
nativeName: string;
|
|
22
|
+
languageCode: string;
|
|
23
|
+
languageName: string;
|
|
24
|
+
nativeLanguageName: string;
|
|
25
|
+
nameWithRegionCode: string;
|
|
26
|
+
nativeNameWithRegionCode: string;
|
|
27
|
+
regionCode: string;
|
|
28
|
+
regionName: string;
|
|
29
|
+
nativeRegionName: string;
|
|
30
|
+
scriptCode: string;
|
|
31
|
+
scriptName: string;
|
|
32
|
+
nativeScriptName: string;
|
|
33
|
+
maximizedCode: string;
|
|
34
|
+
maximizedName: string;
|
|
35
|
+
nativeMaximizedName: string;
|
|
36
|
+
minimizedCode: string;
|
|
37
|
+
minimizedName: string;
|
|
38
|
+
nativeMinimizedName: string;
|
|
39
|
+
emoji: string;
|
|
40
|
+
}; //#endregion
|
|
41
|
+
//#region src/locales/getRegionProperties.d.ts
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region ../core/dist/types-wj-Dtih8.d.cts
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/types-dir/config.d.ts
|
|
46
|
+
/**
|
|
47
|
+
* Options shared by the CLI, compiler, and runtimes under
|
|
48
|
+
* `files.gt.parsingFlags` in gt.config.json.
|
|
49
|
+
*/
|
|
50
|
+
type GTParsingFlags = {
|
|
51
|
+
autoderive?: boolean | {
|
|
52
|
+
jsx?: boolean;
|
|
53
|
+
strings?: boolean;
|
|
54
|
+
};
|
|
55
|
+
includeSourceCodeContext?: boolean;
|
|
56
|
+
enableAutoJsxInjection?: boolean;
|
|
57
|
+
legacyGtReactImportSource?: boolean;
|
|
58
|
+
devHotReload?: boolean | {
|
|
59
|
+
strings?: boolean;
|
|
60
|
+
jsx?: boolean;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/** Configuration for generated GT translation files. */
|
|
64
|
+
type GTOutputFileConfig = {
|
|
65
|
+
output?: string;
|
|
66
|
+
publish?: boolean;
|
|
67
|
+
parsingFlags?: GTParsingFlags; /** @deprecated Use `parsingFlags.includeSourceCodeContext` instead. */
|
|
68
|
+
includeSourceCodeContext?: boolean;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* File configuration is primarily consumed by the CLI. Other packages only
|
|
72
|
+
* inspect `files.gt`, but must still accept the complete gt.config.json shape.
|
|
73
|
+
*/
|
|
74
|
+
type GTFilesConfig = {
|
|
75
|
+
gt?: GTOutputFileConfig;
|
|
76
|
+
[fileType: string]: unknown;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The configuration stored in gt.config.json.
|
|
80
|
+
*
|
|
81
|
+
* All settings are optional. Runtimes default `defaultLocale` to
|
|
82
|
+
* `libraryDefaultLocale` and `locales` to an empty list before resolving the
|
|
83
|
+
* effective locale set.
|
|
84
|
+
*/
|
|
85
|
+
type GTConfig = {
|
|
86
|
+
defaultLocale?: string;
|
|
87
|
+
locales?: string[];
|
|
88
|
+
customMapping?: CustomMapping;
|
|
89
|
+
enableI18n?: boolean; /** Enable framework-provided locale path routing when supported. */
|
|
90
|
+
localeRouting?: boolean;
|
|
91
|
+
projectId?: string;
|
|
92
|
+
devApiKey?: string;
|
|
93
|
+
apiKey?: string;
|
|
94
|
+
_versionId?: string;
|
|
95
|
+
_branchId?: string;
|
|
96
|
+
cacheUrl?: string | null;
|
|
97
|
+
cacheExpiryTime?: number;
|
|
98
|
+
runtimeUrl?: string | null;
|
|
99
|
+
modelProvider?: string;
|
|
100
|
+
_disableDevHotReload?: boolean;
|
|
101
|
+
files?: GTFilesConfig;
|
|
102
|
+
}; //#endregion
|
|
103
|
+
//#region src/types-dir/api/json.d.ts
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/types/InitializeGTParams.d.ts
|
|
106
|
+
type BrowserConditionStoreParams = Parameters<typeof createOrUpdateBrowserConditionStore>[0];
|
|
107
|
+
type InitializeGTParams = Parameters<typeof initializeGT$1>[0] & Pick<BrowserConditionStoreParams, '_reload'> & Pick<GTConfig, 'localeRouting'>;
|
|
108
|
+
//#endregion
|
|
14
109
|
//#region src/functions/runtime.d.ts
|
|
15
110
|
/** Return the locale associated with the current request or browser. */
|
|
16
111
|
declare const getLocale: () => string;
|
|
@@ -24,9 +119,8 @@ declare const getMessages: () => Promise<MFunctionType>;
|
|
|
24
119
|
declare const getTranslations: (rootId?: string) => Promise<TFunctionType>;
|
|
25
120
|
//#endregion
|
|
26
121
|
//#region src/setup/initializeGT.client.d.ts
|
|
27
|
-
type InitializeGTParams = Parameters<typeof initializeGT$1>[0];
|
|
28
122
|
/** Initialize GT and its browser condition store from the locale cookie. */
|
|
29
123
|
declare function initializeGT(config: InitializeGTParams): void;
|
|
30
124
|
//#endregion
|
|
31
|
-
export { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getEnableI18n, getGT, getLocale, getMessages, getTranslations, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, parseLocale, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations };
|
|
125
|
+
export { Branch, Currency, DateTime, Derive, GTProvider, type InitializeGTParams, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getEnableI18n, getGT, getLocale, getMessages, getTranslations, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, parseLocale, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations };
|
|
32
126
|
//# sourceMappingURL=index.client.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.d.mts","names":[],"sources":["../src/functions/parseLocale.ts","../src/functions/runtime.ts","../src/setup/initializeGT.client.ts"],"mappings":";;;;;;;;AAuBA;;;iBAAgB,WAAA,CAAA;;;;
|
|
1
|
+
{"version":3,"file":"index.client.d.mts","names":["CustomMapping","LocaleProperties","Partial","Record","code","name","nativeName","languageCode","languageName","nativeLanguageName","nameWithRegionCode","nativeNameWithRegionCode","regionCode","regionName","nativeRegionName","scriptCode","scriptName","nativeScriptName","maximizedCode","maximizedName","nativeMaximizedName","minimizedCode","minimizedName","nativeMinimizedName","emoji","CustomRegionMapping","region","locale","getRegionProperties","defaultLocale","customMapping","CutoffFormatStyle","TerminatorOptions","terminator","separator","CutoffFormatOptions","maxChars","style","VariableType","Variable","k","i","v","HTML_CONTENT_PROPS","pl","ti","alt","arl","arb","ard","HtmlContentPropKeysRecord","HtmlContentPropValuesRecord","GTProp","JsxChildren","b","t","JsxElement","d","c","JsxChild","StringFormat","DataFormat","StringContent","IcuMessage","StringMessage","I18nextMessage","Content","FormatVariables","Date","S","_","a","f","g","h","l","m","n","o","p","r","s","u","x","y","Content","CustomMapping","CustomMapping$1","CustomRegionMapping","CustomRegionMapping$1","CutoffFormatOptions","CutoffFormatOptions$1","DataFormat","DataFormat$1","FormatVariables","FormatVariables$1","GTProp","HTML_CONTENT_PROPS","HtmlContentPropKeysRecord","HtmlContentPropValuesRecord","I18nextMessage","I18nextMessage$1","IcuMessage","IcuMessage$1","JsxChild","JsxChildren","JsxChildren$1","JsxElement","LocaleProperties","LocaleProperties$1","StringContent","StringFormat","StringFormat$1","StringMessage","StringMessage$1","Variable","VariableType","ActionType","EntryMetadata","id","hash","context","maxChars","dataFormat","actionType","RuntimeTranslateManyOptions","sourceLocale","modelProvider","key","TranslateOptions","targetLocale","TranslateManyEntry","source","metadata","HashMetadata","requiresReview","GTParsingFlags","autoderive","jsx","strings","includeSourceCodeContext","enableAutoJsxInjection","legacyGtReactImportSource","devHotReload","GTOutputFileConfig","output","publish","parsingFlags","GTFilesConfig","gt","fileType","GTConfig","defaultLocale","locales","customMapping","enableI18n","localeRouting","projectId","devApiKey","apiKey","_versionId","_branchId","cacheUrl","cacheExpiryTime","runtimeUrl","_disableDevHotReload","files","JsonPrimitive","JsonValue","JsonObject","CheckFileTranslationsOptions","timeout","FileQuery","fileId","branchId","versionId","FileQueryResult","sourceFile","fileName","fileFormat","createdAt","updatedAt","translations","locale","completedAt","approvedAt","publishedAt","UpdateMetadata","staticId","format","filePaths","sourceCode","contextDeriveExpr","_contextDeriveExpr","Updates","EnqueueFilesResult","jobData","jobId","sourceFileId","force","message","FileFormat","FormatMetadata","FileToUpload","FileReference","Omit","content","transformFormat","formatMetadata","incomingBranchId","checkedOutBranchId","FileReferenceIds","DownloadFileBatchRequest","useLatestAvailableVersion","DownloadFileBatchOptions","DownloadedFile","data","DownloadFileBatchResult","count","EnqueueFilesOptions","targetLocales","CreateTagFileReference","CreateTagOptions","tagId","CreateTagResult","tag","SetupProjectFileReference","Pick","SetupProjectResult","setupJobId","status","SetupProjectOptions","timeoutMs","GTJsonFormatMetadata","Record","domain","requestVersion","approved_at","approved_by","FileUpload","UploadFilesOptions","UploadFilesResponse","uploadedFiles","PublishFileEntry","PublishFilesResult","results","success","error","DownloadFileOptions","TranslationResultReference","TypedResult","translation","TranslationError","code","RequestSuccess","TranslationResult","TranslateManyResult","BranchDataResult","branches","name","defaultBranch","BranchQuery","branchNames","FileDataQuery","sourceFiles","translatedFiles","FileDataResult","OrphanedFile","GetOrphanedFilesResult","orphanedFiles","MoveMapping","oldFileId","newFileId","newFileName","MoveResult","newSourceFileId","clonedTranslationsCount","ProcessMovesResponse","summary","total","succeeded","failed","ProcessMovesOptions","JobStatus","CheckJobStatusResult","AwaitJobsOptions","pollingIntervalSeconds","timeoutSeconds","JobResult","AwaitJobsResult","complete","jobs","SubmitUserEditDiff","diff","localContent","SubmitUserEditDiffsPayload","diffs","Transformation","BaseTransformation","InjectionType","TransformationPrefix","VariableTransformationSuffix","Metadata","TranslationRequestConfig","baseUrl","$","A","At","B","C","Ct","D","Dt","E","Et","F","G","H","I","J","K","L","M","Mt","N","O","Ot","P","Q","R","S","St","T","Tt","U","V","W","X","Y","Z","_","_t","a","at","b","bt","c","ct","d","dt","et","f","ft","g","h","ht","i","it","j","jt","k","kt","l","lt","m","mt","n","nt","o","ot","p","pt","q","r","rt","s","st","t","tt","u","ut","v","vt","w","wt","x","xt","y","yt","z"],"sources":["../src/functions/parseLocale.ts","../../format/dist/types-COaQnqVZ.d.cts","../../core/dist/types-wj-Dtih8.d.cts","../src/types/InitializeGTParams.ts","../src/functions/runtime.ts","../src/setup/initializeGT.client.ts"],"mappings":";;;;;;;;AAuBA;;;iBAAgB,WAAA,CAAA;;;;KCtBXA,aAAAA,GAAgBG,MAAAA,kBAAwBD,OAAAA,CAAQD,gBAAAA;AAAAA;AAAAA,KAGhDA,gBAAAA;EACHG,IAAAA;EACAC,IAAAA;EACAC,UAAAA;EACAC,YAAAA;EACAC,YAAAA;EACAC,kBAAAA;EACAC,kBAAAA;EACAC,wBAAAA;EACAC,UAAAA;EACAC,UAAAA;EACAC,gBAAAA;EACAC,UAAAA;EACAC,UAAAA;EACAC,gBAAAA;EACAC,aAAAA;EACAC,aAAAA;EACAC,mBAAAA;EACAC,aAAAA;EACAC,aAAAA;EACAC,mBAAAA;EACAC,KAAAA;AAAAA;AAAAA;;;;;AC4BuB;;;;AAAA,KAQpBgH,cAAAA;EACHC,UAAAA;IACEC,GAAAA;IACAC,OAAAA;EAAAA;EAEFC,wBAAAA;EACAC,sBAAAA;EACAC,yBAAAA;EACAC,YAAAA;IACEJ,OAAAA;IACAD,GAAAA;EAAAA;AAAAA;;KAICM,kBAAAA;EACHC,MAAAA;EACAC,OAAAA;EACAC,YAAAA,GAAeX,cAAAA,EAAfW;EACAP,wBAAAA;AAAAA;;;AAAwB;;KAMrBQ,aAAAA;EACHC,EAAAA,GAAKL,kBAAAA;EAAAA,CACJM,QAAAA;AAAAA;;;;AAAgB;;;;KASdC,QAAAA;EACHC,aAAAA;EACAC,OAAAA;EACAC,aAAAA,GAAgBpE,aAAAA;EAChBqE,UAAAA,YAAAA;EACAC,aAAAA;EACAC,SAAAA;EACAC,SAAAA;EACAC,MAAAA;EACAC,UAAAA;EACAC,SAAAA;EACAC,QAAAA;EACAC,eAAAA;EACAC,UAAAA;EACArC,aAAAA;EACAsC,oBAAAA;EACAC,KAAAA,GAAQlB,aAAAA;AAAAA;AAAAA;;;KC1GL,2BAAA,GAA8B,UAAA,QAC1B,mCAAA;AAAA,KAGG,kBAAA,GAAqB,UAAA,QAAkB,cAAA,OACjD,IAAA,CAAK,2BAAA,eACL,IAAA,CAAK,QAAA;;;;cCIM,SAAA;;cAKA,aAAA;;cAKA,KAAA,GAAQ,QAAA,GAAW,OAAA,OAAc,OAAA,CAAQ,cAAA;;cAwBzC,WAAA,QAAmB,OAAA,CAAQ,aAAA;;cAiB3B,eAAA,GAAkB,MAAA,cAAoB,OAAA,CAAQ,aAAA;;;;iBC1D3C,YAAA,CAAa,MAAA,EAAQ,kBAAA"}
|
package/dist/index.client.mjs
CHANGED
|
@@ -62,6 +62,48 @@ const getConditionStore = conditionStoreSingleton.get;
|
|
|
62
62
|
conditionStoreSingleton.set;
|
|
63
63
|
const isConditionStoreInitialized = conditionStoreSingleton.isInitialized;
|
|
64
64
|
//#endregion
|
|
65
|
+
//#region src/functions/localeRouting.ts
|
|
66
|
+
/** Resolve a supported locale from the first pathname segment. */
|
|
67
|
+
function getLocaleFromPath(pathname, basepath = getRouterBasepath()) {
|
|
68
|
+
const { pathname: routePathname } = splitBasepath(pathname, basepath);
|
|
69
|
+
const match = routePathname.match(/^\/([^/]+)(?:\/|$)/);
|
|
70
|
+
if (!match) return void 0;
|
|
71
|
+
let segment;
|
|
72
|
+
try {
|
|
73
|
+
segment = decodeURIComponent(match[1]);
|
|
74
|
+
} catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return getI18nConfig().determineSupportedLocale(segment);
|
|
78
|
+
}
|
|
79
|
+
/** Replace the pathname locale, leaving the default locale unprefixed. */
|
|
80
|
+
function getPathnameForLocale(pathname, locale, basepath = getRouterBasepath()) {
|
|
81
|
+
const i18nConfig = getI18nConfig();
|
|
82
|
+
const { basepath: routeBasepath, pathname: routePathname } = splitBasepath(pathname, basepath);
|
|
83
|
+
const unlocalizedPath = getLocaleFromPath(routePathname, "/") ? routePathname.replace(/^\/[^/]+/, "") || "/" : routePathname;
|
|
84
|
+
const resolvedLocale = i18nConfig.resolveSupportedLocale(locale);
|
|
85
|
+
if (resolvedLocale === i18nConfig.getDefaultLocale()) return `${routeBasepath}${unlocalizedPath}`;
|
|
86
|
+
return `${routeBasepath}/${encodeURIComponent(resolvedLocale)}${unlocalizedPath === "/" ? "" : unlocalizedPath}`;
|
|
87
|
+
}
|
|
88
|
+
function getRouterBasepath() {
|
|
89
|
+
return process.env.TSS_ROUTER_BASEPATH || "/";
|
|
90
|
+
}
|
|
91
|
+
function splitBasepath(pathname, basepath) {
|
|
92
|
+
const normalizedBasepath = `/${basepath.replace(/^\/+|\/+$/g, "")}`;
|
|
93
|
+
if (normalizedBasepath === "/" || pathname === normalizedBasepath) return {
|
|
94
|
+
basepath: normalizedBasepath === "/" ? "" : normalizedBasepath,
|
|
95
|
+
pathname: pathname === normalizedBasepath ? "/" : pathname
|
|
96
|
+
};
|
|
97
|
+
if (pathname.startsWith(`${normalizedBasepath}/`)) return {
|
|
98
|
+
basepath: normalizedBasepath,
|
|
99
|
+
pathname: pathname.slice(normalizedBasepath.length)
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
basepath: "",
|
|
103
|
+
pathname
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
65
107
|
//#region src/functions/requestConditions.ts
|
|
66
108
|
const localeCookieOptions = {
|
|
67
109
|
path: "/",
|
|
@@ -75,10 +117,14 @@ const noLocaleCandidatesWarning = createDiagnosticMessage({
|
|
|
75
117
|
reassurance: "GT will use the configured default locale",
|
|
76
118
|
why: "neither the locale cookie nor the Accept-Language header supplied a supported locale candidate"
|
|
77
119
|
});
|
|
78
|
-
function resolveRequestConditions(request, localeConfig) {
|
|
120
|
+
function resolveRequestConditions(request, localeConfig, pathname = new URL(request.url).pathname) {
|
|
79
121
|
const i18nConfig = getI18nConfig();
|
|
80
122
|
const cookieHeader = request.headers.get("cookie");
|
|
81
123
|
const localeCandidates = [];
|
|
124
|
+
if (localeConfig?.localeRouting) {
|
|
125
|
+
const pathLocale = getLocaleFromPath(pathname);
|
|
126
|
+
if (pathLocale) localeCandidates.push(pathLocale);
|
|
127
|
+
}
|
|
82
128
|
const cookieLocale = getCookieValue(cookieHeader, i18nConfig.getLocaleCookieName());
|
|
83
129
|
if (cookieLocale) localeCandidates.push(cookieLocale);
|
|
84
130
|
localeCandidates.push(...parseAcceptLanguage(request.headers.get("accept-language")));
|
|
@@ -193,9 +239,18 @@ function determineLocaleClient({ defaultLocale, locales, customMapping }) {
|
|
|
193
239
|
//#region src/setup/initializeGT.client.ts
|
|
194
240
|
/** Initialize GT and its browser condition store from the locale cookie. */
|
|
195
241
|
function initializeGT(config) {
|
|
242
|
+
const browserConfig = config.localeRouting && !config._reload ? {
|
|
243
|
+
...config,
|
|
244
|
+
_reload: ({ locale }) => {
|
|
245
|
+
const pathname = getPathnameForLocale(window.location.pathname, locale);
|
|
246
|
+
const destination = new URL(window.location.href);
|
|
247
|
+
destination.pathname = pathname;
|
|
248
|
+
window.location.assign(destination.href);
|
|
249
|
+
}
|
|
250
|
+
} : config;
|
|
196
251
|
initializeGT$1(config);
|
|
197
252
|
createOrUpdateBrowserConditionStore({
|
|
198
|
-
...
|
|
253
|
+
...browserConfig,
|
|
199
254
|
locale: determineLocaleClient(config)
|
|
200
255
|
});
|
|
201
256
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/requestConditions.ts","../src/functions/runtime.ts","../src/functions/parseLocale.ts","../src/setup/initializeGT.client.ts"],"sourcesContent":["//#region src/settings/settings.ts\nconst libraryDefaultLocale = \"en\";\nconst defaultTimeout = 6e4;\n//#endregion\n//#region src/logging/diagnostics.ts\nfunction ensureSentence(text) {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return \"\";\n\treturn /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\nfunction stripSentence(text) {\n\tconst trimmed = text.trim();\n\tlet end = trimmed.length;\n\twhile (end > 0) {\n\t\tconst char = trimmed[end - 1];\n\t\tif (char !== \".\" && char !== \"!\" && char !== \"?\") break;\n\t\tend -= 1;\n\t}\n\treturn trimmed.slice(0, end);\n}\nfunction lowercaseFirstWord(text) {\n\treturn text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\nfunction formatDetails(details) {\n\tif (!details) return \"\";\n\tconst detailText = Array.isArray(details) ? details.join(\", \") : details;\n\tif (!detailText.trim()) return \"\";\n\treturn ensureSentence(`Details: ${detailText}`);\n}\nfunction formatDiagnosticErrorDetails(error) {\n\tif (error == null) return void 0;\n\treturn String(error);\n}\nfunction createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {\n\tconst prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : \"\";\n\tconst whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;\n\tconst shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n\tconst messageParts = [\n\t\twhatAndWhy,\n\t\treassurance,\n\t\tshouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,\n\t\tshouldCombineWayOut ? void 0 : wayOut,\n\t\tformatDetails(details)\n\t].filter((part) => !!part).map(ensureSentence);\n\tif (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);\n\tconst message = messageParts.join(\" \");\n\treturn prefix ? `${prefix} ${message}` : message;\n}\n//#endregion\n//#region src/settings/settingsUrls.ts\nconst defaultCacheUrl = \"https://cdn.gtx.dev\";\nconst defaultBaseUrl = \"https://api2.gtx.dev\";\nconst defaultRuntimeApiUrl = \"https://runtime2.gtx.dev\";\n//#endregion\n//#region src/translate/api.ts\nconst API_VERSION = \"2026-03-06.v1\";\n//#endregion\nexport { createDiagnosticMessage as a, libraryDefaultLocale as c, defaultRuntimeApiUrl as i, defaultBaseUrl as n, formatDiagnosticErrorDetails as o, defaultCacheUrl as r, defaultTimeout as s, API_VERSION as t };\n\n//# sourceMappingURL=api-BOEGbEF6.mjs.map","import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport type { AsyncLocalConditionStore } from './AsyncLocalConditionStore';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT server request state before initialization',\n why: 'initializeGT() has not initialized the TanStack Start server condition store',\n fix: \"Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs.\",\n});\n\nconst conditionStoreSingleton = createGlobalSingleton<AsyncLocalConditionStore>(\n {\n namespace: 'tanstackStart',\n key: 'conditionStore',\n source: 'gt-tanstack-start',\n notInitialized: () => conditionStoreNotInitializedError,\n }\n);\n\nexport const getConditionStore = conditionStoreSingleton.get;\nexport const setConditionStore = conditionStoreSingleton.set;\nexport const isConditionStoreInitialized =\n conditionStoreSingleton.isInitialized;\n","import { setCookie } from '@tanstack/react-start/server';\nimport {\n getI18nConfig,\n type I18nConfigParams,\n} from '@generaltranslation/react-core/pure';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getCookieValue, parseAcceptLanguage } from 'gt-i18n/internal';\nimport type { RequestConditions } from '../condition-store/AsyncLocalConditionStore';\n\nexport const localeCookieOptions = {\n path: '/',\n sameSite: 'lax' as const,\n maxAge: 60 * 60 * 24 * 365,\n};\n\nconst noLocaleCandidatesWarning = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Warning',\n whatHappened: 'No locale preference was found for the current request',\n reassurance: 'GT will use the configured default locale',\n why: 'neither the locale cookie nor the Accept-Language header supplied a supported locale candidate',\n});\n\nexport function resolveRequestConditions(\n request: Request,\n localeConfig?: I18nConfigParams\n): RequestConditions {\n const i18nConfig = getI18nConfig();\n const cookieHeader = request.headers.get('cookie');\n const localeCandidates: string[] = [];\n const cookieLocale = getCookieValue(\n cookieHeader,\n i18nConfig.getLocaleCookieName()\n );\n if (cookieLocale) localeCandidates.push(cookieLocale);\n localeCandidates.push(\n ...parseAcceptLanguage(request.headers.get('accept-language'))\n );\n\n if (localeCandidates.length === 0) {\n console.warn(noLocaleCandidatesWarning);\n }\n\n const locale = i18nConfig.resolveSupportedLocale(\n localeCandidates,\n localeConfig ?? {\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n }\n );\n\n setCookie(i18nConfig.getLocaleCookieName(), locale, localeCookieOptions);\n\n const enableI18nCookie = getCookieValue(\n cookieHeader,\n i18nConfig.getEnableI18nCookieName()\n );\n\n return {\n locale,\n region:\n getCookieValue(cookieHeader, i18nConfig.getRegionCookieName()) ||\n undefined,\n enableI18n:\n enableI18nCookie === undefined ? true : enableI18nCookie === 'true',\n };\n}\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getReadonlyConditionStore } from '@generaltranslation/react-core/pure';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type {\n GTFunctionType,\n MFunctionType,\n Message,\n TFunctionType,\n} from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current request or browser. */\nexport const getLocale: () => string = createIsomorphicFn()\n .server((): string => getConditionStore().getLocale())\n .client((): string => getReadonlyConditionStore().getLocale());\n\n/** Return whether internationalization is enabled for the current runtime. */\nexport const getEnableI18n: () => boolean = createIsomorphicFn()\n .server((): boolean => getConditionStore().getEnableI18n())\n .client((): boolean => getReadonlyConditionStore().getEnableI18n());\n\n/** Return a string translation function for the current runtime. */\nexport const getGT: (messages?: Message[]) => Promise<GTFunctionType> =\n createIsomorphicFn()\n .server((messages?: Message[]) => {\n const conditionStore = getConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n })\n .client((messages?: Message[]) => {\n const conditionStore = getReadonlyConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n });\n\n/** Return a registered-message translation function for the current runtime. */\nexport const getMessages: () => Promise<MFunctionType> = createIsomorphicFn()\n .server(() => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n })\n .client(() => {\n const conditionStore = getReadonlyConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n });\n\n/** Return a dictionary translation function for the current runtime. */\nexport const getTranslations: (rootId?: string) => Promise<TFunctionType> =\n createIsomorphicFn()\n .server((rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n })\n .client((rootId?: string) => {\n const conditionStore = getReadonlyConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n });\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getRequest } from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getCookieValue } from 'gt-i18n/internal';\nimport type { LocaleResolverConfig } from 'gt-i18n/internal/types';\nimport {\n getConditionStore,\n isConditionStoreInitialized,\n} from '../condition-store/singleton';\nimport { resolveRequestConditions } from './requestConditions';\nimport { getLocale } from './runtime';\n\nexport const determineLocale = createIsomorphicFn()\n .server(determineLocaleServer)\n .client(() => getLocale());\n\n/**\n * Resolve the user's locale for the current TanStack Start request or browser.\n *\n * @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is\n * retained as a fallback for server setups that have not initialized request\n * scope through the middleware.\n */\nexport function parseLocale(): string {\n const i18nConfig = getI18nConfig();\n return determineLocale({\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n });\n}\n\nfunction determineLocaleServer({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig) {\n if (isConditionStoreInitialized()) {\n const conditionStore = getConditionStore();\n if (conditionStore.hasActiveScope()) {\n return conditionStore.getLocale();\n }\n }\n\n return resolveRequestConditions(getRequest(), {\n defaultLocale,\n locales,\n customMapping,\n }).locale;\n}\n\n/** Read the server-synchronized locale cookie during client initialization. */\nexport function determineLocaleClient({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig): string {\n const i18nConfig = getI18nConfig();\n const localeCookieName = i18nConfig.getLocaleCookieName();\n const candidates: string[] = [];\n\n const cookie = getCookieValue(document.cookie, localeCookieName);\n if (cookie) candidates.push(cookie);\n\n if (candidates.length === 0) {\n console.warn(\n 'gt-tanstack-start(client): no locales could be determined for this request'\n );\n }\n\n return i18nConfig.resolveSupportedLocale(candidates, {\n defaultLocale,\n locales,\n customMapping,\n });\n}\n","import {\n createOrUpdateBrowserConditionStore,\n initializeGT as initializeReactGT,\n} from 'gt-react';\nimport { determineLocaleClient } from '../functions/parseLocale';\n\ntype InitializeGTParams = Parameters<typeof initializeReactGT>[0];\n\n/** Initialize GT and its browser condition store from the locale cookie. */\nexport function initializeGT(config: InitializeGTParams): void {\n initializeReactGT(config);\n createOrUpdateBrowserConditionStore({\n ...config,\n locale: determineLocaleClient(config),\n });\n}\n"],"mappings":";;;;;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OAAO,SAAS,IAAK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C,QAAO,yBAAyB,YAAY,EAAE;EAC5C;EACA;EACA;EACD,CAAC,CAAC;;;AAIL,SAAgB,sBAAsB,EACpC,eACA,SACA,iBAC+B;CAC/B,MAAM,aAAa,eAAe;CAClC,MAAM,mBAAmB,WAAW,qBAAqB;CACzD,MAAM,aAAuB,EAAE;CAE/B,MAAM,SAAS,eAAe,SAAS,QAAQ,iBAAiB;AAChE,KAAI,OAAQ,YAAW,KAAK,OAAO;AAEnC,KAAI,WAAW,WAAW,EACxB,SAAQ,KACN,6EACD;AAGH,QAAO,WAAW,uBAAuB,YAAY;EACnD;EACA;EACA;EACD,CAAC;;;;;ACjEJ,SAAgB,aAAa,QAAkC;AAC7D,gBAAkB,OAAO;AACzB,qCAAoC;EAClC,GAAG;EACH,QAAQ,sBAAsB,OAAO;EACtC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.client.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/localeRouting.ts","../src/functions/requestConditions.ts","../src/functions/runtime.ts","../src/functions/parseLocale.ts","../src/setup/initializeGT.client.ts"],"sourcesContent":["//#region src/settings/settings.ts\nconst libraryDefaultLocale = \"en\";\nconst defaultTimeout = 6e4;\n//#endregion\n//#region src/logging/diagnostics.ts\nfunction ensureSentence(text) {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return \"\";\n\treturn /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\nfunction stripSentence(text) {\n\tconst trimmed = text.trim();\n\tlet end = trimmed.length;\n\twhile (end > 0) {\n\t\tconst char = trimmed[end - 1];\n\t\tif (char !== \".\" && char !== \"!\" && char !== \"?\") break;\n\t\tend -= 1;\n\t}\n\treturn trimmed.slice(0, end);\n}\nfunction lowercaseFirstWord(text) {\n\treturn text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\nfunction formatDetails(details) {\n\tif (!details) return \"\";\n\tconst detailText = Array.isArray(details) ? details.join(\", \") : details;\n\tif (!detailText.trim()) return \"\";\n\treturn ensureSentence(`Details: ${detailText}`);\n}\nfunction formatDiagnosticErrorDetails(error) {\n\tif (error == null) return void 0;\n\treturn String(error);\n}\nfunction createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {\n\tconst prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : \"\";\n\tconst whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;\n\tconst shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n\tconst messageParts = [\n\t\twhatAndWhy,\n\t\treassurance,\n\t\tshouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,\n\t\tshouldCombineWayOut ? void 0 : wayOut,\n\t\tformatDetails(details)\n\t].filter((part) => !!part).map(ensureSentence);\n\tif (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);\n\tconst message = messageParts.join(\" \");\n\treturn prefix ? `${prefix} ${message}` : message;\n}\n//#endregion\n//#region src/settings/settingsUrls.ts\nconst defaultCacheUrl = \"https://cdn.gtx.dev\";\nconst defaultBaseUrl = \"https://api2.gtx.dev\";\nconst defaultRuntimeApiUrl = \"https://runtime2.gtx.dev\";\n//#endregion\n//#region src/translate/api.ts\nconst API_VERSION = \"2026-03-06.v1\";\n//#endregion\nexport { createDiagnosticMessage as a, libraryDefaultLocale as c, defaultRuntimeApiUrl as i, defaultBaseUrl as n, formatDiagnosticErrorDetails as o, defaultCacheUrl as r, defaultTimeout as s, API_VERSION as t };\n\n//# sourceMappingURL=api-BOEGbEF6.mjs.map","import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport type { AsyncLocalConditionStore } from './AsyncLocalConditionStore';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT server request state before initialization',\n why: 'initializeGT() has not initialized the TanStack Start server condition store',\n fix: \"Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs.\",\n});\n\nconst conditionStoreSingleton = createGlobalSingleton<AsyncLocalConditionStore>(\n {\n namespace: 'tanstackStart',\n key: 'conditionStore',\n source: 'gt-tanstack-start',\n notInitialized: () => conditionStoreNotInitializedError,\n }\n);\n\nexport const getConditionStore = conditionStoreSingleton.get;\nexport const setConditionStore = conditionStoreSingleton.set;\nexport const isConditionStoreInitialized =\n conditionStoreSingleton.isInitialized;\n","import { getI18nConfig } from '@generaltranslation/react-core/pure';\n\n/** Resolve a supported locale from the first pathname segment. */\nexport function getLocaleFromPath(\n pathname: string,\n basepath = getRouterBasepath()\n): string | undefined {\n const { pathname: routePathname } = splitBasepath(pathname, basepath);\n const match = routePathname.match(/^\\/([^/]+)(?:\\/|$)/);\n if (!match) return undefined;\n\n let segment: string;\n try {\n segment = decodeURIComponent(match[1]);\n } catch {\n return undefined;\n }\n\n return getI18nConfig().determineSupportedLocale(segment);\n}\n\n/** Replace the pathname locale, leaving the default locale unprefixed. */\nexport function getPathnameForLocale(\n pathname: string,\n locale: string,\n basepath = getRouterBasepath()\n): string {\n const i18nConfig = getI18nConfig();\n const { basepath: routeBasepath, pathname: routePathname } = splitBasepath(\n pathname,\n basepath\n );\n const pathLocale = getLocaleFromPath(routePathname, '/');\n const unlocalizedPath = pathLocale\n ? routePathname.replace(/^\\/[^/]+/, '') || '/'\n : routePathname;\n const resolvedLocale = i18nConfig.resolveSupportedLocale(locale);\n\n if (resolvedLocale === i18nConfig.getDefaultLocale()) {\n return `${routeBasepath}${unlocalizedPath}`;\n }\n\n return `${routeBasepath}/${encodeURIComponent(resolvedLocale)}${\n unlocalizedPath === '/' ? '' : unlocalizedPath\n }`;\n}\n\nfunction getRouterBasepath(): string {\n return process.env.TSS_ROUTER_BASEPATH || '/';\n}\n\nfunction splitBasepath(\n pathname: string,\n basepath: string\n): { basepath: string; pathname: string } {\n const normalizedBasepath = `/${basepath.replace(/^\\/+|\\/+$/g, '')}`;\n if (normalizedBasepath === '/' || pathname === normalizedBasepath) {\n return {\n basepath: normalizedBasepath === '/' ? '' : normalizedBasepath,\n pathname: pathname === normalizedBasepath ? '/' : pathname,\n };\n }\n if (pathname.startsWith(`${normalizedBasepath}/`)) {\n return {\n basepath: normalizedBasepath,\n pathname: pathname.slice(normalizedBasepath.length),\n };\n }\n return { basepath: '', pathname };\n}\n","import { setCookie } from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getCookieValue, parseAcceptLanguage } from 'gt-i18n/internal';\nimport type { RequestConditions } from '../condition-store/AsyncLocalConditionStore';\nimport type { InitializeGTParams } from '../types/InitializeGTParams';\nimport { getLocaleFromPath } from './localeRouting';\n\nexport const localeCookieOptions = {\n path: '/',\n sameSite: 'lax' as const,\n maxAge: 60 * 60 * 24 * 365,\n};\n\nconst noLocaleCandidatesWarning = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Warning',\n whatHappened: 'No locale preference was found for the current request',\n reassurance: 'GT will use the configured default locale',\n why: 'neither the locale cookie nor the Accept-Language header supplied a supported locale candidate',\n});\n\nexport function resolveRequestConditions(\n request: Request,\n localeConfig?: InitializeGTParams,\n pathname = new URL(request.url).pathname\n): RequestConditions {\n const i18nConfig = getI18nConfig();\n const cookieHeader = request.headers.get('cookie');\n const localeCandidates: string[] = [];\n if (localeConfig?.localeRouting) {\n const pathLocale = getLocaleFromPath(pathname);\n if (pathLocale) localeCandidates.push(pathLocale);\n }\n const cookieLocale = getCookieValue(\n cookieHeader,\n i18nConfig.getLocaleCookieName()\n );\n if (cookieLocale) localeCandidates.push(cookieLocale);\n localeCandidates.push(\n ...parseAcceptLanguage(request.headers.get('accept-language'))\n );\n\n if (localeCandidates.length === 0) {\n console.warn(noLocaleCandidatesWarning);\n }\n\n const locale = i18nConfig.resolveSupportedLocale(\n localeCandidates,\n localeConfig ?? {\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n }\n );\n\n setCookie(i18nConfig.getLocaleCookieName(), locale, localeCookieOptions);\n\n const enableI18nCookie = getCookieValue(\n cookieHeader,\n i18nConfig.getEnableI18nCookieName()\n );\n\n return {\n locale,\n region:\n getCookieValue(cookieHeader, i18nConfig.getRegionCookieName()) ||\n undefined,\n enableI18n:\n enableI18nCookie === undefined ? true : enableI18nCookie === 'true',\n };\n}\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getReadonlyConditionStore } from '@generaltranslation/react-core/pure';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type {\n GTFunctionType,\n MFunctionType,\n Message,\n TFunctionType,\n} from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current request or browser. */\nexport const getLocale: () => string = createIsomorphicFn()\n .server((): string => getConditionStore().getLocale())\n .client((): string => getReadonlyConditionStore().getLocale());\n\n/** Return whether internationalization is enabled for the current runtime. */\nexport const getEnableI18n: () => boolean = createIsomorphicFn()\n .server((): boolean => getConditionStore().getEnableI18n())\n .client((): boolean => getReadonlyConditionStore().getEnableI18n());\n\n/** Return a string translation function for the current runtime. */\nexport const getGT: (messages?: Message[]) => Promise<GTFunctionType> =\n createIsomorphicFn()\n .server((messages?: Message[]) => {\n const conditionStore = getConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n })\n .client((messages?: Message[]) => {\n const conditionStore = getReadonlyConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n });\n\n/** Return a registered-message translation function for the current runtime. */\nexport const getMessages: () => Promise<MFunctionType> = createIsomorphicFn()\n .server(() => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n })\n .client(() => {\n const conditionStore = getReadonlyConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n });\n\n/** Return a dictionary translation function for the current runtime. */\nexport const getTranslations: (rootId?: string) => Promise<TFunctionType> =\n createIsomorphicFn()\n .server((rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n })\n .client((rootId?: string) => {\n const conditionStore = getReadonlyConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n });\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getRequest } from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getCookieValue } from 'gt-i18n/internal';\nimport type { LocaleResolverConfig } from 'gt-i18n/internal/types';\nimport {\n getConditionStore,\n isConditionStoreInitialized,\n} from '../condition-store/singleton';\nimport { resolveRequestConditions } from './requestConditions';\nimport { getLocale } from './runtime';\n\nexport const determineLocale = createIsomorphicFn()\n .server(determineLocaleServer)\n .client(() => getLocale());\n\n/**\n * Resolve the user's locale for the current TanStack Start request or browser.\n *\n * @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is\n * retained as a fallback for server setups that have not initialized request\n * scope through the middleware.\n */\nexport function parseLocale(): string {\n const i18nConfig = getI18nConfig();\n return determineLocale({\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n });\n}\n\nfunction determineLocaleServer({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig) {\n if (isConditionStoreInitialized()) {\n const conditionStore = getConditionStore();\n if (conditionStore.hasActiveScope()) {\n return conditionStore.getLocale();\n }\n }\n\n return resolveRequestConditions(getRequest(), {\n defaultLocale,\n locales,\n customMapping,\n }).locale;\n}\n\n/** Read the server-synchronized locale cookie during client initialization. */\nexport function determineLocaleClient({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig): string {\n const i18nConfig = getI18nConfig();\n const localeCookieName = i18nConfig.getLocaleCookieName();\n const candidates: string[] = [];\n\n const cookie = getCookieValue(document.cookie, localeCookieName);\n if (cookie) candidates.push(cookie);\n\n if (candidates.length === 0) {\n console.warn(\n 'gt-tanstack-start(client): no locales could be determined for this request'\n );\n }\n\n return i18nConfig.resolveSupportedLocale(candidates, {\n defaultLocale,\n locales,\n customMapping,\n });\n}\n","import {\n createOrUpdateBrowserConditionStore,\n initializeGT as initializeReactGT,\n} from 'gt-react';\nimport { determineLocaleClient } from '../functions/parseLocale';\nimport { getPathnameForLocale } from '../functions/localeRouting';\nimport type { InitializeGTParams } from '../types/InitializeGTParams';\n\n/** Initialize GT and its browser condition store from the locale cookie. */\nexport function initializeGT(config: InitializeGTParams): void {\n const browserConfig =\n config.localeRouting && !config._reload\n ? {\n ...config,\n _reload: ({ locale }: { locale: string }) => {\n const pathname = getPathnameForLocale(\n window.location.pathname,\n locale\n );\n const destination = new URL(window.location.href);\n destination.pathname = pathname;\n window.location.assign(destination.href);\n },\n }\n : config;\n\n initializeReactGT(config);\n createOrUpdateBrowserConditionStore({\n ...browserConfig,\n locale: determineLocaleClient(config),\n });\n}\n"],"mappings":";;;;;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,S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ACjC,QAAO,eAAe,WAAW;;AAIrC,QAAO,yBAAyB,YAAY,EAAE;EAC5C;EACA;EACA;EACD,CAAC,CAAC;;;AAIL,SAAgB,sBAAsB,EACpC,eACA,SACA,iBAC+B;CAC/B,MAAM,aAAa,eAAe;CAClC,MAAM,mBAAmB,WAAW,qBAAqB;CACzD,MAAM,aAAuB,EAAE;CAE/B,MAAM,SAAS,eAAe,SAAS,QAAQ,iBAAiB;AAChE,KAAI,OAAQ,YAAW,KAAK,OAAO;AAEnC,KAAI,WAAW,WAAW,EACxB,SAAQ,KACN,6EACD;AAGH,QAAO,WAAW,uBAAuB,YAAY;EACnD;EACA;EACA;EACD,CAAC;;;;;ACjEJ,SAAgB,aAAa,QAAkC;CAC7D,MAAM,gBACJ,OAAO,iBAAiB,CAAC,OAAO,UAC5B;EACE,GAAG;EACH,UAAU,EAAE,aAAiC;GAC3C,MAAM,WAAW,qBACf,OAAO,SAAS,UAChB,OACD;GACD,MAAM,cAAc,IAAI,IAAI,OAAO,SAAS,KAAK;AACjD,eAAY,WAAW;AACvB,UAAO,SAAS,OAAO,YAAY,KAAK;;EAE3C,GACD;AAEN,gBAAkB,OAAO;AACzB,qCAAoC;EAClC,GAAG;EACH,QAAQ,sBAAsB,OAAO;EACtC,CAAC"}
|
package/dist/index.server.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestMiddlewareAfterServer } from "@tanstack/react-start";
|
|
2
|
-
import { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT as initializeGT$1, mFallback, msg, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations } from "gt-react";
|
|
2
|
+
import { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, createOrUpdateBrowserConditionStore, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT as initializeGT$1, mFallback, msg, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations } from "gt-react";
|
|
3
3
|
import { GTFunctionType, MFunctionType, Message, TFunctionType } from "gt-i18n/types";
|
|
4
4
|
|
|
5
5
|
//#region src/functions/parseLocale.d.ts
|
|
@@ -12,6 +12,101 @@ import { GTFunctionType, MFunctionType, Message, TFunctionType } from "gt-i18n/t
|
|
|
12
12
|
*/
|
|
13
13
|
declare function parseLocale(): string;
|
|
14
14
|
//#endregion
|
|
15
|
+
//#region ../format/dist/types-COaQnqVZ.d.cts
|
|
16
|
+
//#region src/locales/customLocaleMapping.d.ts
|
|
17
|
+
type CustomMapping = Record<string, string | Partial<LocaleProperties>>; //#endregion
|
|
18
|
+
//#region src/locales/getLocaleProperties.d.ts
|
|
19
|
+
type LocaleProperties = {
|
|
20
|
+
code: string;
|
|
21
|
+
name: string;
|
|
22
|
+
nativeName: string;
|
|
23
|
+
languageCode: string;
|
|
24
|
+
languageName: string;
|
|
25
|
+
nativeLanguageName: string;
|
|
26
|
+
nameWithRegionCode: string;
|
|
27
|
+
nativeNameWithRegionCode: string;
|
|
28
|
+
regionCode: string;
|
|
29
|
+
regionName: string;
|
|
30
|
+
nativeRegionName: string;
|
|
31
|
+
scriptCode: string;
|
|
32
|
+
scriptName: string;
|
|
33
|
+
nativeScriptName: string;
|
|
34
|
+
maximizedCode: string;
|
|
35
|
+
maximizedName: string;
|
|
36
|
+
nativeMaximizedName: string;
|
|
37
|
+
minimizedCode: string;
|
|
38
|
+
minimizedName: string;
|
|
39
|
+
nativeMinimizedName: string;
|
|
40
|
+
emoji: string;
|
|
41
|
+
}; //#endregion
|
|
42
|
+
//#region src/locales/getRegionProperties.d.ts
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ../core/dist/types-wj-Dtih8.d.cts
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/types-dir/config.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Options shared by the CLI, compiler, and runtimes under
|
|
49
|
+
* `files.gt.parsingFlags` in gt.config.json.
|
|
50
|
+
*/
|
|
51
|
+
type GTParsingFlags = {
|
|
52
|
+
autoderive?: boolean | {
|
|
53
|
+
jsx?: boolean;
|
|
54
|
+
strings?: boolean;
|
|
55
|
+
};
|
|
56
|
+
includeSourceCodeContext?: boolean;
|
|
57
|
+
enableAutoJsxInjection?: boolean;
|
|
58
|
+
legacyGtReactImportSource?: boolean;
|
|
59
|
+
devHotReload?: boolean | {
|
|
60
|
+
strings?: boolean;
|
|
61
|
+
jsx?: boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/** Configuration for generated GT translation files. */
|
|
65
|
+
type GTOutputFileConfig = {
|
|
66
|
+
output?: string;
|
|
67
|
+
publish?: boolean;
|
|
68
|
+
parsingFlags?: GTParsingFlags; /** @deprecated Use `parsingFlags.includeSourceCodeContext` instead. */
|
|
69
|
+
includeSourceCodeContext?: boolean;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* File configuration is primarily consumed by the CLI. Other packages only
|
|
73
|
+
* inspect `files.gt`, but must still accept the complete gt.config.json shape.
|
|
74
|
+
*/
|
|
75
|
+
type GTFilesConfig = {
|
|
76
|
+
gt?: GTOutputFileConfig;
|
|
77
|
+
[fileType: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* The configuration stored in gt.config.json.
|
|
81
|
+
*
|
|
82
|
+
* All settings are optional. Runtimes default `defaultLocale` to
|
|
83
|
+
* `libraryDefaultLocale` and `locales` to an empty list before resolving the
|
|
84
|
+
* effective locale set.
|
|
85
|
+
*/
|
|
86
|
+
type GTConfig = {
|
|
87
|
+
defaultLocale?: string;
|
|
88
|
+
locales?: string[];
|
|
89
|
+
customMapping?: CustomMapping;
|
|
90
|
+
enableI18n?: boolean; /** Enable framework-provided locale path routing when supported. */
|
|
91
|
+
localeRouting?: boolean;
|
|
92
|
+
projectId?: string;
|
|
93
|
+
devApiKey?: string;
|
|
94
|
+
apiKey?: string;
|
|
95
|
+
_versionId?: string;
|
|
96
|
+
_branchId?: string;
|
|
97
|
+
cacheUrl?: string | null;
|
|
98
|
+
cacheExpiryTime?: number;
|
|
99
|
+
runtimeUrl?: string | null;
|
|
100
|
+
modelProvider?: string;
|
|
101
|
+
_disableDevHotReload?: boolean;
|
|
102
|
+
files?: GTFilesConfig;
|
|
103
|
+
}; //#endregion
|
|
104
|
+
//#region src/types-dir/api/json.d.ts
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/types/InitializeGTParams.d.ts
|
|
107
|
+
type BrowserConditionStoreParams = Parameters<typeof createOrUpdateBrowserConditionStore>[0];
|
|
108
|
+
type InitializeGTParams = Parameters<typeof initializeGT$1>[0] & Pick<BrowserConditionStoreParams, '_reload'> & Pick<GTConfig, 'localeRouting'>;
|
|
109
|
+
//#endregion
|
|
15
110
|
//#region src/functions/runtime.d.ts
|
|
16
111
|
/** Return the locale associated with the current request or browser. */
|
|
17
112
|
declare const getLocale: () => string;
|
|
@@ -32,9 +127,8 @@ declare const getTranslations: (rootId?: string) => Promise<TFunctionType>;
|
|
|
32
127
|
declare const gtMiddleware: RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
33
128
|
//#endregion
|
|
34
129
|
//#region src/setup/initializeGT.server.d.ts
|
|
35
|
-
type InitializeGTParams = Parameters<typeof initializeGT$1>[0];
|
|
36
130
|
/** Initialize GT and its server request condition store. */
|
|
37
131
|
declare function initializeGT(config: InitializeGTParams): void;
|
|
38
132
|
//#endregion
|
|
39
|
-
export { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getEnableI18n, getGT, getLocale, getMessages, getTranslations, getTranslationsSnapshot, gtFallback, gtMiddleware, initializeGT, mFallback, msg, parseLocale, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations };
|
|
133
|
+
export { Branch, Currency, DateTime, Derive, GTProvider, type InitializeGTParams, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getEnableI18n, getGT, getLocale, getMessages, getTranslations, getTranslationsSnapshot, gtFallback, gtMiddleware, initializeGT, mFallback, msg, parseLocale, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations };
|
|
40
134
|
//# sourceMappingURL=index.server.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.server.d.mts","names":[],"sources":["../src/functions/parseLocale.ts","../src/functions/runtime.ts","../src/middleware/gtMiddleware.ts","../src/setup/initializeGT.server.ts"],"mappings":";;;;;;;;;AAuBA;;;iBAAgB,WAAA,CAAA;;;;
|
|
1
|
+
{"version":3,"file":"index.server.d.mts","names":["CustomMapping","LocaleProperties","Partial","Record","code","name","nativeName","languageCode","languageName","nativeLanguageName","nameWithRegionCode","nativeNameWithRegionCode","regionCode","regionName","nativeRegionName","scriptCode","scriptName","nativeScriptName","maximizedCode","maximizedName","nativeMaximizedName","minimizedCode","minimizedName","nativeMinimizedName","emoji","CustomRegionMapping","region","locale","getRegionProperties","defaultLocale","customMapping","CutoffFormatStyle","TerminatorOptions","terminator","separator","CutoffFormatOptions","maxChars","style","VariableType","Variable","k","i","v","HTML_CONTENT_PROPS","pl","ti","alt","arl","arb","ard","HtmlContentPropKeysRecord","HtmlContentPropValuesRecord","GTProp","JsxChildren","b","t","JsxElement","d","c","JsxChild","StringFormat","DataFormat","StringContent","IcuMessage","StringMessage","I18nextMessage","Content","FormatVariables","Date","S","_","a","f","g","h","l","m","n","o","p","r","s","u","x","y","Content","CustomMapping","CustomMapping$1","CustomRegionMapping","CustomRegionMapping$1","CutoffFormatOptions","CutoffFormatOptions$1","DataFormat","DataFormat$1","FormatVariables","FormatVariables$1","GTProp","HTML_CONTENT_PROPS","HtmlContentPropKeysRecord","HtmlContentPropValuesRecord","I18nextMessage","I18nextMessage$1","IcuMessage","IcuMessage$1","JsxChild","JsxChildren","JsxChildren$1","JsxElement","LocaleProperties","LocaleProperties$1","StringContent","StringFormat","StringFormat$1","StringMessage","StringMessage$1","Variable","VariableType","ActionType","EntryMetadata","id","hash","context","maxChars","dataFormat","actionType","RuntimeTranslateManyOptions","sourceLocale","modelProvider","key","TranslateOptions","targetLocale","TranslateManyEntry","source","metadata","HashMetadata","requiresReview","GTParsingFlags","autoderive","jsx","strings","includeSourceCodeContext","enableAutoJsxInjection","legacyGtReactImportSource","devHotReload","GTOutputFileConfig","output","publish","parsingFlags","GTFilesConfig","gt","fileType","GTConfig","defaultLocale","locales","customMapping","enableI18n","localeRouting","projectId","devApiKey","apiKey","_versionId","_branchId","cacheUrl","cacheExpiryTime","runtimeUrl","_disableDevHotReload","files","JsonPrimitive","JsonValue","JsonObject","CheckFileTranslationsOptions","timeout","FileQuery","fileId","branchId","versionId","FileQueryResult","sourceFile","fileName","fileFormat","createdAt","updatedAt","translations","locale","completedAt","approvedAt","publishedAt","UpdateMetadata","staticId","format","filePaths","sourceCode","contextDeriveExpr","_contextDeriveExpr","Updates","EnqueueFilesResult","jobData","jobId","sourceFileId","force","message","FileFormat","FormatMetadata","FileToUpload","FileReference","Omit","content","transformFormat","formatMetadata","incomingBranchId","checkedOutBranchId","FileReferenceIds","DownloadFileBatchRequest","useLatestAvailableVersion","DownloadFileBatchOptions","DownloadedFile","data","DownloadFileBatchResult","count","EnqueueFilesOptions","targetLocales","CreateTagFileReference","CreateTagOptions","tagId","CreateTagResult","tag","SetupProjectFileReference","Pick","SetupProjectResult","setupJobId","status","SetupProjectOptions","timeoutMs","GTJsonFormatMetadata","Record","domain","requestVersion","approved_at","approved_by","FileUpload","UploadFilesOptions","UploadFilesResponse","uploadedFiles","PublishFileEntry","PublishFilesResult","results","success","error","DownloadFileOptions","TranslationResultReference","TypedResult","translation","TranslationError","code","RequestSuccess","TranslationResult","TranslateManyResult","BranchDataResult","branches","name","defaultBranch","BranchQuery","branchNames","FileDataQuery","sourceFiles","translatedFiles","FileDataResult","OrphanedFile","GetOrphanedFilesResult","orphanedFiles","MoveMapping","oldFileId","newFileId","newFileName","MoveResult","newSourceFileId","clonedTranslationsCount","ProcessMovesResponse","summary","total","succeeded","failed","ProcessMovesOptions","JobStatus","CheckJobStatusResult","AwaitJobsOptions","pollingIntervalSeconds","timeoutSeconds","JobResult","AwaitJobsResult","complete","jobs","SubmitUserEditDiff","diff","localContent","SubmitUserEditDiffsPayload","diffs","Transformation","BaseTransformation","InjectionType","TransformationPrefix","VariableTransformationSuffix","Metadata","TranslationRequestConfig","baseUrl","$","A","At","B","C","Ct","D","Dt","E","Et","F","G","H","I","J","K","L","M","Mt","N","O","Ot","P","Q","R","S","St","T","Tt","U","V","W","X","Y","Z","_","_t","a","at","b","bt","c","ct","d","dt","et","f","ft","g","h","ht","i","it","j","jt","k","kt","l","lt","m","mt","n","nt","o","ot","p","pt","q","r","rt","s","st","t","tt","u","ut","v","vt","w","wt","x","xt","y","yt","z"],"sources":["../src/functions/parseLocale.ts","../../format/dist/types-COaQnqVZ.d.cts","../../core/dist/types-wj-Dtih8.d.cts","../src/types/InitializeGTParams.ts","../src/functions/runtime.ts","../src/middleware/gtMiddleware.ts","../src/setup/initializeGT.server.ts"],"mappings":";;;;;;;;;AAuBA;;;iBAAgB,WAAA,CAAA;;;;KCtBXA,aAAAA,GAAgBG,MAAAA,kBAAwBD,OAAAA,CAAQD,gBAAAA;AAAAA;AAAAA,KAGhDA,gBAAAA;EACHG,IAAAA;EACAC,IAAAA;EACAC,UAAAA;EACAC,YAAAA;EACAC,YAAAA;EACAC,kBAAAA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,YAAA,EAAc,4BAAA;;;;iBCJX,YAAA,CAAa,MAAA,EAAQ,kBAAA"}
|
package/dist/index.server.mjs
CHANGED
|
@@ -63,6 +63,39 @@ const getConditionStore = conditionStoreSingleton.get;
|
|
|
63
63
|
const setConditionStore = conditionStoreSingleton.set;
|
|
64
64
|
const isConditionStoreInitialized = conditionStoreSingleton.isInitialized;
|
|
65
65
|
//#endregion
|
|
66
|
+
//#region src/functions/localeRouting.ts
|
|
67
|
+
/** Resolve a supported locale from the first pathname segment. */
|
|
68
|
+
function getLocaleFromPath(pathname, basepath = getRouterBasepath()) {
|
|
69
|
+
const { pathname: routePathname } = splitBasepath(pathname, basepath);
|
|
70
|
+
const match = routePathname.match(/^\/([^/]+)(?:\/|$)/);
|
|
71
|
+
if (!match) return void 0;
|
|
72
|
+
let segment;
|
|
73
|
+
try {
|
|
74
|
+
segment = decodeURIComponent(match[1]);
|
|
75
|
+
} catch {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
return getI18nConfig().determineSupportedLocale(segment);
|
|
79
|
+
}
|
|
80
|
+
function getRouterBasepath() {
|
|
81
|
+
return process.env.TSS_ROUTER_BASEPATH || "/";
|
|
82
|
+
}
|
|
83
|
+
function splitBasepath(pathname, basepath) {
|
|
84
|
+
const normalizedBasepath = `/${basepath.replace(/^\/+|\/+$/g, "")}`;
|
|
85
|
+
if (normalizedBasepath === "/" || pathname === normalizedBasepath) return {
|
|
86
|
+
basepath: normalizedBasepath === "/" ? "" : normalizedBasepath,
|
|
87
|
+
pathname: pathname === normalizedBasepath ? "/" : pathname
|
|
88
|
+
};
|
|
89
|
+
if (pathname.startsWith(`${normalizedBasepath}/`)) return {
|
|
90
|
+
basepath: normalizedBasepath,
|
|
91
|
+
pathname: pathname.slice(normalizedBasepath.length)
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
basepath: "",
|
|
95
|
+
pathname
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
66
99
|
//#region src/functions/requestConditions.ts
|
|
67
100
|
const localeCookieOptions = {
|
|
68
101
|
path: "/",
|
|
@@ -76,10 +109,14 @@ const noLocaleCandidatesWarning = createDiagnosticMessage({
|
|
|
76
109
|
reassurance: "GT will use the configured default locale",
|
|
77
110
|
why: "neither the locale cookie nor the Accept-Language header supplied a supported locale candidate"
|
|
78
111
|
});
|
|
79
|
-
function resolveRequestConditions(request, localeConfig) {
|
|
112
|
+
function resolveRequestConditions(request, localeConfig, pathname = new URL(request.url).pathname) {
|
|
80
113
|
const i18nConfig = getI18nConfig();
|
|
81
114
|
const cookieHeader = request.headers.get("cookie");
|
|
82
115
|
const localeCandidates = [];
|
|
116
|
+
if (localeConfig?.localeRouting) {
|
|
117
|
+
const pathLocale = getLocaleFromPath(pathname);
|
|
118
|
+
if (pathLocale) localeCandidates.push(pathLocale);
|
|
119
|
+
}
|
|
83
120
|
const cookieLocale = getCookieValue(cookieHeader, i18nConfig.getLocaleCookieName());
|
|
84
121
|
if (cookieLocale) localeCandidates.push(cookieLocale);
|
|
85
122
|
localeCandidates.push(...parseAcceptLanguage(request.headers.get("accept-language")));
|
|
@@ -182,8 +219,8 @@ function determineLocaleServer({ defaultLocale, locales, customMapping }) {
|
|
|
182
219
|
* Establish request-scoped GT conditions for SSR, server routes, and server
|
|
183
220
|
* functions.
|
|
184
221
|
*/
|
|
185
|
-
const gtMiddleware = createMiddleware().server(({ request, next }) => {
|
|
186
|
-
return getConditionStore().run(request, () => next());
|
|
222
|
+
const gtMiddleware = createMiddleware().server(({ request, pathname, next }) => {
|
|
223
|
+
return getConditionStore().run(request, () => next(), pathname);
|
|
187
224
|
});
|
|
188
225
|
//#endregion
|
|
189
226
|
//#region src/condition-store/AsyncLocalConditionStore.ts
|
|
@@ -208,8 +245,8 @@ var AsyncLocalConditionStore = class {
|
|
|
208
245
|
this.setRegion = (_region) => {};
|
|
209
246
|
this.setEnableI18n = (_enableI18n) => {};
|
|
210
247
|
}
|
|
211
|
-
run(request, callback) {
|
|
212
|
-
const conditions = resolveRequestConditions(request, this.config);
|
|
248
|
+
run(request, callback, pathname) {
|
|
249
|
+
const conditions = resolveRequestConditions(request, this.config, pathname);
|
|
213
250
|
return this.storage.run(conditions, callback);
|
|
214
251
|
}
|
|
215
252
|
hasActiveScope() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.server.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/requestConditions.ts","../src/functions/runtime.ts","../src/functions/parseLocale.ts","../src/middleware/gtMiddleware.ts","../src/condition-store/AsyncLocalConditionStore.ts","../src/setup/initializeGT.server.ts"],"sourcesContent":["//#region src/settings/settings.ts\nconst libraryDefaultLocale = \"en\";\nconst defaultTimeout = 6e4;\n//#endregion\n//#region src/logging/diagnostics.ts\nfunction ensureSentence(text) {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return \"\";\n\treturn /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\nfunction stripSentence(text) {\n\tconst trimmed = text.trim();\n\tlet end = trimmed.length;\n\twhile (end > 0) {\n\t\tconst char = trimmed[end - 1];\n\t\tif (char !== \".\" && char !== \"!\" && char !== \"?\") break;\n\t\tend -= 1;\n\t}\n\treturn trimmed.slice(0, end);\n}\nfunction lowercaseFirstWord(text) {\n\treturn text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\nfunction formatDetails(details) {\n\tif (!details) return \"\";\n\tconst detailText = Array.isArray(details) ? details.join(\", \") : details;\n\tif (!detailText.trim()) return \"\";\n\treturn ensureSentence(`Details: ${detailText}`);\n}\nfunction formatDiagnosticErrorDetails(error) {\n\tif (error == null) return void 0;\n\treturn String(error);\n}\nfunction createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {\n\tconst prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : \"\";\n\tconst whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;\n\tconst shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n\tconst messageParts = [\n\t\twhatAndWhy,\n\t\treassurance,\n\t\tshouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,\n\t\tshouldCombineWayOut ? void 0 : wayOut,\n\t\tformatDetails(details)\n\t].filter((part) => !!part).map(ensureSentence);\n\tif (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);\n\tconst message = messageParts.join(\" \");\n\treturn prefix ? `${prefix} ${message}` : message;\n}\n//#endregion\n//#region src/settings/settingsUrls.ts\nconst defaultCacheUrl = \"https://cdn.gtx.dev\";\nconst defaultBaseUrl = \"https://api2.gtx.dev\";\nconst defaultRuntimeApiUrl = \"https://runtime2.gtx.dev\";\n//#endregion\n//#region src/translate/api.ts\nconst API_VERSION = \"2026-03-06.v1\";\n//#endregion\nexport { createDiagnosticMessage as a, libraryDefaultLocale as c, defaultRuntimeApiUrl as i, defaultBaseUrl as n, formatDiagnosticErrorDetails as o, defaultCacheUrl as r, defaultTimeout as s, API_VERSION as t };\n\n//# sourceMappingURL=api-BOEGbEF6.mjs.map","import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport type { AsyncLocalConditionStore } from './AsyncLocalConditionStore';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT server request state before initialization',\n why: 'initializeGT() has not initialized the TanStack Start server condition store',\n fix: \"Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs.\",\n});\n\nconst conditionStoreSingleton = createGlobalSingleton<AsyncLocalConditionStore>(\n {\n namespace: 'tanstackStart',\n key: 'conditionStore',\n source: 'gt-tanstack-start',\n notInitialized: () => conditionStoreNotInitializedError,\n }\n);\n\nexport const getConditionStore = conditionStoreSingleton.get;\nexport const setConditionStore = conditionStoreSingleton.set;\nexport const isConditionStoreInitialized =\n conditionStoreSingleton.isInitialized;\n","import { setCookie } from '@tanstack/react-start/server';\nimport {\n getI18nConfig,\n type I18nConfigParams,\n} from '@generaltranslation/react-core/pure';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getCookieValue, parseAcceptLanguage } from 'gt-i18n/internal';\nimport type { RequestConditions } from '../condition-store/AsyncLocalConditionStore';\n\nexport const localeCookieOptions = {\n path: '/',\n sameSite: 'lax' as const,\n maxAge: 60 * 60 * 24 * 365,\n};\n\nconst noLocaleCandidatesWarning = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Warning',\n whatHappened: 'No locale preference was found for the current request',\n reassurance: 'GT will use the configured default locale',\n why: 'neither the locale cookie nor the Accept-Language header supplied a supported locale candidate',\n});\n\nexport function resolveRequestConditions(\n request: Request,\n localeConfig?: I18nConfigParams\n): RequestConditions {\n const i18nConfig = getI18nConfig();\n const cookieHeader = request.headers.get('cookie');\n const localeCandidates: string[] = [];\n const cookieLocale = getCookieValue(\n cookieHeader,\n i18nConfig.getLocaleCookieName()\n );\n if (cookieLocale) localeCandidates.push(cookieLocale);\n localeCandidates.push(\n ...parseAcceptLanguage(request.headers.get('accept-language'))\n );\n\n if (localeCandidates.length === 0) {\n console.warn(noLocaleCandidatesWarning);\n }\n\n const locale = i18nConfig.resolveSupportedLocale(\n localeCandidates,\n localeConfig ?? {\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n }\n );\n\n setCookie(i18nConfig.getLocaleCookieName(), locale, localeCookieOptions);\n\n const enableI18nCookie = getCookieValue(\n cookieHeader,\n i18nConfig.getEnableI18nCookieName()\n );\n\n return {\n locale,\n region:\n getCookieValue(cookieHeader, i18nConfig.getRegionCookieName()) ||\n undefined,\n enableI18n:\n enableI18nCookie === undefined ? true : enableI18nCookie === 'true',\n };\n}\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getReadonlyConditionStore } from '@generaltranslation/react-core/pure';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type {\n GTFunctionType,\n MFunctionType,\n Message,\n TFunctionType,\n} from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current request or browser. */\nexport const getLocale: () => string = createIsomorphicFn()\n .server((): string => getConditionStore().getLocale())\n .client((): string => getReadonlyConditionStore().getLocale());\n\n/** Return whether internationalization is enabled for the current runtime. */\nexport const getEnableI18n: () => boolean = createIsomorphicFn()\n .server((): boolean => getConditionStore().getEnableI18n())\n .client((): boolean => getReadonlyConditionStore().getEnableI18n());\n\n/** Return a string translation function for the current runtime. */\nexport const getGT: (messages?: Message[]) => Promise<GTFunctionType> =\n createIsomorphicFn()\n .server((messages?: Message[]) => {\n const conditionStore = getConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n })\n .client((messages?: Message[]) => {\n const conditionStore = getReadonlyConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n });\n\n/** Return a registered-message translation function for the current runtime. */\nexport const getMessages: () => Promise<MFunctionType> = createIsomorphicFn()\n .server(() => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n })\n .client(() => {\n const conditionStore = getReadonlyConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n });\n\n/** Return a dictionary translation function for the current runtime. */\nexport const getTranslations: (rootId?: string) => Promise<TFunctionType> =\n createIsomorphicFn()\n .server((rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n })\n .client((rootId?: string) => {\n const conditionStore = getReadonlyConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n });\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getRequest } from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getCookieValue } from 'gt-i18n/internal';\nimport type { LocaleResolverConfig } from 'gt-i18n/internal/types';\nimport {\n getConditionStore,\n isConditionStoreInitialized,\n} from '../condition-store/singleton';\nimport { resolveRequestConditions } from './requestConditions';\nimport { getLocale } from './runtime';\n\nexport const determineLocale = createIsomorphicFn()\n .server(determineLocaleServer)\n .client(() => getLocale());\n\n/**\n * Resolve the user's locale for the current TanStack Start request or browser.\n *\n * @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is\n * retained as a fallback for server setups that have not initialized request\n * scope through the middleware.\n */\nexport function parseLocale(): string {\n const i18nConfig = getI18nConfig();\n return determineLocale({\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n });\n}\n\nfunction determineLocaleServer({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig) {\n if (isConditionStoreInitialized()) {\n const conditionStore = getConditionStore();\n if (conditionStore.hasActiveScope()) {\n return conditionStore.getLocale();\n }\n }\n\n return resolveRequestConditions(getRequest(), {\n defaultLocale,\n locales,\n customMapping,\n }).locale;\n}\n\n/** Read the server-synchronized locale cookie during client initialization. */\nexport function determineLocaleClient({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig): string {\n const i18nConfig = getI18nConfig();\n const localeCookieName = i18nConfig.getLocaleCookieName();\n const candidates: string[] = [];\n\n const cookie = getCookieValue(document.cookie, localeCookieName);\n if (cookie) candidates.push(cookie);\n\n if (candidates.length === 0) {\n console.warn(\n 'gt-tanstack-start(client): no locales could be determined for this request'\n );\n }\n\n return i18nConfig.resolveSupportedLocale(candidates, {\n defaultLocale,\n locales,\n customMapping,\n });\n}\n","import {\n createMiddleware,\n type RequestMiddlewareAfterServer,\n} from '@tanstack/react-start';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/**\n * Establish request-scoped GT conditions for SSR, server routes, and server\n * functions.\n */\nexport const gtMiddleware: RequestMiddlewareAfterServer<\n {},\n undefined,\n undefined\n> = createMiddleware().server(({ request, next }) => {\n return getConditionStore().run(request, () => next());\n});\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { I18nConfigParams } from '@generaltranslation/react-core/pure';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport type { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport { resolveRequestConditions } from '../functions/requestConditions';\n\nexport type RequestConditions = {\n locale: string;\n region?: string;\n enableI18n: boolean;\n};\n\nconst missingRequestScopeError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT request state outside a request scope',\n why: 'the gt-tanstack-start request middleware has not initialized the ConditionStore for this request',\n fix: \"Register gtMiddleware from 'gt-tanstack-start' as global TanStack Start request middleware.\",\n});\n\n/**\n * Read-only ConditionStore backed by request-scoped AsyncLocalStorage.\n */\nexport class AsyncLocalConditionStore implements ReadonlyConditionStoreInterface {\n private readonly storage = new AsyncLocalStorage<RequestConditions>();\n\n constructor(private readonly config: I18nConfigParams) {}\n\n run<T>(request: Request, callback: () => T): T {\n const conditions = resolveRequestConditions(request, this.config);\n return this.storage.run(conditions, callback);\n }\n\n hasActiveScope(): boolean {\n return this.storage.getStore() !== undefined;\n }\n\n getLocale = (): string => this.getConditions().locale;\n\n getRegion = (): string | undefined => this.getConditions().region;\n\n getEnableI18n = (): boolean => this.getConditions().enableI18n;\n\n setLocale = (_locale: string): void => {};\n\n setRegion = (_region: string | undefined): void => {};\n\n setEnableI18n = (_enableI18n: boolean): void => {};\n\n private getConditions(): RequestConditions {\n const conditions = this.storage.getStore();\n if (!conditions) throw new Error(missingRequestScopeError);\n return conditions;\n }\n}\n","import { initializeGT as initializeReactGT } from 'gt-react';\nimport { AsyncLocalConditionStore } from '../condition-store/AsyncLocalConditionStore';\nimport { setConditionStore } from '../condition-store/singleton';\n\ntype InitializeGTParams = Parameters<typeof initializeReactGT>[0];\n\n/** Initialize GT and its server request condition store. */\nexport function initializeGT(config: InitializeGTParams): void {\n initializeReactGT(config);\n setConditionStore(new AsyncLocalConditionStore(config));\n}\n"],"mappings":";;;;;;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OAAO,SAAS,IAAK;AAClD,SAAO;;AAER,QAAO,QAAQ,MAAM,GAAG,IAAI;;AAE7B,SAAS,mBAAmB,MAAM;AACjC,QAAO,KAAK,QAAQ,gBAAgB,UAAU,MAAM,aAAa,CAAC;;AAEnE,SAAS,cAAc,SAAS;AAC/B,KAAI,CAAC,QAAS,QAAO;CACrB,MAAM,aAAa,MAAM,QAAQ,QAAQ,GAAG,QAAQ,KAAK,KAAK,GAAG;AACjE,KAAI,CAAC,WAAW,MAAM,CAAE,QAAO;AAC/B,QAAO,eAAe,YAAY,aAAa;;AAMhD,SAAS,wBAAwB,EAAE,QAAQ,UAAU,cAAc,aAAa,KAAK,KAAK,QAAQ,SAAS,WAAW;CACrH,MAAM,SAAS,SAAS,WAAW,GAAG,OAAO,GAAG,SAAS,KAAK,GAAG,OAAO,KAAK,WAAW,GAAG,SAAS,KAAK;CACzG,MAAM,aAAa,MAAM,GAAG,cAAc,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a,yBAAyB,SAAS,KAAK,OAAO;AACjE,SAAO,KAAK,QAAQ,IAAI,YAAY,SAAS;;CAG/C,iBAA0B;AACxB,SAAO,KAAK,QAAQ,UAAU,KAAK,KAAA;;CAerC,gBAA2C;EACzC,MAAM,aAAa,KAAK,QAAQ,UAAU;AAC1C,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,yBAAyB;AAC1D,SAAO;;;;;;AC7CX,SAAgB,aAAa,QAAkC;AAC7D,gBAAkB,OAAO;AACzB,mBAAkB,IAAI,yBAAyB,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.server.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/localeRouting.ts","../src/functions/requestConditions.ts","../src/functions/runtime.ts","../src/functions/parseLocale.ts","../src/middleware/gtMiddleware.ts","../src/condition-store/AsyncLocalConditionStore.ts","../src/setup/initializeGT.server.ts"],"sourcesContent":["//#region src/settings/settings.ts\nconst libraryDefaultLocale = \"en\";\nconst defaultTimeout = 6e4;\n//#endregion\n//#region src/logging/diagnostics.ts\nfunction ensureSentence(text) {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return \"\";\n\treturn /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\nfunction stripSentence(text) {\n\tconst trimmed = text.trim();\n\tlet end = trimmed.length;\n\twhile (end > 0) {\n\t\tconst char = trimmed[end - 1];\n\t\tif (char !== \".\" && char !== \"!\" && char !== \"?\") break;\n\t\tend -= 1;\n\t}\n\treturn trimmed.slice(0, end);\n}\nfunction lowercaseFirstWord(text) {\n\treturn text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\nfunction formatDetails(details) {\n\tif (!details) return \"\";\n\tconst detailText = Array.isArray(details) ? details.join(\", \") : details;\n\tif (!detailText.trim()) return \"\";\n\treturn ensureSentence(`Details: ${detailText}`);\n}\nfunction formatDiagnosticErrorDetails(error) {\n\tif (error == null) return void 0;\n\treturn String(error);\n}\nfunction createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {\n\tconst prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : \"\";\n\tconst whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;\n\tconst shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n\tconst messageParts = [\n\t\twhatAndWhy,\n\t\treassurance,\n\t\tshouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,\n\t\tshouldCombineWayOut ? void 0 : wayOut,\n\t\tformatDetails(details)\n\t].filter((part) => !!part).map(ensureSentence);\n\tif (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);\n\tconst message = messageParts.join(\" \");\n\treturn prefix ? `${prefix} ${message}` : message;\n}\n//#endregion\n//#region src/settings/settingsUrls.ts\nconst defaultCacheUrl = \"https://cdn.gtx.dev\";\nconst defaultBaseUrl = \"https://api2.gtx.dev\";\nconst defaultRuntimeApiUrl = \"https://runtime2.gtx.dev\";\n//#endregion\n//#region src/translate/api.ts\nconst API_VERSION = \"2026-03-06.v1\";\n//#endregion\nexport { createDiagnosticMessage as a, libraryDefaultLocale as c, defaultRuntimeApiUrl as i, defaultBaseUrl as n, formatDiagnosticErrorDetails as o, defaultCacheUrl as r, defaultTimeout as s, API_VERSION as t };\n\n//# sourceMappingURL=api-BOEGbEF6.mjs.map","import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport type { AsyncLocalConditionStore } from './AsyncLocalConditionStore';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT server request state before initialization',\n why: 'initializeGT() has not initialized the TanStack Start server condition store',\n fix: \"Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs.\",\n});\n\nconst conditionStoreSingleton = createGlobalSingleton<AsyncLocalConditionStore>(\n {\n namespace: 'tanstackStart',\n key: 'conditionStore',\n source: 'gt-tanstack-start',\n notInitialized: () => conditionStoreNotInitializedError,\n }\n);\n\nexport const getConditionStore = conditionStoreSingleton.get;\nexport const setConditionStore = conditionStoreSingleton.set;\nexport const isConditionStoreInitialized =\n conditionStoreSingleton.isInitialized;\n","import { getI18nConfig } from '@generaltranslation/react-core/pure';\n\n/** Resolve a supported locale from the first pathname segment. */\nexport function getLocaleFromPath(\n pathname: string,\n basepath = getRouterBasepath()\n): string | undefined {\n const { pathname: routePathname } = splitBasepath(pathname, basepath);\n const match = routePathname.match(/^\\/([^/]+)(?:\\/|$)/);\n if (!match) return undefined;\n\n let segment: string;\n try {\n segment = decodeURIComponent(match[1]);\n } catch {\n return undefined;\n }\n\n return getI18nConfig().determineSupportedLocale(segment);\n}\n\n/** Replace the pathname locale, leaving the default locale unprefixed. */\nexport function getPathnameForLocale(\n pathname: string,\n locale: string,\n basepath = getRouterBasepath()\n): string {\n const i18nConfig = getI18nConfig();\n const { basepath: routeBasepath, pathname: routePathname } = splitBasepath(\n pathname,\n basepath\n );\n const pathLocale = getLocaleFromPath(routePathname, '/');\n const unlocalizedPath = pathLocale\n ? routePathname.replace(/^\\/[^/]+/, '') || '/'\n : routePathname;\n const resolvedLocale = i18nConfig.resolveSupportedLocale(locale);\n\n if (resolvedLocale === i18nConfig.getDefaultLocale()) {\n return `${routeBasepath}${unlocalizedPath}`;\n }\n\n return `${routeBasepath}/${encodeURIComponent(resolvedLocale)}${\n unlocalizedPath === '/' ? '' : unlocalizedPath\n }`;\n}\n\nfunction getRouterBasepath(): string {\n return process.env.TSS_ROUTER_BASEPATH || '/';\n}\n\nfunction splitBasepath(\n pathname: string,\n basepath: string\n): { basepath: string; pathname: string } {\n const normalizedBasepath = `/${basepath.replace(/^\\/+|\\/+$/g, '')}`;\n if (normalizedBasepath === '/' || pathname === normalizedBasepath) {\n return {\n basepath: normalizedBasepath === '/' ? '' : normalizedBasepath,\n pathname: pathname === normalizedBasepath ? '/' : pathname,\n };\n }\n if (pathname.startsWith(`${normalizedBasepath}/`)) {\n return {\n basepath: normalizedBasepath,\n pathname: pathname.slice(normalizedBasepath.length),\n };\n }\n return { basepath: '', pathname };\n}\n","import { setCookie } from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getCookieValue, parseAcceptLanguage } from 'gt-i18n/internal';\nimport type { RequestConditions } from '../condition-store/AsyncLocalConditionStore';\nimport type { InitializeGTParams } from '../types/InitializeGTParams';\nimport { getLocaleFromPath } from './localeRouting';\n\nexport const localeCookieOptions = {\n path: '/',\n sameSite: 'lax' as const,\n maxAge: 60 * 60 * 24 * 365,\n};\n\nconst noLocaleCandidatesWarning = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Warning',\n whatHappened: 'No locale preference was found for the current request',\n reassurance: 'GT will use the configured default locale',\n why: 'neither the locale cookie nor the Accept-Language header supplied a supported locale candidate',\n});\n\nexport function resolveRequestConditions(\n request: Request,\n localeConfig?: InitializeGTParams,\n pathname = new URL(request.url).pathname\n): RequestConditions {\n const i18nConfig = getI18nConfig();\n const cookieHeader = request.headers.get('cookie');\n const localeCandidates: string[] = [];\n if (localeConfig?.localeRouting) {\n const pathLocale = getLocaleFromPath(pathname);\n if (pathLocale) localeCandidates.push(pathLocale);\n }\n const cookieLocale = getCookieValue(\n cookieHeader,\n i18nConfig.getLocaleCookieName()\n );\n if (cookieLocale) localeCandidates.push(cookieLocale);\n localeCandidates.push(\n ...parseAcceptLanguage(request.headers.get('accept-language'))\n );\n\n if (localeCandidates.length === 0) {\n console.warn(noLocaleCandidatesWarning);\n }\n\n const locale = i18nConfig.resolveSupportedLocale(\n localeCandidates,\n localeConfig ?? {\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n }\n );\n\n setCookie(i18nConfig.getLocaleCookieName(), locale, localeCookieOptions);\n\n const enableI18nCookie = getCookieValue(\n cookieHeader,\n i18nConfig.getEnableI18nCookieName()\n );\n\n return {\n locale,\n region:\n getCookieValue(cookieHeader, i18nConfig.getRegionCookieName()) ||\n undefined,\n enableI18n:\n enableI18nCookie === undefined ? true : enableI18nCookie === 'true',\n };\n}\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getReadonlyConditionStore } from '@generaltranslation/react-core/pure';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type {\n GTFunctionType,\n MFunctionType,\n Message,\n TFunctionType,\n} from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current request or browser. */\nexport const getLocale: () => string = createIsomorphicFn()\n .server((): string => getConditionStore().getLocale())\n .client((): string => getReadonlyConditionStore().getLocale());\n\n/** Return whether internationalization is enabled for the current runtime. */\nexport const getEnableI18n: () => boolean = createIsomorphicFn()\n .server((): boolean => getConditionStore().getEnableI18n())\n .client((): boolean => getReadonlyConditionStore().getEnableI18n());\n\n/** Return a string translation function for the current runtime. */\nexport const getGT: (messages?: Message[]) => Promise<GTFunctionType> =\n createIsomorphicFn()\n .server((messages?: Message[]) => {\n const conditionStore = getConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n })\n .client((messages?: Message[]) => {\n const conditionStore = getReadonlyConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n });\n\n/** Return a registered-message translation function for the current runtime. */\nexport const getMessages: () => Promise<MFunctionType> = createIsomorphicFn()\n .server(() => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n })\n .client(() => {\n const conditionStore = getReadonlyConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n });\n\n/** Return a dictionary translation function for the current runtime. */\nexport const getTranslations: (rootId?: string) => Promise<TFunctionType> =\n createIsomorphicFn()\n .server((rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n })\n .client((rootId?: string) => {\n const conditionStore = getReadonlyConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n });\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getRequest } from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getCookieValue } from 'gt-i18n/internal';\nimport type { LocaleResolverConfig } from 'gt-i18n/internal/types';\nimport {\n getConditionStore,\n isConditionStoreInitialized,\n} from '../condition-store/singleton';\nimport { resolveRequestConditions } from './requestConditions';\nimport { getLocale } from './runtime';\n\nexport const determineLocale = createIsomorphicFn()\n .server(determineLocaleServer)\n .client(() => getLocale());\n\n/**\n * Resolve the user's locale for the current TanStack Start request or browser.\n *\n * @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is\n * retained as a fallback for server setups that have not initialized request\n * scope through the middleware.\n */\nexport function parseLocale(): string {\n const i18nConfig = getI18nConfig();\n return determineLocale({\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n });\n}\n\nfunction determineLocaleServer({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig) {\n if (isConditionStoreInitialized()) {\n const conditionStore = getConditionStore();\n if (conditionStore.hasActiveScope()) {\n return conditionStore.getLocale();\n }\n }\n\n return resolveRequestConditions(getRequest(), {\n defaultLocale,\n locales,\n customMapping,\n }).locale;\n}\n\n/** Read the server-synchronized locale cookie during client initialization. */\nexport function determineLocaleClient({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig): string {\n const i18nConfig = getI18nConfig();\n const localeCookieName = i18nConfig.getLocaleCookieName();\n const candidates: string[] = [];\n\n const cookie = getCookieValue(document.cookie, localeCookieName);\n if (cookie) candidates.push(cookie);\n\n if (candidates.length === 0) {\n console.warn(\n 'gt-tanstack-start(client): no locales could be determined for this request'\n );\n }\n\n return i18nConfig.resolveSupportedLocale(candidates, {\n defaultLocale,\n locales,\n customMapping,\n });\n}\n","import {\n createMiddleware,\n type RequestMiddlewareAfterServer,\n} from '@tanstack/react-start';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/**\n * Establish request-scoped GT conditions for SSR, server routes, and server\n * functions.\n */\nexport const gtMiddleware: RequestMiddlewareAfterServer<\n {},\n undefined,\n undefined\n> = createMiddleware().server(({ request, pathname, next }) => {\n return getConditionStore().run(request, () => next(), pathname);\n});\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport type { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport { resolveRequestConditions } from '../functions/requestConditions';\nimport type { InitializeGTParams } from '../types/InitializeGTParams';\n\nexport type RequestConditions = {\n locale: string;\n region?: string;\n enableI18n: boolean;\n};\n\nconst missingRequestScopeError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT request state outside a request scope',\n why: 'the gt-tanstack-start request middleware has not initialized the ConditionStore for this request',\n fix: \"Register gtMiddleware from 'gt-tanstack-start' as global TanStack Start request middleware.\",\n});\n\n/**\n * Read-only ConditionStore backed by request-scoped AsyncLocalStorage.\n */\nexport class AsyncLocalConditionStore implements ReadonlyConditionStoreInterface {\n private readonly storage = new AsyncLocalStorage<RequestConditions>();\n\n constructor(private readonly config: InitializeGTParams) {}\n\n run<T>(request: Request, callback: () => T, pathname?: string): T {\n const conditions = resolveRequestConditions(request, this.config, pathname);\n return this.storage.run(conditions, callback);\n }\n\n hasActiveScope(): boolean {\n return this.storage.getStore() !== undefined;\n }\n\n getLocale = (): string => this.getConditions().locale;\n\n getRegion = (): string | undefined => this.getConditions().region;\n\n getEnableI18n = (): boolean => this.getConditions().enableI18n;\n\n setLocale = (_locale: string): void => {};\n\n setRegion = (_region: string | undefined): void => {};\n\n setEnableI18n = (_enableI18n: boolean): void => {};\n\n private getConditions(): RequestConditions {\n const conditions = this.storage.getStore();\n if (!conditions) throw new Error(missingRequestScopeError);\n return conditions;\n }\n}\n","import { initializeGT as initializeReactGT } from 'gt-react';\nimport { AsyncLocalConditionStore } from '../condition-store/AsyncLocalConditionStore';\nimport { setConditionStore } from '../condition-store/singleton';\nimport type { InitializeGTParams } from '../types/InitializeGTParams';\n\n/** Initialize GT and its server request condition store. */\nexport function initializeGT(config: InitializeGTParams): void {\n initializeReactGT(config);\n setConditionStore(new AsyncLocalConditionStore(config));\n}\n"],"mappings":";;;;;;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OAAO,SAAS,IAAK;AAClD,SAAO;;AAER,QAAO,QAAQ,MAAM,GAAG,IAAI;;AAE7B,SAAS,mBAAmB,MAAM;AACjC,QAAO,KAAK,QAAQ,gBAAgB,UAAU,MAAM,aAAa,CAAC;;AAEnE,SAAS,cAAc,SAAS;AAC/B,KAAI,CAAC,QAAS,QAAO;CACrB,MAAM,aAAa,MAAM,QAAQ,QAAQ,GAAG,QAAQ,KAAK,KAAK,GAAG;AACjE,KAAI,CAAC,WAAW,MAAM,CAA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,QAAQ,UAAU,KAAK,KAAA;;CAerC,gBAA2C;EACzC,MAAM,aAAa,KAAK,QAAQ,UAAU;AAC1C,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,yBAAyB;AAC1D,SAAO;;;;;;AC9CX,SAAgB,aAAa,QAAkC;AAC7D,gBAAkB,OAAO;AACzB,mBAAkB,IAAI,yBAAyB,OAAO,CAAC"}
|
package/dist/server.mjs
CHANGED
|
@@ -65,8 +65,8 @@ conditionStoreSingleton.isInitialized;
|
|
|
65
65
|
* Establish request-scoped GT conditions for SSR, server routes, and server
|
|
66
66
|
* functions.
|
|
67
67
|
*/
|
|
68
|
-
const gtMiddleware$1 = createMiddleware().server(({ request, next }) => {
|
|
69
|
-
return getConditionStore().run(request, () => next());
|
|
68
|
+
const gtMiddleware$1 = createMiddleware().server(({ request, pathname, next }) => {
|
|
69
|
+
return getConditionStore().run(request, () => next(), pathname);
|
|
70
70
|
});
|
|
71
71
|
//#endregion
|
|
72
72
|
//#region src/functions/runtime.ts
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","names":["gtMiddleware","getLocale","getEnableI18n","getGT","getMessages","getTranslations","mainGtMiddleware","mainGetLocale","mainGetEnableI18n","mainGetGT","mainGetMessages","mainGetTranslations"],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/middleware/gtMiddleware.ts","../src/functions/runtime.ts","../src/server.ts"],"sourcesContent":["//#region src/settings/settings.ts\nconst libraryDefaultLocale = \"en\";\nconst defaultTimeout = 6e4;\n//#endregion\n//#region src/logging/diagnostics.ts\nfunction ensureSentence(text) {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return \"\";\n\treturn /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\nfunction stripSentence(text) {\n\tconst trimmed = text.trim();\n\tlet end = trimmed.length;\n\twhile (end > 0) {\n\t\tconst char = trimmed[end - 1];\n\t\tif (char !== \".\" && char !== \"!\" && char !== \"?\") break;\n\t\tend -= 1;\n\t}\n\treturn trimmed.slice(0, end);\n}\nfunction lowercaseFirstWord(text) {\n\treturn text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\nfunction formatDetails(details) {\n\tif (!details) return \"\";\n\tconst detailText = Array.isArray(details) ? details.join(\", \") : details;\n\tif (!detailText.trim()) return \"\";\n\treturn ensureSentence(`Details: ${detailText}`);\n}\nfunction formatDiagnosticErrorDetails(error) {\n\tif (error == null) return void 0;\n\treturn String(error);\n}\nfunction createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {\n\tconst prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : \"\";\n\tconst whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;\n\tconst shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n\tconst messageParts = [\n\t\twhatAndWhy,\n\t\treassurance,\n\t\tshouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,\n\t\tshouldCombineWayOut ? void 0 : wayOut,\n\t\tformatDetails(details)\n\t].filter((part) => !!part).map(ensureSentence);\n\tif (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);\n\tconst message = messageParts.join(\" \");\n\treturn prefix ? `${prefix} ${message}` : message;\n}\n//#endregion\n//#region src/settings/settingsUrls.ts\nconst defaultCacheUrl = \"https://cdn.gtx.dev\";\nconst defaultBaseUrl = \"https://api2.gtx.dev\";\nconst defaultRuntimeApiUrl = \"https://runtime2.gtx.dev\";\n//#endregion\n//#region src/translate/api.ts\nconst API_VERSION = \"2026-03-06.v1\";\n//#endregion\nexport { createDiagnosticMessage as a, libraryDefaultLocale as c, defaultRuntimeApiUrl as i, defaultBaseUrl as n, formatDiagnosticErrorDetails as o, defaultCacheUrl as r, defaultTimeout as s, API_VERSION as t };\n\n//# sourceMappingURL=api-BOEGbEF6.mjs.map","import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport type { AsyncLocalConditionStore } from './AsyncLocalConditionStore';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT server request state before initialization',\n why: 'initializeGT() has not initialized the TanStack Start server condition store',\n fix: \"Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs.\",\n});\n\nconst conditionStoreSingleton = createGlobalSingleton<AsyncLocalConditionStore>(\n {\n namespace: 'tanstackStart',\n key: 'conditionStore',\n source: 'gt-tanstack-start',\n notInitialized: () => conditionStoreNotInitializedError,\n }\n);\n\nexport const getConditionStore = conditionStoreSingleton.get;\nexport const setConditionStore = conditionStoreSingleton.set;\nexport const isConditionStoreInitialized =\n conditionStoreSingleton.isInitialized;\n","import {\n createMiddleware,\n type RequestMiddlewareAfterServer,\n} from '@tanstack/react-start';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/**\n * Establish request-scoped GT conditions for SSR, server routes, and server\n * functions.\n */\nexport const gtMiddleware: RequestMiddlewareAfterServer<\n {},\n undefined,\n undefined\n> = createMiddleware().server(({ request, next }) => {\n return getConditionStore().run(request, () => next());\n});\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getReadonlyConditionStore } from '@generaltranslation/react-core/pure';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type {\n GTFunctionType,\n MFunctionType,\n Message,\n TFunctionType,\n} from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current request or browser. */\nexport const getLocale: () => string = createIsomorphicFn()\n .server((): string => getConditionStore().getLocale())\n .client((): string => getReadonlyConditionStore().getLocale());\n\n/** Return whether internationalization is enabled for the current runtime. */\nexport const getEnableI18n: () => boolean = createIsomorphicFn()\n .server((): boolean => getConditionStore().getEnableI18n())\n .client((): boolean => getReadonlyConditionStore().getEnableI18n());\n\n/** Return a string translation function for the current runtime. */\nexport const getGT: (messages?: Message[]) => Promise<GTFunctionType> =\n createIsomorphicFn()\n .server((messages?: Message[]) => {\n const conditionStore = getConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n })\n .client((messages?: Message[]) => {\n const conditionStore = getReadonlyConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n });\n\n/** Return a registered-message translation function for the current runtime. */\nexport const getMessages: () => Promise<MFunctionType> = createIsomorphicFn()\n .server(() => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n })\n .client(() => {\n const conditionStore = getReadonlyConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n });\n\n/** Return a dictionary translation function for the current runtime. */\nexport const getTranslations: (rootId?: string) => Promise<TFunctionType> =\n createIsomorphicFn()\n .server((rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n })\n .client((rootId?: string) => {\n const conditionStore = getReadonlyConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n });\n","import type { RequestMiddlewareAfterServer } from '@tanstack/react-start';\nimport { gtMiddleware as mainGtMiddleware } from './middleware/gtMiddleware';\nimport {\n getEnableI18n as mainGetEnableI18n,\n getGT as mainGetGT,\n getLocale as mainGetLocale,\n getMessages as mainGetMessages,\n getTranslations as mainGetTranslations,\n} from './functions/runtime';\n\n/** @deprecated Import `gtMiddleware` from `gt-tanstack-start` instead. */\nexport const gtMiddleware: RequestMiddlewareAfterServer<\n {},\n undefined,\n undefined\n> = mainGtMiddleware;\n\n/** @deprecated Import `getLocale` from `gt-tanstack-start` instead. */\nexport const getLocale = mainGetLocale;\n\n/** @deprecated Import `getEnableI18n` from `gt-tanstack-start` instead. */\nexport const getEnableI18n = mainGetEnableI18n;\n\n/** @deprecated Import `getGT` from `gt-tanstack-start` instead. */\nexport const getGT = mainGetGT;\n\n/** @deprecated Import `getMessages` from `gt-tanstack-start` instead. */\nexport const getMessages = mainGetMessages;\n\n/** @deprecated Import `getTranslations` from `gt-tanstack-start` instead. */\nexport const getTranslations = mainGetTranslations;\n"],"mappings":";;;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OAAO,SAAS,IAAK;AAClD,SAAO;;AAER,QAAO,QAAQ,MAAM,GAAG,IAAI;;AAE7B,SAAS,mBAAmB,MAAM;AACjC,QAAO,KAAK,QAAQ,gBAAgB,UAAU,MAAM,aAAa,CAAC;;AAEnE,SAAS,cAAc,SAAS;AAC/B,KAAI,CAAC,QAAS,QAAO;CACrB,MAAM,aAAa,MAAM,QAAQ,QAAQ,GAAG,QAAQ,KAAK,KAAK,GAAG;AACjE,KAAI,CAAC,WAAW,MAAM,CAAE,QAAO;AAC/B,QAAO,eAAe,YAAY,aAAa;;AAMhD,SAAS,wBAAwB,EAAE,QAAQ,UAAU,cAAc,aAAa,KAAK,KAAK,QAAQ,SAAS,WAAW;CACrH,MAAM,SAAS,SAAS,WAAW,GAAG,OAAO,GAAG,SAAS,KAAK,GAAG,OAAO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L;EACE,QAAQ,eAAe,WAAW;EAClC,YAAY,eAAe,eAAe;EAC3C,EACD,SACD;EACD,CACD,QAAQ,aAAyB;CAChC,MAAM,iBAAiB,2BAA2B;AAClD,QAAO,cACL;EACE,QAAQ,eAAe,WAAW;EAClC,YAAY,eAAe,eAAe;EAC3C,EACD,SACD;EACD;;AAGN,MAAaC,gBAA4C,oBAAoB,CAC1E,aAAa;CACZ,MAAM,iBAAiB,mBAAmB;AAC1C,QAAO,oBAAoB;EACzB,QAAQ,eAAe,WAAW;EAClC,YAAY,eAAe,eAAe;EAC3C,CAAC;EACF,CACD,aAAa;CACZ,MAAM,iBAAiB,2BAA2B;AAClD,QAAO,oBAAoB;EACzB,QAAQ,eAAe,WAAW;EAClC,YAAY,eAAe,eAAe;EAC3C,CAAC;EACF;;AAGJ,MAAaC,oBACX,oBAAoB,CACjB,QAAQ,WAAoB;CAC3B,MAAM,iBAAiB,mBAAmB;AAC1C,QAAO,wBAAwB;EAC7B,QAAQ,eAAe,WAAW;EAClC,YAAY,eAAe,eAAe;EAC1C;EACD,CAAC;EACF,CACD,QAAQ,WAAoB;CAC3B,MAAM,iBAAiB,2BAA2B;AAClD,QAAO,wBAAwB;EAC7B,QAAQ,eAAe,WAAW;EAClC,YAAY,eAAe,eAAe;EAC1C;EACD,CAAC;EACF;;;;ACzEN,MAAa,eAITC;;AAGJ,MAAa,YAAYC;;AAGzB,MAAa,gBAAgBC;;AAG7B,MAAa,QAAQC;;AAGrB,MAAa,cAAcC;;AAG3B,MAAa,kBAAkBC"}
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["gtMiddleware","getLocale","getEnableI18n","getGT","getMessages","getTranslations","mainGtMiddleware","mainGetLocale","mainGetEnableI18n","mainGetGT","mainGetMessages","mainGetTranslations"],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/middleware/gtMiddleware.ts","../src/functions/runtime.ts","../src/server.ts"],"sourcesContent":["//#region src/settings/settings.ts\nconst libraryDefaultLocale = \"en\";\nconst defaultTimeout = 6e4;\n//#endregion\n//#region src/logging/diagnostics.ts\nfunction ensureSentence(text) {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return \"\";\n\treturn /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\nfunction stripSentence(text) {\n\tconst trimmed = text.trim();\n\tlet end = trimmed.length;\n\twhile (end > 0) {\n\t\tconst char = trimmed[end - 1];\n\t\tif (char !== \".\" && char !== \"!\" && char !== \"?\") break;\n\t\tend -= 1;\n\t}\n\treturn trimmed.slice(0, end);\n}\nfunction lowercaseFirstWord(text) {\n\treturn text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\nfunction formatDetails(details) {\n\tif (!details) return \"\";\n\tconst detailText = Array.isArray(details) ? details.join(\", \") : details;\n\tif (!detailText.trim()) return \"\";\n\treturn ensureSentence(`Details: ${detailText}`);\n}\nfunction formatDiagnosticErrorDetails(error) {\n\tif (error == null) return void 0;\n\treturn String(error);\n}\nfunction createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {\n\tconst prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : \"\";\n\tconst whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;\n\tconst shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n\tconst messageParts = [\n\t\twhatAndWhy,\n\t\treassurance,\n\t\tshouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,\n\t\tshouldCombineWayOut ? void 0 : wayOut,\n\t\tformatDetails(details)\n\t].filter((part) => !!part).map(ensureSentence);\n\tif (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);\n\tconst message = messageParts.join(\" \");\n\treturn prefix ? `${prefix} ${message}` : message;\n}\n//#endregion\n//#region src/settings/settingsUrls.ts\nconst defaultCacheUrl = \"https://cdn.gtx.dev\";\nconst defaultBaseUrl = \"https://api2.gtx.dev\";\nconst defaultRuntimeApiUrl = \"https://runtime2.gtx.dev\";\n//#endregion\n//#region src/translate/api.ts\nconst API_VERSION = \"2026-03-06.v1\";\n//#endregion\nexport { createDiagnosticMessage as a, libraryDefaultLocale as c, defaultRuntimeApiUrl as i, defaultBaseUrl as n, formatDiagnosticErrorDetails as o, defaultCacheUrl as r, defaultTimeout as s, API_VERSION as t };\n\n//# sourceMappingURL=api-BOEGbEF6.mjs.map","import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport type { AsyncLocalConditionStore } from './AsyncLocalConditionStore';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT server request state before initialization',\n why: 'initializeGT() has not initialized the TanStack Start server condition store',\n fix: \"Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs.\",\n});\n\nconst conditionStoreSingleton = createGlobalSingleton<AsyncLocalConditionStore>(\n {\n namespace: 'tanstackStart',\n key: 'conditionStore',\n source: 'gt-tanstack-start',\n notInitialized: () => conditionStoreNotInitializedError,\n }\n);\n\nexport const getConditionStore = conditionStoreSingleton.get;\nexport const setConditionStore = conditionStoreSingleton.set;\nexport const isConditionStoreInitialized =\n conditionStoreSingleton.isInitialized;\n","import {\n createMiddleware,\n type RequestMiddlewareAfterServer,\n} from '@tanstack/react-start';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/**\n * Establish request-scoped GT conditions for SSR, server routes, and server\n * functions.\n */\nexport const gtMiddleware: RequestMiddlewareAfterServer<\n {},\n undefined,\n undefined\n> = createMiddleware().server(({ request, pathname, next }) => {\n return getConditionStore().run(request, () => next(), pathname);\n});\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getReadonlyConditionStore } from '@generaltranslation/react-core/pure';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type {\n GTFunctionType,\n MFunctionType,\n Message,\n TFunctionType,\n} from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current request or browser. */\nexport const getLocale: () => string = createIsomorphicFn()\n .server((): string => getConditionStore().getLocale())\n .client((): string => getReadonlyConditionStore().getLocale());\n\n/** Return whether internationalization is enabled for the current runtime. */\nexport const getEnableI18n: () => boolean = createIsomorphicFn()\n .server((): boolean => getConditionStore().getEnableI18n())\n .client((): boolean => getReadonlyConditionStore().getEnableI18n());\n\n/** Return a string translation function for the current runtime. */\nexport const getGT: (messages?: Message[]) => Promise<GTFunctionType> =\n createIsomorphicFn()\n .server((messages?: Message[]) => {\n const conditionStore = getConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n })\n .client((messages?: Message[]) => {\n const conditionStore = getReadonlyConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n });\n\n/** Return a registered-message translation function for the current runtime. */\nexport const getMessages: () => Promise<MFunctionType> = createIsomorphicFn()\n .server(() => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n })\n .client(() => {\n const conditionStore = getReadonlyConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n });\n\n/** Return a dictionary translation function for the current runtime. */\nexport const getTranslations: (rootId?: string) => Promise<TFunctionType> =\n createIsomorphicFn()\n .server((rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n })\n .client((rootId?: string) => {\n const conditionStore = getReadonlyConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n });\n","import type { RequestMiddlewareAfterServer } from '@tanstack/react-start';\nimport { gtMiddleware as mainGtMiddleware } from './middleware/gtMiddleware';\nimport {\n getEnableI18n as mainGetEnableI18n,\n getGT as mainGetGT,\n getLocale as mainGetLocale,\n getMessages as mainGetMessages,\n getTranslations as mainGetTranslations,\n} from './functions/runtime';\n\n/** @deprecated Import `gtMiddleware` from `gt-tanstack-start` instead. */\nexport const gtMiddleware: RequestMiddlewareAfterServer<\n {},\n undefined,\n undefined\n> = mainGtMiddleware;\n\n/** @deprecated Import `getLocale` from `gt-tanstack-start` instead. */\nexport const getLocale = mainGetLocale;\n\n/** @deprecated Import `getEnableI18n` from `gt-tanstack-start` instead. */\nexport const getEnableI18n = mainGetEnableI18n;\n\n/** @deprecated Import `getGT` from `gt-tanstack-start` instead. */\nexport const getGT = mainGetGT;\n\n/** @deprecated Import `getMessages` from `gt-tanstack-start` instead. */\nexport const getMessages = mainGetMessages;\n\n/** @deprecated Import `getTranslations` from `gt-tanstack-start` instead. */\nexport const getTranslations = mainGetTranslations;\n"],"mappings":";;;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OAAO,SAAS,IAAK;AAClD,SAAO;;AAER,QAAO,QAAQ,MAAM,GAAG,IAAI;;AAE7B,SAAS,mBAAmB,MAAM;AACjC,QAAO,KAAK,QAAQ,gBAAgB,UAAU,MAAM,aAAa,CAAC;;AAEnE,SAAS,cAAc,SAAS;AAC/B,KAAI,CAAC,QAAS,QAAO;CACrB,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cC;;AAG3B,MAAa,kBAAkBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-tanstack-start",
|
|
3
|
-
"version": "11.0
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "TanStack Start integration for General Translation",
|
|
5
5
|
"main": "./dist/index.server.mjs",
|
|
6
6
|
"module": "./dist/index.server.mjs",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"@tanstack/react-start": ">=1.159.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"gt-react": "11.0
|
|
20
|
-
"@generaltranslation/react-core": "11.0
|
|
21
|
-
"gt-i18n": "1.0.
|
|
22
|
-
"generaltranslation": "9.0.
|
|
19
|
+
"gt-react": "11.1.0",
|
|
20
|
+
"@generaltranslation/react-core": "11.1.0",
|
|
21
|
+
"gt-i18n": "1.0.8",
|
|
22
|
+
"generaltranslation": "9.0.4"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|