gt-tanstack-start 11.0.11 → 11.0.13
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 +20 -0
- package/dist/index.client.d.mts +32 -0
- package/dist/index.client.d.mts.map +1 -0
- package/dist/index.client.mjs +205 -0
- package/dist/index.client.mjs.map +1 -0
- package/dist/index.server.d.mts +40 -0
- package/dist/index.server.d.mts.map +1 -0
- package/dist/index.server.mjs +234 -0
- package/dist/index.server.mjs.map +1 -0
- package/dist/server.d.mts +19 -0
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +138 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +29 -12
- package/dist/index.cjs +0 -260
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -10
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -9
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -55
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# gt-tanstack-start
|
|
2
2
|
|
|
3
|
+
## 11.0.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1971](https://github.com/generaltranslation/gt/pull/1971) [`f1eb7c4`](https://github.com/generaltranslation/gt/commit/f1eb7c42bebf0eb75e477c700a61ac060924bb30) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Initialize TanStack Start browser condition state from the locale cookie, expose translation helpers from the isomorphic package entry point, and deprecate `parseLocale()` in favor of `getLocale()`. Export the browser condition-store factory from `gt-react` for framework integrations.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`f1eb7c4`](https://github.com/generaltranslation/gt/commit/f1eb7c42bebf0eb75e477c700a61ac060924bb30)]:
|
|
10
|
+
- gt-react@11.0.13
|
|
11
|
+
- @generaltranslation/react-core@11.0.13
|
|
12
|
+
|
|
13
|
+
## 11.0.12
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#1941](https://github.com/generaltranslation/gt/pull/1941) [`7fef71d`](https://github.com/generaltranslation/gt/commit/7fef71de88a770bd5e14ec9f62cdac91671b3d2f) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add request-scoped server middleware and server-only translation helpers for TanStack Start.
|
|
18
|
+
|
|
19
|
+
- Updated dependencies []:
|
|
20
|
+
- @generaltranslation/react-core@11.0.12
|
|
21
|
+
- gt-react@11.0.12
|
|
22
|
+
|
|
3
23
|
## 11.0.11
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -0,0 +1,32 @@
|
|
|
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";
|
|
2
|
+
import { GTFunctionType, MFunctionType, Message, TFunctionType } from "gt-i18n/types";
|
|
3
|
+
|
|
4
|
+
//#region src/functions/parseLocale.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is
|
|
9
|
+
* retained as a fallback for server setups that have not initialized request
|
|
10
|
+
* scope through the middleware.
|
|
11
|
+
*/
|
|
12
|
+
declare function parseLocale(): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/functions/runtime.d.ts
|
|
15
|
+
/** Return the locale associated with the current request or browser. */
|
|
16
|
+
declare const getLocale: () => string;
|
|
17
|
+
/** Return whether internationalization is enabled for the current runtime. */
|
|
18
|
+
declare const getEnableI18n: () => boolean;
|
|
19
|
+
/** Return a string translation function for the current runtime. */
|
|
20
|
+
declare const getGT: (messages?: Message[]) => Promise<GTFunctionType>;
|
|
21
|
+
/** Return a registered-message translation function for the current runtime. */
|
|
22
|
+
declare const getMessages: () => Promise<MFunctionType>;
|
|
23
|
+
/** Return a dictionary translation function for the current runtime. */
|
|
24
|
+
declare const getTranslations: (rootId?: string) => Promise<TFunctionType>;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/setup/initializeGT.client.d.ts
|
|
27
|
+
type InitializeGTParams = Parameters<typeof initializeGT$1>[0];
|
|
28
|
+
/** Initialize GT and its browser condition store from the locale cookie. */
|
|
29
|
+
declare function initializeGT(config: InitializeGTParams): void;
|
|
30
|
+
//#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 };
|
|
32
|
+
//# sourceMappingURL=index.client.d.mts.map
|
|
@@ -0,0 +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;;;;cCPH,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;;;KC7DtD,kBAAA,GAAqB,UAAA,QAAkB,cAAA;;iBAG5B,YAAA,CAAa,MAAA,EAAQ,kBAAA"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { createIsomorphicFn } from "@tanstack/react-start";
|
|
2
|
+
import { getRequest, setCookie } from "@tanstack/react-start/server";
|
|
3
|
+
import { getI18nConfig, getReadonlyConditionStore } from "@generaltranslation/react-core/pure";
|
|
4
|
+
import { createGlobalSingleton, getCookieValue, getGTInternal, getMessagesInternal, getTranslationsInternal, parseAcceptLanguage } from "gt-i18n/internal";
|
|
5
|
+
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";
|
|
6
|
+
//#region ../core/dist/api-BOEGbEF6.mjs
|
|
7
|
+
function ensureSentence(text) {
|
|
8
|
+
const trimmed = text.trim();
|
|
9
|
+
if (!trimmed) return "";
|
|
10
|
+
return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
11
|
+
}
|
|
12
|
+
function stripSentence(text) {
|
|
13
|
+
const trimmed = text.trim();
|
|
14
|
+
let end = trimmed.length;
|
|
15
|
+
while (end > 0) {
|
|
16
|
+
const char = trimmed[end - 1];
|
|
17
|
+
if (char !== "." && char !== "!" && char !== "?") break;
|
|
18
|
+
end -= 1;
|
|
19
|
+
}
|
|
20
|
+
return trimmed.slice(0, end);
|
|
21
|
+
}
|
|
22
|
+
function lowercaseFirstWord(text) {
|
|
23
|
+
return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());
|
|
24
|
+
}
|
|
25
|
+
function formatDetails(details) {
|
|
26
|
+
if (!details) return "";
|
|
27
|
+
const detailText = Array.isArray(details) ? details.join(", ") : details;
|
|
28
|
+
if (!detailText.trim()) return "";
|
|
29
|
+
return ensureSentence(`Details: ${detailText}`);
|
|
30
|
+
}
|
|
31
|
+
function createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {
|
|
32
|
+
const prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : "";
|
|
33
|
+
const whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;
|
|
34
|
+
const shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));
|
|
35
|
+
const messageParts = [
|
|
36
|
+
whatAndWhy,
|
|
37
|
+
reassurance,
|
|
38
|
+
shouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,
|
|
39
|
+
shouldCombineWayOut ? void 0 : wayOut,
|
|
40
|
+
formatDetails(details)
|
|
41
|
+
].filter((part) => !!part).map(ensureSentence);
|
|
42
|
+
if (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);
|
|
43
|
+
const message = messageParts.join(" ");
|
|
44
|
+
return prefix ? `${prefix} ${message}` : message;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/condition-store/singleton.ts
|
|
48
|
+
const conditionStoreNotInitializedError = createDiagnosticMessage({
|
|
49
|
+
source: "gt-tanstack-start",
|
|
50
|
+
severity: "Error",
|
|
51
|
+
whatHappened: "Cannot read GT server request state before initialization",
|
|
52
|
+
why: "initializeGT() has not initialized the TanStack Start server condition store",
|
|
53
|
+
fix: "Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs."
|
|
54
|
+
});
|
|
55
|
+
const conditionStoreSingleton = createGlobalSingleton({
|
|
56
|
+
namespace: "tanstackStart",
|
|
57
|
+
key: "conditionStore",
|
|
58
|
+
source: "gt-tanstack-start",
|
|
59
|
+
notInitialized: () => conditionStoreNotInitializedError
|
|
60
|
+
});
|
|
61
|
+
const getConditionStore = conditionStoreSingleton.get;
|
|
62
|
+
conditionStoreSingleton.set;
|
|
63
|
+
const isConditionStoreInitialized = conditionStoreSingleton.isInitialized;
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/functions/requestConditions.ts
|
|
66
|
+
const localeCookieOptions = {
|
|
67
|
+
path: "/",
|
|
68
|
+
sameSite: "lax",
|
|
69
|
+
maxAge: 3600 * 24 * 365
|
|
70
|
+
};
|
|
71
|
+
const noLocaleCandidatesWarning = createDiagnosticMessage({
|
|
72
|
+
source: "gt-tanstack-start",
|
|
73
|
+
severity: "Warning",
|
|
74
|
+
whatHappened: "No locale preference was found for the current request",
|
|
75
|
+
reassurance: "GT will use the configured default locale",
|
|
76
|
+
why: "neither the locale cookie nor the Accept-Language header supplied a supported locale candidate"
|
|
77
|
+
});
|
|
78
|
+
function resolveRequestConditions(request, localeConfig) {
|
|
79
|
+
const i18nConfig = getI18nConfig();
|
|
80
|
+
const cookieHeader = request.headers.get("cookie");
|
|
81
|
+
const localeCandidates = [];
|
|
82
|
+
const cookieLocale = getCookieValue(cookieHeader, i18nConfig.getLocaleCookieName());
|
|
83
|
+
if (cookieLocale) localeCandidates.push(cookieLocale);
|
|
84
|
+
localeCandidates.push(...parseAcceptLanguage(request.headers.get("accept-language")));
|
|
85
|
+
if (localeCandidates.length === 0) console.warn(noLocaleCandidatesWarning);
|
|
86
|
+
const locale = i18nConfig.resolveSupportedLocale(localeCandidates, localeConfig ?? {
|
|
87
|
+
defaultLocale: i18nConfig.getDefaultLocale(),
|
|
88
|
+
locales: i18nConfig.getLocales(),
|
|
89
|
+
customMapping: i18nConfig.getCustomMapping()
|
|
90
|
+
});
|
|
91
|
+
setCookie(i18nConfig.getLocaleCookieName(), locale, localeCookieOptions);
|
|
92
|
+
const enableI18nCookie = getCookieValue(cookieHeader, i18nConfig.getEnableI18nCookieName());
|
|
93
|
+
return {
|
|
94
|
+
locale,
|
|
95
|
+
region: getCookieValue(cookieHeader, i18nConfig.getRegionCookieName()) || void 0,
|
|
96
|
+
enableI18n: enableI18nCookie === void 0 ? true : enableI18nCookie === "true"
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/functions/runtime.ts
|
|
101
|
+
/** Return the locale associated with the current request or browser. */
|
|
102
|
+
const getLocale = createIsomorphicFn().server(() => getConditionStore().getLocale()).client(() => getReadonlyConditionStore().getLocale());
|
|
103
|
+
/** Return whether internationalization is enabled for the current runtime. */
|
|
104
|
+
const getEnableI18n = createIsomorphicFn().server(() => getConditionStore().getEnableI18n()).client(() => getReadonlyConditionStore().getEnableI18n());
|
|
105
|
+
/** Return a string translation function for the current runtime. */
|
|
106
|
+
const getGT = createIsomorphicFn().server((messages) => {
|
|
107
|
+
const conditionStore = getConditionStore();
|
|
108
|
+
return getGTInternal({
|
|
109
|
+
locale: conditionStore.getLocale(),
|
|
110
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
111
|
+
}, messages);
|
|
112
|
+
}).client((messages) => {
|
|
113
|
+
const conditionStore = getReadonlyConditionStore();
|
|
114
|
+
return getGTInternal({
|
|
115
|
+
locale: conditionStore.getLocale(),
|
|
116
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
117
|
+
}, messages);
|
|
118
|
+
});
|
|
119
|
+
/** Return a registered-message translation function for the current runtime. */
|
|
120
|
+
const getMessages = createIsomorphicFn().server(() => {
|
|
121
|
+
const conditionStore = getConditionStore();
|
|
122
|
+
return getMessagesInternal({
|
|
123
|
+
locale: conditionStore.getLocale(),
|
|
124
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
125
|
+
});
|
|
126
|
+
}).client(() => {
|
|
127
|
+
const conditionStore = getReadonlyConditionStore();
|
|
128
|
+
return getMessagesInternal({
|
|
129
|
+
locale: conditionStore.getLocale(),
|
|
130
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
/** Return a dictionary translation function for the current runtime. */
|
|
134
|
+
const getTranslations = createIsomorphicFn().server((rootId) => {
|
|
135
|
+
const conditionStore = getConditionStore();
|
|
136
|
+
return getTranslationsInternal({
|
|
137
|
+
locale: conditionStore.getLocale(),
|
|
138
|
+
enableI18n: conditionStore.getEnableI18n(),
|
|
139
|
+
rootId
|
|
140
|
+
});
|
|
141
|
+
}).client((rootId) => {
|
|
142
|
+
const conditionStore = getReadonlyConditionStore();
|
|
143
|
+
return getTranslationsInternal({
|
|
144
|
+
locale: conditionStore.getLocale(),
|
|
145
|
+
enableI18n: conditionStore.getEnableI18n(),
|
|
146
|
+
rootId
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/functions/parseLocale.ts
|
|
151
|
+
const determineLocale = createIsomorphicFn().server(determineLocaleServer).client(() => getLocale());
|
|
152
|
+
/**
|
|
153
|
+
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
154
|
+
*
|
|
155
|
+
* @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is
|
|
156
|
+
* retained as a fallback for server setups that have not initialized request
|
|
157
|
+
* scope through the middleware.
|
|
158
|
+
*/
|
|
159
|
+
function parseLocale() {
|
|
160
|
+
const i18nConfig = getI18nConfig();
|
|
161
|
+
return determineLocale({
|
|
162
|
+
defaultLocale: i18nConfig.getDefaultLocale(),
|
|
163
|
+
locales: i18nConfig.getLocales(),
|
|
164
|
+
customMapping: i18nConfig.getCustomMapping()
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function determineLocaleServer({ defaultLocale, locales, customMapping }) {
|
|
168
|
+
if (isConditionStoreInitialized()) {
|
|
169
|
+
const conditionStore = getConditionStore();
|
|
170
|
+
if (conditionStore.hasActiveScope()) return conditionStore.getLocale();
|
|
171
|
+
}
|
|
172
|
+
return resolveRequestConditions(getRequest(), {
|
|
173
|
+
defaultLocale,
|
|
174
|
+
locales,
|
|
175
|
+
customMapping
|
|
176
|
+
}).locale;
|
|
177
|
+
}
|
|
178
|
+
/** Read the server-synchronized locale cookie during client initialization. */
|
|
179
|
+
function determineLocaleClient({ defaultLocale, locales, customMapping }) {
|
|
180
|
+
const i18nConfig = getI18nConfig();
|
|
181
|
+
const localeCookieName = i18nConfig.getLocaleCookieName();
|
|
182
|
+
const candidates = [];
|
|
183
|
+
const cookie = getCookieValue(document.cookie, localeCookieName);
|
|
184
|
+
if (cookie) candidates.push(cookie);
|
|
185
|
+
if (candidates.length === 0) console.warn("gt-tanstack-start(client): no locales could be determined for this request");
|
|
186
|
+
return i18nConfig.resolveSupportedLocale(candidates, {
|
|
187
|
+
defaultLocale,
|
|
188
|
+
locales,
|
|
189
|
+
customMapping
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/setup/initializeGT.client.ts
|
|
194
|
+
/** Initialize GT and its browser condition store from the locale cookie. */
|
|
195
|
+
function initializeGT(config) {
|
|
196
|
+
initializeGT$1(config);
|
|
197
|
+
createOrUpdateBrowserConditionStore({
|
|
198
|
+
...config,
|
|
199
|
+
locale: determineLocaleClient(config)
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
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 };
|
|
204
|
+
|
|
205
|
+
//# sourceMappingURL=index.client.mjs.map
|
|
@@ -0,0 +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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BAAkB;EAC5C,SAAS,WAAW,YAAY;EAChC,eAAe,WAAW,kBAAkB;EAC7C,CAAC;;AAGJ,SAAS,sBAAsB,EAC7B,eACA,SACA,iBACuB;AACvB,KAAI,6BAA6B,EAAE;EACjC,MAAM,iBAAiB,mBAAmB;AAC1C,MAAI,eAAe,gBAAgB,CACjC,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;AAC7D,gBAAkB,OAAO;AACzB,qCAAoC;EAClC,GAAG;EACH,QAAQ,sBAAsB,OAAO;EACtC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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";
|
|
3
|
+
import { GTFunctionType, MFunctionType, Message, TFunctionType } from "gt-i18n/types";
|
|
4
|
+
|
|
5
|
+
//#region src/functions/parseLocale.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
8
|
+
*
|
|
9
|
+
* @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is
|
|
10
|
+
* retained as a fallback for server setups that have not initialized request
|
|
11
|
+
* scope through the middleware.
|
|
12
|
+
*/
|
|
13
|
+
declare function parseLocale(): string;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/functions/runtime.d.ts
|
|
16
|
+
/** Return the locale associated with the current request or browser. */
|
|
17
|
+
declare const getLocale: () => string;
|
|
18
|
+
/** Return whether internationalization is enabled for the current runtime. */
|
|
19
|
+
declare const getEnableI18n: () => boolean;
|
|
20
|
+
/** Return a string translation function for the current runtime. */
|
|
21
|
+
declare const getGT: (messages?: Message[]) => Promise<GTFunctionType>;
|
|
22
|
+
/** Return a registered-message translation function for the current runtime. */
|
|
23
|
+
declare const getMessages: () => Promise<MFunctionType>;
|
|
24
|
+
/** Return a dictionary translation function for the current runtime. */
|
|
25
|
+
declare const getTranslations: (rootId?: string) => Promise<TFunctionType>;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/middleware/gtMiddleware.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* Establish request-scoped GT conditions for SSR, server routes, and server
|
|
30
|
+
* functions.
|
|
31
|
+
*/
|
|
32
|
+
declare const gtMiddleware: RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/setup/initializeGT.server.d.ts
|
|
35
|
+
type InitializeGTParams = Parameters<typeof initializeGT$1>[0];
|
|
36
|
+
/** Initialize GT and its server request condition store. */
|
|
37
|
+
declare function initializeGT(config: InitializeGTParams): void;
|
|
38
|
+
//#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 };
|
|
40
|
+
//# sourceMappingURL=index.server.d.mts.map
|
|
@@ -0,0 +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;;;;cCPH,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;;;;;;;cCzD9C,YAAA,EAAc,4BAAA;;;KCNtB,kBAAA,GAAqB,UAAA,QAAkB,cAAA;;iBAG5B,YAAA,CAAa,MAAA,EAAQ,kBAAA"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { createIsomorphicFn, createMiddleware } from "@tanstack/react-start";
|
|
2
|
+
import { getRequest, setCookie } from "@tanstack/react-start/server";
|
|
3
|
+
import { getI18nConfig, getReadonlyConditionStore } from "@generaltranslation/react-core/pure";
|
|
4
|
+
import { createGlobalSingleton, getCookieValue, getGTInternal, getMessagesInternal, getTranslationsInternal, parseAcceptLanguage } from "gt-i18n/internal";
|
|
5
|
+
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";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
//#region ../core/dist/api-BOEGbEF6.mjs
|
|
8
|
+
function ensureSentence(text) {
|
|
9
|
+
const trimmed = text.trim();
|
|
10
|
+
if (!trimmed) return "";
|
|
11
|
+
return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
12
|
+
}
|
|
13
|
+
function stripSentence(text) {
|
|
14
|
+
const trimmed = text.trim();
|
|
15
|
+
let end = trimmed.length;
|
|
16
|
+
while (end > 0) {
|
|
17
|
+
const char = trimmed[end - 1];
|
|
18
|
+
if (char !== "." && char !== "!" && char !== "?") break;
|
|
19
|
+
end -= 1;
|
|
20
|
+
}
|
|
21
|
+
return trimmed.slice(0, end);
|
|
22
|
+
}
|
|
23
|
+
function lowercaseFirstWord(text) {
|
|
24
|
+
return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());
|
|
25
|
+
}
|
|
26
|
+
function formatDetails(details) {
|
|
27
|
+
if (!details) return "";
|
|
28
|
+
const detailText = Array.isArray(details) ? details.join(", ") : details;
|
|
29
|
+
if (!detailText.trim()) return "";
|
|
30
|
+
return ensureSentence(`Details: ${detailText}`);
|
|
31
|
+
}
|
|
32
|
+
function createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {
|
|
33
|
+
const prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : "";
|
|
34
|
+
const whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;
|
|
35
|
+
const shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));
|
|
36
|
+
const messageParts = [
|
|
37
|
+
whatAndWhy,
|
|
38
|
+
reassurance,
|
|
39
|
+
shouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,
|
|
40
|
+
shouldCombineWayOut ? void 0 : wayOut,
|
|
41
|
+
formatDetails(details)
|
|
42
|
+
].filter((part) => !!part).map(ensureSentence);
|
|
43
|
+
if (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);
|
|
44
|
+
const message = messageParts.join(" ");
|
|
45
|
+
return prefix ? `${prefix} ${message}` : message;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/condition-store/singleton.ts
|
|
49
|
+
const conditionStoreNotInitializedError = createDiagnosticMessage({
|
|
50
|
+
source: "gt-tanstack-start",
|
|
51
|
+
severity: "Error",
|
|
52
|
+
whatHappened: "Cannot read GT server request state before initialization",
|
|
53
|
+
why: "initializeGT() has not initialized the TanStack Start server condition store",
|
|
54
|
+
fix: "Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs."
|
|
55
|
+
});
|
|
56
|
+
const conditionStoreSingleton = createGlobalSingleton({
|
|
57
|
+
namespace: "tanstackStart",
|
|
58
|
+
key: "conditionStore",
|
|
59
|
+
source: "gt-tanstack-start",
|
|
60
|
+
notInitialized: () => conditionStoreNotInitializedError
|
|
61
|
+
});
|
|
62
|
+
const getConditionStore = conditionStoreSingleton.get;
|
|
63
|
+
const setConditionStore = conditionStoreSingleton.set;
|
|
64
|
+
const isConditionStoreInitialized = conditionStoreSingleton.isInitialized;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/functions/requestConditions.ts
|
|
67
|
+
const localeCookieOptions = {
|
|
68
|
+
path: "/",
|
|
69
|
+
sameSite: "lax",
|
|
70
|
+
maxAge: 3600 * 24 * 365
|
|
71
|
+
};
|
|
72
|
+
const noLocaleCandidatesWarning = createDiagnosticMessage({
|
|
73
|
+
source: "gt-tanstack-start",
|
|
74
|
+
severity: "Warning",
|
|
75
|
+
whatHappened: "No locale preference was found for the current request",
|
|
76
|
+
reassurance: "GT will use the configured default locale",
|
|
77
|
+
why: "neither the locale cookie nor the Accept-Language header supplied a supported locale candidate"
|
|
78
|
+
});
|
|
79
|
+
function resolveRequestConditions(request, localeConfig) {
|
|
80
|
+
const i18nConfig = getI18nConfig();
|
|
81
|
+
const cookieHeader = request.headers.get("cookie");
|
|
82
|
+
const localeCandidates = [];
|
|
83
|
+
const cookieLocale = getCookieValue(cookieHeader, i18nConfig.getLocaleCookieName());
|
|
84
|
+
if (cookieLocale) localeCandidates.push(cookieLocale);
|
|
85
|
+
localeCandidates.push(...parseAcceptLanguage(request.headers.get("accept-language")));
|
|
86
|
+
if (localeCandidates.length === 0) console.warn(noLocaleCandidatesWarning);
|
|
87
|
+
const locale = i18nConfig.resolveSupportedLocale(localeCandidates, localeConfig ?? {
|
|
88
|
+
defaultLocale: i18nConfig.getDefaultLocale(),
|
|
89
|
+
locales: i18nConfig.getLocales(),
|
|
90
|
+
customMapping: i18nConfig.getCustomMapping()
|
|
91
|
+
});
|
|
92
|
+
setCookie(i18nConfig.getLocaleCookieName(), locale, localeCookieOptions);
|
|
93
|
+
const enableI18nCookie = getCookieValue(cookieHeader, i18nConfig.getEnableI18nCookieName());
|
|
94
|
+
return {
|
|
95
|
+
locale,
|
|
96
|
+
region: getCookieValue(cookieHeader, i18nConfig.getRegionCookieName()) || void 0,
|
|
97
|
+
enableI18n: enableI18nCookie === void 0 ? true : enableI18nCookie === "true"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/functions/runtime.ts
|
|
102
|
+
/** Return the locale associated with the current request or browser. */
|
|
103
|
+
const getLocale = createIsomorphicFn().server(() => getConditionStore().getLocale()).client(() => getReadonlyConditionStore().getLocale());
|
|
104
|
+
/** Return whether internationalization is enabled for the current runtime. */
|
|
105
|
+
const getEnableI18n = createIsomorphicFn().server(() => getConditionStore().getEnableI18n()).client(() => getReadonlyConditionStore().getEnableI18n());
|
|
106
|
+
/** Return a string translation function for the current runtime. */
|
|
107
|
+
const getGT = createIsomorphicFn().server((messages) => {
|
|
108
|
+
const conditionStore = getConditionStore();
|
|
109
|
+
return getGTInternal({
|
|
110
|
+
locale: conditionStore.getLocale(),
|
|
111
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
112
|
+
}, messages);
|
|
113
|
+
}).client((messages) => {
|
|
114
|
+
const conditionStore = getReadonlyConditionStore();
|
|
115
|
+
return getGTInternal({
|
|
116
|
+
locale: conditionStore.getLocale(),
|
|
117
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
118
|
+
}, messages);
|
|
119
|
+
});
|
|
120
|
+
/** Return a registered-message translation function for the current runtime. */
|
|
121
|
+
const getMessages = createIsomorphicFn().server(() => {
|
|
122
|
+
const conditionStore = getConditionStore();
|
|
123
|
+
return getMessagesInternal({
|
|
124
|
+
locale: conditionStore.getLocale(),
|
|
125
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
126
|
+
});
|
|
127
|
+
}).client(() => {
|
|
128
|
+
const conditionStore = getReadonlyConditionStore();
|
|
129
|
+
return getMessagesInternal({
|
|
130
|
+
locale: conditionStore.getLocale(),
|
|
131
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
/** Return a dictionary translation function for the current runtime. */
|
|
135
|
+
const getTranslations = createIsomorphicFn().server((rootId) => {
|
|
136
|
+
const conditionStore = getConditionStore();
|
|
137
|
+
return getTranslationsInternal({
|
|
138
|
+
locale: conditionStore.getLocale(),
|
|
139
|
+
enableI18n: conditionStore.getEnableI18n(),
|
|
140
|
+
rootId
|
|
141
|
+
});
|
|
142
|
+
}).client((rootId) => {
|
|
143
|
+
const conditionStore = getReadonlyConditionStore();
|
|
144
|
+
return getTranslationsInternal({
|
|
145
|
+
locale: conditionStore.getLocale(),
|
|
146
|
+
enableI18n: conditionStore.getEnableI18n(),
|
|
147
|
+
rootId
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/functions/parseLocale.ts
|
|
152
|
+
const determineLocale = createIsomorphicFn().server(determineLocaleServer).client(() => getLocale());
|
|
153
|
+
/**
|
|
154
|
+
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
155
|
+
*
|
|
156
|
+
* @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is
|
|
157
|
+
* retained as a fallback for server setups that have not initialized request
|
|
158
|
+
* scope through the middleware.
|
|
159
|
+
*/
|
|
160
|
+
function parseLocale() {
|
|
161
|
+
const i18nConfig = getI18nConfig();
|
|
162
|
+
return determineLocale({
|
|
163
|
+
defaultLocale: i18nConfig.getDefaultLocale(),
|
|
164
|
+
locales: i18nConfig.getLocales(),
|
|
165
|
+
customMapping: i18nConfig.getCustomMapping()
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function determineLocaleServer({ defaultLocale, locales, customMapping }) {
|
|
169
|
+
if (isConditionStoreInitialized()) {
|
|
170
|
+
const conditionStore = getConditionStore();
|
|
171
|
+
if (conditionStore.hasActiveScope()) return conditionStore.getLocale();
|
|
172
|
+
}
|
|
173
|
+
return resolveRequestConditions(getRequest(), {
|
|
174
|
+
defaultLocale,
|
|
175
|
+
locales,
|
|
176
|
+
customMapping
|
|
177
|
+
}).locale;
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/middleware/gtMiddleware.ts
|
|
181
|
+
/**
|
|
182
|
+
* Establish request-scoped GT conditions for SSR, server routes, and server
|
|
183
|
+
* functions.
|
|
184
|
+
*/
|
|
185
|
+
const gtMiddleware = createMiddleware().server(({ request, next }) => {
|
|
186
|
+
return getConditionStore().run(request, () => next());
|
|
187
|
+
});
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/condition-store/AsyncLocalConditionStore.ts
|
|
190
|
+
const missingRequestScopeError = createDiagnosticMessage({
|
|
191
|
+
source: "gt-tanstack-start",
|
|
192
|
+
severity: "Error",
|
|
193
|
+
whatHappened: "Cannot read GT request state outside a request scope",
|
|
194
|
+
why: "the gt-tanstack-start request middleware has not initialized the ConditionStore for this request",
|
|
195
|
+
fix: "Register gtMiddleware from 'gt-tanstack-start' as global TanStack Start request middleware."
|
|
196
|
+
});
|
|
197
|
+
/**
|
|
198
|
+
* Read-only ConditionStore backed by request-scoped AsyncLocalStorage.
|
|
199
|
+
*/
|
|
200
|
+
var AsyncLocalConditionStore = class {
|
|
201
|
+
constructor(config) {
|
|
202
|
+
this.config = config;
|
|
203
|
+
this.storage = new AsyncLocalStorage();
|
|
204
|
+
this.getLocale = () => this.getConditions().locale;
|
|
205
|
+
this.getRegion = () => this.getConditions().region;
|
|
206
|
+
this.getEnableI18n = () => this.getConditions().enableI18n;
|
|
207
|
+
this.setLocale = (_locale) => {};
|
|
208
|
+
this.setRegion = (_region) => {};
|
|
209
|
+
this.setEnableI18n = (_enableI18n) => {};
|
|
210
|
+
}
|
|
211
|
+
run(request, callback) {
|
|
212
|
+
const conditions = resolveRequestConditions(request, this.config);
|
|
213
|
+
return this.storage.run(conditions, callback);
|
|
214
|
+
}
|
|
215
|
+
hasActiveScope() {
|
|
216
|
+
return this.storage.getStore() !== void 0;
|
|
217
|
+
}
|
|
218
|
+
getConditions() {
|
|
219
|
+
const conditions = this.storage.getStore();
|
|
220
|
+
if (!conditions) throw new Error(missingRequestScopeError);
|
|
221
|
+
return conditions;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/setup/initializeGT.server.ts
|
|
226
|
+
/** Initialize GT and its server request condition store. */
|
|
227
|
+
function initializeGT(config) {
|
|
228
|
+
initializeGT$1(config);
|
|
229
|
+
setConditionStore(new AsyncLocalConditionStore(config));
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
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 };
|
|
233
|
+
|
|
234
|
+
//# sourceMappingURL=index.server.mjs.map
|
|
@@ -0,0 +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,aAAa,CAAC,WAAW,mBAAmB,cAAc,IAAI,CAAC,KAAK;CAC9G,MAAM,sBAAsB,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,SAAS,KAAK,cAAc,OAAO,CAAC;CACrF,MAA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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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RequestMiddlewareAfterServer } from "@tanstack/react-start";
|
|
2
|
+
import * as _$gt_i18n_types0 from "gt-i18n/types";
|
|
3
|
+
|
|
4
|
+
//#region src/server.d.ts
|
|
5
|
+
/** @deprecated Import `gtMiddleware` from `gt-tanstack-start` instead. */
|
|
6
|
+
declare const gtMiddleware: RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
7
|
+
/** @deprecated Import `getLocale` from `gt-tanstack-start` instead. */
|
|
8
|
+
declare const getLocale: () => string;
|
|
9
|
+
/** @deprecated Import `getEnableI18n` from `gt-tanstack-start` instead. */
|
|
10
|
+
declare const getEnableI18n: () => boolean;
|
|
11
|
+
/** @deprecated Import `getGT` from `gt-tanstack-start` instead. */
|
|
12
|
+
declare const getGT: (messages?: _$gt_i18n_types0.Message[]) => Promise<_$gt_i18n_types0.GTFunctionType>;
|
|
13
|
+
/** @deprecated Import `getMessages` from `gt-tanstack-start` instead. */
|
|
14
|
+
declare const getMessages: () => Promise<_$gt_i18n_types0.MFunctionType>;
|
|
15
|
+
/** @deprecated Import `getTranslations` from `gt-tanstack-start` instead. */
|
|
16
|
+
declare const getTranslations: (rootId?: string) => Promise<_$gt_i18n_types0.TFunctionType>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { getEnableI18n, getGT, getLocale, getMessages, getTranslations, gtMiddleware };
|
|
19
|
+
//# sourceMappingURL=server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";;;;;cAWa,YAAA,EAAc,4BAAA;;cAOd,SAAA;;cAGA,aAAA;;cAGA,KAAA,GAAK,QAAA,GAAY,gBAAA,CAAZ,OAAA,OAAA,OAAA,CAAA,gBAAA,CAAA,cAAA;AANlB;AAAA,cASa,WAAA,QAAW,OAAA,CAAkB,gBAAA,CAAlB,aAAA;;cAGX,eAAA,GAAe,MAAA,cAAA,OAAA,CAAsB,gBAAA,CAAtB,aAAA"}
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { createIsomorphicFn, createMiddleware } from "@tanstack/react-start";
|
|
2
|
+
import { createGlobalSingleton, getGTInternal, getMessagesInternal, getTranslationsInternal } from "gt-i18n/internal";
|
|
3
|
+
import { getReadonlyConditionStore } from "@generaltranslation/react-core/pure";
|
|
4
|
+
//#region ../core/dist/api-BOEGbEF6.mjs
|
|
5
|
+
function ensureSentence(text) {
|
|
6
|
+
const trimmed = text.trim();
|
|
7
|
+
if (!trimmed) return "";
|
|
8
|
+
return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
9
|
+
}
|
|
10
|
+
function stripSentence(text) {
|
|
11
|
+
const trimmed = text.trim();
|
|
12
|
+
let end = trimmed.length;
|
|
13
|
+
while (end > 0) {
|
|
14
|
+
const char = trimmed[end - 1];
|
|
15
|
+
if (char !== "." && char !== "!" && char !== "?") break;
|
|
16
|
+
end -= 1;
|
|
17
|
+
}
|
|
18
|
+
return trimmed.slice(0, end);
|
|
19
|
+
}
|
|
20
|
+
function lowercaseFirstWord(text) {
|
|
21
|
+
return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());
|
|
22
|
+
}
|
|
23
|
+
function formatDetails(details) {
|
|
24
|
+
if (!details) return "";
|
|
25
|
+
const detailText = Array.isArray(details) ? details.join(", ") : details;
|
|
26
|
+
if (!detailText.trim()) return "";
|
|
27
|
+
return ensureSentence(`Details: ${detailText}`);
|
|
28
|
+
}
|
|
29
|
+
function createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {
|
|
30
|
+
const prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : "";
|
|
31
|
+
const whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;
|
|
32
|
+
const shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));
|
|
33
|
+
const messageParts = [
|
|
34
|
+
whatAndWhy,
|
|
35
|
+
reassurance,
|
|
36
|
+
shouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,
|
|
37
|
+
shouldCombineWayOut ? void 0 : wayOut,
|
|
38
|
+
formatDetails(details)
|
|
39
|
+
].filter((part) => !!part).map(ensureSentence);
|
|
40
|
+
if (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);
|
|
41
|
+
const message = messageParts.join(" ");
|
|
42
|
+
return prefix ? `${prefix} ${message}` : message;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/condition-store/singleton.ts
|
|
46
|
+
const conditionStoreNotInitializedError = createDiagnosticMessage({
|
|
47
|
+
source: "gt-tanstack-start",
|
|
48
|
+
severity: "Error",
|
|
49
|
+
whatHappened: "Cannot read GT server request state before initialization",
|
|
50
|
+
why: "initializeGT() has not initialized the TanStack Start server condition store",
|
|
51
|
+
fix: "Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs."
|
|
52
|
+
});
|
|
53
|
+
const conditionStoreSingleton = createGlobalSingleton({
|
|
54
|
+
namespace: "tanstackStart",
|
|
55
|
+
key: "conditionStore",
|
|
56
|
+
source: "gt-tanstack-start",
|
|
57
|
+
notInitialized: () => conditionStoreNotInitializedError
|
|
58
|
+
});
|
|
59
|
+
const getConditionStore = conditionStoreSingleton.get;
|
|
60
|
+
conditionStoreSingleton.set;
|
|
61
|
+
conditionStoreSingleton.isInitialized;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/middleware/gtMiddleware.ts
|
|
64
|
+
/**
|
|
65
|
+
* Establish request-scoped GT conditions for SSR, server routes, and server
|
|
66
|
+
* functions.
|
|
67
|
+
*/
|
|
68
|
+
const gtMiddleware$1 = createMiddleware().server(({ request, next }) => {
|
|
69
|
+
return getConditionStore().run(request, () => next());
|
|
70
|
+
});
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/functions/runtime.ts
|
|
73
|
+
/** Return the locale associated with the current request or browser. */
|
|
74
|
+
const getLocale$1 = createIsomorphicFn().server(() => getConditionStore().getLocale()).client(() => getReadonlyConditionStore().getLocale());
|
|
75
|
+
/** Return whether internationalization is enabled for the current runtime. */
|
|
76
|
+
const getEnableI18n$1 = createIsomorphicFn().server(() => getConditionStore().getEnableI18n()).client(() => getReadonlyConditionStore().getEnableI18n());
|
|
77
|
+
/** Return a string translation function for the current runtime. */
|
|
78
|
+
const getGT$1 = createIsomorphicFn().server((messages) => {
|
|
79
|
+
const conditionStore = getConditionStore();
|
|
80
|
+
return getGTInternal({
|
|
81
|
+
locale: conditionStore.getLocale(),
|
|
82
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
83
|
+
}, messages);
|
|
84
|
+
}).client((messages) => {
|
|
85
|
+
const conditionStore = getReadonlyConditionStore();
|
|
86
|
+
return getGTInternal({
|
|
87
|
+
locale: conditionStore.getLocale(),
|
|
88
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
89
|
+
}, messages);
|
|
90
|
+
});
|
|
91
|
+
/** Return a registered-message translation function for the current runtime. */
|
|
92
|
+
const getMessages$1 = createIsomorphicFn().server(() => {
|
|
93
|
+
const conditionStore = getConditionStore();
|
|
94
|
+
return getMessagesInternal({
|
|
95
|
+
locale: conditionStore.getLocale(),
|
|
96
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
97
|
+
});
|
|
98
|
+
}).client(() => {
|
|
99
|
+
const conditionStore = getReadonlyConditionStore();
|
|
100
|
+
return getMessagesInternal({
|
|
101
|
+
locale: conditionStore.getLocale(),
|
|
102
|
+
enableI18n: conditionStore.getEnableI18n()
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
/** Return a dictionary translation function for the current runtime. */
|
|
106
|
+
const getTranslations$1 = createIsomorphicFn().server((rootId) => {
|
|
107
|
+
const conditionStore = getConditionStore();
|
|
108
|
+
return getTranslationsInternal({
|
|
109
|
+
locale: conditionStore.getLocale(),
|
|
110
|
+
enableI18n: conditionStore.getEnableI18n(),
|
|
111
|
+
rootId
|
|
112
|
+
});
|
|
113
|
+
}).client((rootId) => {
|
|
114
|
+
const conditionStore = getReadonlyConditionStore();
|
|
115
|
+
return getTranslationsInternal({
|
|
116
|
+
locale: conditionStore.getLocale(),
|
|
117
|
+
enableI18n: conditionStore.getEnableI18n(),
|
|
118
|
+
rootId
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/server.ts
|
|
123
|
+
/** @deprecated Import `gtMiddleware` from `gt-tanstack-start` instead. */
|
|
124
|
+
const gtMiddleware = gtMiddleware$1;
|
|
125
|
+
/** @deprecated Import `getLocale` from `gt-tanstack-start` instead. */
|
|
126
|
+
const getLocale = getLocale$1;
|
|
127
|
+
/** @deprecated Import `getEnableI18n` from `gt-tanstack-start` instead. */
|
|
128
|
+
const getEnableI18n = getEnableI18n$1;
|
|
129
|
+
/** @deprecated Import `getGT` from `gt-tanstack-start` instead. */
|
|
130
|
+
const getGT = getGT$1;
|
|
131
|
+
/** @deprecated Import `getMessages` from `gt-tanstack-start` instead. */
|
|
132
|
+
const getMessages = getMessages$1;
|
|
133
|
+
/** @deprecated Import `getTranslations` from `gt-tanstack-start` instead. */
|
|
134
|
+
const getTranslations = getTranslations$1;
|
|
135
|
+
//#endregion
|
|
136
|
+
export { getEnableI18n, getGT, getLocale, getMessages, getTranslations, gtMiddleware };
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +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,SA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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"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-tanstack-start",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.13",
|
|
4
4
|
"description": "TanStack Start integration for General Translation",
|
|
5
|
-
"main": "./dist/index.
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "./dist/index.d.
|
|
5
|
+
"main": "./dist/index.server.mjs",
|
|
6
|
+
"module": "./dist/index.server.mjs",
|
|
7
|
+
"types": "./dist/index.server.d.mts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"CHANGELOG.md"
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"@tanstack/react-start": ">=1.159.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"gt-react": "11.0.
|
|
19
|
+
"gt-react": "11.0.13",
|
|
20
|
+
"@generaltranslation/react-core": "11.0.13",
|
|
20
21
|
"gt-i18n": "1.0.7",
|
|
21
|
-
"@generaltranslation/react-core": "11.0.11",
|
|
22
22
|
"generaltranslation": "9.0.3"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
@@ -41,15 +41,32 @@
|
|
|
41
41
|
},
|
|
42
42
|
"exports": {
|
|
43
43
|
".": {
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
44
|
+
"browser": {
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/index.client.d.mts",
|
|
47
|
+
"default": "./dist/index.client.mjs"
|
|
48
|
+
},
|
|
49
|
+
"default": "./dist/index.client.mjs"
|
|
47
50
|
},
|
|
48
51
|
"import": {
|
|
49
|
-
"types": "./dist/index.d.mts",
|
|
50
|
-
"default": "./dist/index.mjs"
|
|
52
|
+
"types": "./dist/index.server.d.mts",
|
|
53
|
+
"default": "./dist/index.server.mjs"
|
|
51
54
|
},
|
|
52
|
-
"default": "./dist/index.mjs"
|
|
55
|
+
"default": "./dist/index.server.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./server": {
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./dist/server.d.mts",
|
|
60
|
+
"default": "./dist/server.mjs"
|
|
61
|
+
},
|
|
62
|
+
"default": "./dist/server.mjs"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"typesVersions": {
|
|
66
|
+
"*": {
|
|
67
|
+
"server": [
|
|
68
|
+
"./dist/server.d.mts"
|
|
69
|
+
]
|
|
53
70
|
}
|
|
54
71
|
},
|
|
55
72
|
"keywords": [
|
package/dist/index.cjs
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
let _tanstack_react_start = require("@tanstack/react-start");
|
|
3
|
-
let _tanstack_react_start_server = require("@tanstack/react-start/server");
|
|
4
|
-
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
5
|
-
let gt_i18n_internal = require("gt-i18n/internal");
|
|
6
|
-
let gt_react = require("gt-react");
|
|
7
|
-
//#region src/functions/parseLocale.ts
|
|
8
|
-
const determineLocale = (0, _tanstack_react_start.createIsomorphicFn)().server(determineLocaleServer).client(determineLocaleClient);
|
|
9
|
-
/**
|
|
10
|
-
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
11
|
-
*/
|
|
12
|
-
function parseLocale() {
|
|
13
|
-
const i18nConfig = (0, _generaltranslation_react_core_pure.getI18nConfig)();
|
|
14
|
-
return determineLocale({
|
|
15
|
-
defaultLocale: i18nConfig.getDefaultLocale(),
|
|
16
|
-
locales: i18nConfig.getLocales(),
|
|
17
|
-
customMapping: i18nConfig.getCustomMapping()
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function determineLocaleServer({ defaultLocale, locales, customMapping }) {
|
|
21
|
-
const i18nConfig = (0, _generaltranslation_react_core_pure.getI18nConfig)();
|
|
22
|
-
const localeCookieName = i18nConfig.getLocaleCookieName();
|
|
23
|
-
const candidates = [];
|
|
24
|
-
const cookie = (0, _tanstack_react_start_server.getCookie)(localeCookieName);
|
|
25
|
-
if (cookie) candidates.push(cookie);
|
|
26
|
-
candidates.push(...(0, gt_i18n_internal.parseAcceptLanguage)((0, _tanstack_react_start_server.getRequestHeader)("accept-language")));
|
|
27
|
-
if (candidates.length === 0) console.warn("gt-tanstack-start(server): no locales could be determined for this request");
|
|
28
|
-
const locale = i18nConfig.resolveSupportedLocale(candidates, {
|
|
29
|
-
defaultLocale,
|
|
30
|
-
locales,
|
|
31
|
-
customMapping
|
|
32
|
-
});
|
|
33
|
-
(0, _tanstack_react_start_server.setCookie)(localeCookieName, locale, {
|
|
34
|
-
path: "/",
|
|
35
|
-
sameSite: "lax",
|
|
36
|
-
maxAge: 3600 * 24 * 365
|
|
37
|
-
});
|
|
38
|
-
return locale;
|
|
39
|
-
}
|
|
40
|
-
function determineLocaleClient({ defaultLocale, locales, customMapping }) {
|
|
41
|
-
const i18nConfig = (0, _generaltranslation_react_core_pure.getI18nConfig)();
|
|
42
|
-
const localeCookieName = i18nConfig.getLocaleCookieName();
|
|
43
|
-
const candidates = [];
|
|
44
|
-
const cookie = (0, gt_i18n_internal.getCookieValue)(document.cookie, localeCookieName);
|
|
45
|
-
if (cookie) candidates.push(cookie);
|
|
46
|
-
if (candidates.length === 0) console.warn("gt-tanstack-start(client): no locales could be determined for this request");
|
|
47
|
-
return i18nConfig.resolveSupportedLocale(candidates, {
|
|
48
|
-
defaultLocale,
|
|
49
|
-
locales,
|
|
50
|
-
customMapping
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
Object.defineProperty(exports, "Branch", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function() {
|
|
57
|
-
return gt_react.Branch;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, "Currency", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function() {
|
|
63
|
-
return gt_react.Currency;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(exports, "DateTime", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function() {
|
|
69
|
-
return gt_react.DateTime;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(exports, "Derive", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function() {
|
|
75
|
-
return gt_react.Derive;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(exports, "GTProvider", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function() {
|
|
81
|
-
return gt_react.GTProvider;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(exports, "LocaleSelector", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function() {
|
|
87
|
-
return gt_react.LocaleSelector;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(exports, "Num", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function() {
|
|
93
|
-
return gt_react.Num;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(exports, "Plural", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function() {
|
|
99
|
-
return gt_react.Plural;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(exports, "RelativeTime", {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
get: function() {
|
|
105
|
-
return gt_react.RelativeTime;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
Object.defineProperty(exports, "T", {
|
|
109
|
-
enumerable: true,
|
|
110
|
-
get: function() {
|
|
111
|
-
return gt_react.T;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
Object.defineProperty(exports, "Var", {
|
|
115
|
-
enumerable: true,
|
|
116
|
-
get: function() {
|
|
117
|
-
return gt_react.Var;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
Object.defineProperty(exports, "declareVar", {
|
|
121
|
-
enumerable: true,
|
|
122
|
-
get: function() {
|
|
123
|
-
return gt_react.declareVar;
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
Object.defineProperty(exports, "decodeMsg", {
|
|
127
|
-
enumerable: true,
|
|
128
|
-
get: function() {
|
|
129
|
-
return gt_react.decodeMsg;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
Object.defineProperty(exports, "decodeOptions", {
|
|
133
|
-
enumerable: true,
|
|
134
|
-
get: function() {
|
|
135
|
-
return gt_react.decodeOptions;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
Object.defineProperty(exports, "decodeVars", {
|
|
139
|
-
enumerable: true,
|
|
140
|
-
get: function() {
|
|
141
|
-
return gt_react.decodeVars;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
Object.defineProperty(exports, "derive", {
|
|
145
|
-
enumerable: true,
|
|
146
|
-
get: function() {
|
|
147
|
-
return gt_react.derive;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
Object.defineProperty(exports, "getTranslationsSnapshot", {
|
|
151
|
-
enumerable: true,
|
|
152
|
-
get: function() {
|
|
153
|
-
return gt_react.getTranslationsSnapshot;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
Object.defineProperty(exports, "gtFallback", {
|
|
157
|
-
enumerable: true,
|
|
158
|
-
get: function() {
|
|
159
|
-
return gt_react.gtFallback;
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(exports, "initializeGT", {
|
|
163
|
-
enumerable: true,
|
|
164
|
-
get: function() {
|
|
165
|
-
return gt_react.initializeGT;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
Object.defineProperty(exports, "mFallback", {
|
|
169
|
-
enumerable: true,
|
|
170
|
-
get: function() {
|
|
171
|
-
return gt_react.mFallback;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
Object.defineProperty(exports, "msg", {
|
|
175
|
-
enumerable: true,
|
|
176
|
-
get: function() {
|
|
177
|
-
return gt_react.msg;
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
exports.parseLocale = parseLocale;
|
|
181
|
-
Object.defineProperty(exports, "t", {
|
|
182
|
-
enumerable: true,
|
|
183
|
-
get: function() {
|
|
184
|
-
return gt_react.t;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
Object.defineProperty(exports, "useCustomMapping", {
|
|
188
|
-
enumerable: true,
|
|
189
|
-
get: function() {
|
|
190
|
-
return gt_react.useCustomMapping;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
Object.defineProperty(exports, "useDefaultLocale", {
|
|
194
|
-
enumerable: true,
|
|
195
|
-
get: function() {
|
|
196
|
-
return gt_react.useDefaultLocale;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
Object.defineProperty(exports, "useEnableI18n", {
|
|
200
|
-
enumerable: true,
|
|
201
|
-
get: function() {
|
|
202
|
-
return gt_react.useEnableI18n;
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
Object.defineProperty(exports, "useFormatLocales", {
|
|
206
|
-
enumerable: true,
|
|
207
|
-
get: function() {
|
|
208
|
-
return gt_react.useFormatLocales;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
Object.defineProperty(exports, "useGT", {
|
|
212
|
-
enumerable: true,
|
|
213
|
-
get: function() {
|
|
214
|
-
return gt_react.useGT;
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
Object.defineProperty(exports, "useLocale", {
|
|
218
|
-
enumerable: true,
|
|
219
|
-
get: function() {
|
|
220
|
-
return gt_react.useLocale;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
Object.defineProperty(exports, "useLocaleSelector", {
|
|
224
|
-
enumerable: true,
|
|
225
|
-
get: function() {
|
|
226
|
-
return gt_react.useLocaleSelector;
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
Object.defineProperty(exports, "useLocales", {
|
|
230
|
-
enumerable: true,
|
|
231
|
-
get: function() {
|
|
232
|
-
return gt_react.useLocales;
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
Object.defineProperty(exports, "useMessages", {
|
|
236
|
-
enumerable: true,
|
|
237
|
-
get: function() {
|
|
238
|
-
return gt_react.useMessages;
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
Object.defineProperty(exports, "useSetEnableI18n", {
|
|
242
|
-
enumerable: true,
|
|
243
|
-
get: function() {
|
|
244
|
-
return gt_react.useSetEnableI18n;
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
Object.defineProperty(exports, "useSetLocale", {
|
|
248
|
-
enumerable: true,
|
|
249
|
-
get: function() {
|
|
250
|
-
return gt_react.useSetLocale;
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
Object.defineProperty(exports, "useTranslations", {
|
|
254
|
-
enumerable: true,
|
|
255
|
-
get: function() {
|
|
256
|
-
return gt_react.useTranslations;
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/functions/parseLocale.ts"],"sourcesContent":["import { createIsomorphicFn } from '@tanstack/react-start';\nimport {\n getRequestHeader,\n getCookie,\n setCookie,\n} from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getCookieValue, parseAcceptLanguage } from 'gt-i18n/internal';\nimport type { LocaleResolverConfig } from 'gt-i18n/internal/types';\n\nexport const determineLocale = createIsomorphicFn()\n .server(determineLocaleServer)\n .client(determineLocaleClient);\n\n/**\n * Resolve the user's locale for the current TanStack Start request or browser.\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 const i18nConfig = getI18nConfig();\n const localeCookieName = i18nConfig.getLocaleCookieName();\n const candidates: string[] = [];\n\n const cookie = getCookie(localeCookieName);\n if (cookie) candidates.push(cookie);\n\n candidates.push(...parseAcceptLanguage(getRequestHeader('accept-language')));\n\n if (candidates.length === 0) {\n console.warn(\n 'gt-tanstack-start(server): no locales could be determined for this request'\n );\n }\n\n const locale = i18nConfig.resolveSupportedLocale(candidates, {\n defaultLocale,\n locales,\n customMapping,\n });\n\n setCookie(localeCookieName, locale, {\n path: '/',\n sameSite: 'lax',\n maxAge: 60 * 60 * 24 * 365,\n });\n\n return locale;\n}\n\nfunction determineLocaleClient({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig) {\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"],"mappings":";;;;;;;AAUA,MAAa,mBAAA,GAAA,sBAAA,qBAAsC,CAChD,OAAO,sBAAsB,CAC7B,OAAO,sBAAsB;;;;AAKhC,SAAgB,cAAsB;CACpC,MAAM,cAAA,GAAA,oCAAA,gBAA4B;AAClC,QAAO,gBAAgB;EACrB,eAAe,WAAW,kBAAkB;EAC5C,SAAS,WAAW,YAAY;EAChC,eAAe,WAAW,kBAAkB;EAC7C,CAAC;;AAGJ,SAAS,sBAAsB,EAC7B,eACA,SACA,iBACuB;CACvB,MAAM,cAAA,GAAA,oCAAA,gBAA4B;CAClC,MAAM,mBAAmB,WAAW,qBAAqB;CACzD,MAAM,aAAuB,EAAE;CAE/B,MAAM,UAAA,GAAA,6BAAA,WAAmB,iBAAiB;AAC1C,KAAI,OAAQ,YAAW,KAAK,OAAO;AAEnC,YAAW,KAAK,IAAA,GAAA,iBAAA,sBAAA,GAAA,6BAAA,kBAAwC,kBAAkB,CAAC,CAAC;AAE5E,KAAI,WAAW,WAAW,EACxB,SAAQ,KACN,6EACD;CAGH,MAAM,SAAS,WAAW,uBAAuB,YAAY;EAC3D;EACA;EACA;EACD,CAAC;AAEF,EAAA,GAAA,6BAAA,WAAU,kBAAkB,QAAQ;EAClC,MAAM;EACN,UAAU;EACV,QAAQ,OAAU,KAAK;EACxB,CAAC;AAEF,QAAO;;AAGT,SAAS,sBAAsB,EAC7B,eACA,SACA,iBACuB;CACvB,MAAM,cAAA,GAAA,oCAAA,gBAA4B;CAClC,MAAM,mBAAmB,WAAW,qBAAqB;CACzD,MAAM,aAAuB,EAAE;CAE/B,MAAM,UAAA,GAAA,iBAAA,gBAAwB,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"}
|
package/dist/index.d.cts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations } from "gt-react";
|
|
2
|
-
|
|
3
|
-
//#region src/functions/parseLocale.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
6
|
-
*/
|
|
7
|
-
declare function parseLocale(): string;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, parseLocale, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations };
|
|
10
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/functions/parseLocale.ts"],"mappings":";;;;;;iBAiBgB,WAAA,CAAA"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations } from "gt-react";
|
|
2
|
-
//#region src/functions/parseLocale.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
5
|
-
*/
|
|
6
|
-
declare function parseLocale(): string;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, parseLocale, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations };
|
|
9
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/functions/parseLocale.ts"],"mappings":";;;;;iBAiBgB,WAAA,CAAA"}
|
package/dist/index.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createIsomorphicFn } from "@tanstack/react-start";
|
|
2
|
-
import { getCookie, getRequestHeader, setCookie } from "@tanstack/react-start/server";
|
|
3
|
-
import { getI18nConfig } from "@generaltranslation/react-core/pure";
|
|
4
|
-
import { getCookieValue, parseAcceptLanguage } from "gt-i18n/internal";
|
|
5
|
-
import { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations } from "gt-react";
|
|
6
|
-
//#region src/functions/parseLocale.ts
|
|
7
|
-
const determineLocale = createIsomorphicFn().server(determineLocaleServer).client(determineLocaleClient);
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the user's locale for the current TanStack Start request or browser.
|
|
10
|
-
*/
|
|
11
|
-
function parseLocale() {
|
|
12
|
-
const i18nConfig = getI18nConfig();
|
|
13
|
-
return determineLocale({
|
|
14
|
-
defaultLocale: i18nConfig.getDefaultLocale(),
|
|
15
|
-
locales: i18nConfig.getLocales(),
|
|
16
|
-
customMapping: i18nConfig.getCustomMapping()
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function determineLocaleServer({ defaultLocale, locales, customMapping }) {
|
|
20
|
-
const i18nConfig = getI18nConfig();
|
|
21
|
-
const localeCookieName = i18nConfig.getLocaleCookieName();
|
|
22
|
-
const candidates = [];
|
|
23
|
-
const cookie = getCookie(localeCookieName);
|
|
24
|
-
if (cookie) candidates.push(cookie);
|
|
25
|
-
candidates.push(...parseAcceptLanguage(getRequestHeader("accept-language")));
|
|
26
|
-
if (candidates.length === 0) console.warn("gt-tanstack-start(server): no locales could be determined for this request");
|
|
27
|
-
const locale = i18nConfig.resolveSupportedLocale(candidates, {
|
|
28
|
-
defaultLocale,
|
|
29
|
-
locales,
|
|
30
|
-
customMapping
|
|
31
|
-
});
|
|
32
|
-
setCookie(localeCookieName, locale, {
|
|
33
|
-
path: "/",
|
|
34
|
-
sameSite: "lax",
|
|
35
|
-
maxAge: 3600 * 24 * 365
|
|
36
|
-
});
|
|
37
|
-
return locale;
|
|
38
|
-
}
|
|
39
|
-
function determineLocaleClient({ defaultLocale, locales, customMapping }) {
|
|
40
|
-
const i18nConfig = getI18nConfig();
|
|
41
|
-
const localeCookieName = i18nConfig.getLocaleCookieName();
|
|
42
|
-
const candidates = [];
|
|
43
|
-
const cookie = getCookieValue(document.cookie, localeCookieName);
|
|
44
|
-
if (cookie) candidates.push(cookie);
|
|
45
|
-
if (candidates.length === 0) console.warn("gt-tanstack-start(client): no locales could be determined for this request");
|
|
46
|
-
return i18nConfig.resolveSupportedLocale(candidates, {
|
|
47
|
-
defaultLocale,
|
|
48
|
-
locales,
|
|
49
|
-
customMapping
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { Branch, Currency, DateTime, Derive, GTProvider, LocaleSelector, Num, Plural, RelativeTime, T, Var, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, parseLocale, t, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useLocale, useLocaleSelector, useLocales, useMessages, useSetEnableI18n, useSetLocale, useTranslations };
|
|
54
|
-
|
|
55
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/functions/parseLocale.ts"],"sourcesContent":["import { createIsomorphicFn } from '@tanstack/react-start';\nimport {\n getRequestHeader,\n getCookie,\n setCookie,\n} from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getCookieValue, parseAcceptLanguage } from 'gt-i18n/internal';\nimport type { LocaleResolverConfig } from 'gt-i18n/internal/types';\n\nexport const determineLocale = createIsomorphicFn()\n .server(determineLocaleServer)\n .client(determineLocaleClient);\n\n/**\n * Resolve the user's locale for the current TanStack Start request or browser.\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 const i18nConfig = getI18nConfig();\n const localeCookieName = i18nConfig.getLocaleCookieName();\n const candidates: string[] = [];\n\n const cookie = getCookie(localeCookieName);\n if (cookie) candidates.push(cookie);\n\n candidates.push(...parseAcceptLanguage(getRequestHeader('accept-language')));\n\n if (candidates.length === 0) {\n console.warn(\n 'gt-tanstack-start(server): no locales could be determined for this request'\n );\n }\n\n const locale = i18nConfig.resolveSupportedLocale(candidates, {\n defaultLocale,\n locales,\n customMapping,\n });\n\n setCookie(localeCookieName, locale, {\n path: '/',\n sameSite: 'lax',\n maxAge: 60 * 60 * 24 * 365,\n });\n\n return locale;\n}\n\nfunction determineLocaleClient({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig) {\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"],"mappings":";;;;;;AAUA,MAAa,kBAAkB,oBAAoB,CAChD,OAAO,sBAAsB,CAC7B,OAAO,sBAAsB;;;;AAKhC,SAAgB,cAAsB;CACpC,MAAM,aAAa,eAAe;AAClC,QAAO,gBAAgB;EACrB,eAAe,WAAW,kBAAkB;EAC5C,SAAS,WAAW,YAAY;EAChC,eAAe,WAAW,kBAAkB;EAC7C,CAAC;;AAGJ,SAAS,sBAAsB,EAC7B,eACA,SACA,iBACuB;CACvB,MAAM,aAAa,eAAe;CAClC,MAAM,mBAAmB,WAAW,qBAAqB;CACzD,MAAM,aAAuB,EAAE;CAE/B,MAAM,SAAS,UAAU,iBAAiB;AAC1C,KAAI,OAAQ,YAAW,KAAK,OAAO;AAEnC,YAAW,KAAK,GAAG,oBAAoB,iBAAiB,kBAAkB,CAAC,CAAC;AAE5E,KAAI,WAAW,WAAW,EACxB,SAAQ,KACN,6EACD;CAGH,MAAM,SAAS,WAAW,uBAAuB,YAAY;EAC3D;EACA;EACA;EACD,CAAC;AAEF,WAAU,kBAAkB,QAAQ;EAClC,MAAM;EACN,UAAU;EACV,QAAQ,OAAU,KAAK;EACxB,CAAC;AAEF,QAAO;;AAGT,SAAS,sBAAsB,EAC7B,eACA,SACA,iBACuB;CACvB,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"}
|