gt-tanstack-start 11.0.12 → 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 CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## 11.0.12
4
14
 
5
15
  ### Patch Changes
@@ -1,9 +1,32 @@
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";
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
+
2
4
  //#region src/functions/parseLocale.d.ts
3
5
  /**
4
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.
5
11
  */
6
12
  declare function parseLocale(): string;
7
13
  //#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 };
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 };
9
32
  //# sourceMappingURL=index.client.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.client.d.mts","names":[],"sources":["../src/functions/parseLocale.ts"],"mappings":";;;;;iBAkBgB,WAAA,CAAA"}
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"}
@@ -1,8 +1,8 @@
1
1
  import { createIsomorphicFn } from "@tanstack/react-start";
2
2
  import { getRequest, setCookie } from "@tanstack/react-start/server";
3
- import { getI18nConfig } from "@generaltranslation/react-core/pure";
4
- import { createGlobalSingleton, 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";
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
6
  //#region ../core/dist/api-BOEGbEF6.mjs
7
7
  function ensureSentence(text) {
8
8
  const trimmed = text.trim();
@@ -97,10 +97,64 @@ function resolveRequestConditions(request, localeConfig) {
97
97
  };
98
98
  }
99
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
100
150
  //#region src/functions/parseLocale.ts
101
- const determineLocale = createIsomorphicFn().server(determineLocaleServer).client(determineLocaleClient);
151
+ const determineLocale = createIsomorphicFn().server(determineLocaleServer).client(() => getLocale());
102
152
  /**
103
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.
104
158
  */
105
159
  function parseLocale() {
106
160
  const i18nConfig = getI18nConfig();
@@ -121,6 +175,7 @@ function determineLocaleServer({ defaultLocale, locales, customMapping }) {
121
175
  customMapping
122
176
  }).locale;
123
177
  }
178
+ /** Read the server-synchronized locale cookie during client initialization. */
124
179
  function determineLocaleClient({ defaultLocale, locales, customMapping }) {
125
180
  const i18nConfig = getI18nConfig();
126
181
  const localeCookieName = i18nConfig.getLocaleCookieName();
@@ -135,6 +190,16 @@ function determineLocaleClient({ defaultLocale, locales, customMapping }) {
135
190
  });
136
191
  }
137
192
  //#endregion
138
- 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 };
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 };
139
204
 
140
205
  //# sourceMappingURL=index.client.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.client.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/requestConditions.ts","../src/functions/parseLocale.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 { 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';\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 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\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":";;;;;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A,IAAY,OAAO,qBAAqB;EAChE;;;;ACvDH,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;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;;AAGL,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"}
1
+ {"version":3,"file":"index.client.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/requestConditions.ts","../src/functions/runtime.ts","../src/functions/parseLocale.ts","../src/setup/initializeGT.client.ts"],"sourcesContent":["//#region src/settings/settings.ts\nconst libraryDefaultLocale = \"en\";\nconst defaultTimeout = 6e4;\n//#endregion\n//#region src/logging/diagnostics.ts\nfunction ensureSentence(text) {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return \"\";\n\treturn /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\nfunction stripSentence(text) {\n\tconst trimmed = text.trim();\n\tlet end = trimmed.length;\n\twhile (end > 0) {\n\t\tconst char = trimmed[end - 1];\n\t\tif (char !== \".\" && char !== \"!\" && char !== \"?\") break;\n\t\tend -= 1;\n\t}\n\treturn trimmed.slice(0, end);\n}\nfunction lowercaseFirstWord(text) {\n\treturn text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\nfunction formatDetails(details) {\n\tif (!details) return \"\";\n\tconst detailText = Array.isArray(details) ? details.join(\", \") : details;\n\tif (!detailText.trim()) return \"\";\n\treturn ensureSentence(`Details: ${detailText}`);\n}\nfunction formatDiagnosticErrorDetails(error) {\n\tif (error == null) return void 0;\n\treturn String(error);\n}\nfunction createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {\n\tconst prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : \"\";\n\tconst whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;\n\tconst shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n\tconst messageParts = [\n\t\twhatAndWhy,\n\t\treassurance,\n\t\tshouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,\n\t\tshouldCombineWayOut ? void 0 : wayOut,\n\t\tformatDetails(details)\n\t].filter((part) => !!part).map(ensureSentence);\n\tif (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);\n\tconst message = messageParts.join(\" \");\n\treturn prefix ? `${prefix} ${message}` : message;\n}\n//#endregion\n//#region src/settings/settingsUrls.ts\nconst defaultCacheUrl = \"https://cdn.gtx.dev\";\nconst defaultBaseUrl = \"https://api2.gtx.dev\";\nconst defaultRuntimeApiUrl = \"https://runtime2.gtx.dev\";\n//#endregion\n//#region src/translate/api.ts\nconst API_VERSION = \"2026-03-06.v1\";\n//#endregion\nexport { createDiagnosticMessage as a, libraryDefaultLocale as c, defaultRuntimeApiUrl as i, defaultBaseUrl as n, formatDiagnosticErrorDetails as o, defaultCacheUrl as r, defaultTimeout as s, API_VERSION as t };\n\n//# sourceMappingURL=api-BOEGbEF6.mjs.map","import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport type { AsyncLocalConditionStore } from './AsyncLocalConditionStore';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Error',\n whatHappened: 'Cannot read GT server request state before initialization',\n why: 'initializeGT() has not initialized the TanStack Start server condition store',\n fix: \"Call initializeGT() from 'gt-tanstack-start' during application setup before using gtMiddleware or server APIs.\",\n});\n\nconst conditionStoreSingleton = createGlobalSingleton<AsyncLocalConditionStore>(\n {\n namespace: 'tanstackStart',\n key: 'conditionStore',\n source: 'gt-tanstack-start',\n notInitialized: () => conditionStoreNotInitializedError,\n }\n);\n\nexport const getConditionStore = conditionStoreSingleton.get;\nexport const setConditionStore = conditionStoreSingleton.set;\nexport const isConditionStoreInitialized =\n conditionStoreSingleton.isInitialized;\n","import { setCookie } from '@tanstack/react-start/server';\nimport {\n getI18nConfig,\n type I18nConfigParams,\n} from '@generaltranslation/react-core/pure';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getCookieValue, parseAcceptLanguage } from 'gt-i18n/internal';\nimport type { RequestConditions } from '../condition-store/AsyncLocalConditionStore';\n\nexport const localeCookieOptions = {\n path: '/',\n sameSite: 'lax' as const,\n maxAge: 60 * 60 * 24 * 365,\n};\n\nconst noLocaleCandidatesWarning = createDiagnosticMessage({\n source: 'gt-tanstack-start',\n severity: 'Warning',\n whatHappened: 'No locale preference was found for the current request',\n reassurance: 'GT will use the configured default locale',\n why: 'neither the locale cookie nor the Accept-Language header supplied a supported locale candidate',\n});\n\nexport function resolveRequestConditions(\n request: Request,\n localeConfig?: I18nConfigParams\n): RequestConditions {\n const i18nConfig = getI18nConfig();\n const cookieHeader = request.headers.get('cookie');\n const localeCandidates: string[] = [];\n const cookieLocale = getCookieValue(\n cookieHeader,\n i18nConfig.getLocaleCookieName()\n );\n if (cookieLocale) localeCandidates.push(cookieLocale);\n localeCandidates.push(\n ...parseAcceptLanguage(request.headers.get('accept-language'))\n );\n\n if (localeCandidates.length === 0) {\n console.warn(noLocaleCandidatesWarning);\n }\n\n const locale = i18nConfig.resolveSupportedLocale(\n localeCandidates,\n localeConfig ?? {\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n }\n );\n\n setCookie(i18nConfig.getLocaleCookieName(), locale, localeCookieOptions);\n\n const enableI18nCookie = getCookieValue(\n cookieHeader,\n i18nConfig.getEnableI18nCookieName()\n );\n\n return {\n locale,\n region:\n getCookieValue(cookieHeader, i18nConfig.getRegionCookieName()) ||\n undefined,\n enableI18n:\n enableI18nCookie === undefined ? true : enableI18nCookie === 'true',\n };\n}\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getReadonlyConditionStore } from '@generaltranslation/react-core/pure';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type {\n GTFunctionType,\n MFunctionType,\n Message,\n TFunctionType,\n} from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current request or browser. */\nexport const getLocale: () => string = createIsomorphicFn()\n .server((): string => getConditionStore().getLocale())\n .client((): string => getReadonlyConditionStore().getLocale());\n\n/** Return whether internationalization is enabled for the current runtime. */\nexport const getEnableI18n: () => boolean = createIsomorphicFn()\n .server((): boolean => getConditionStore().getEnableI18n())\n .client((): boolean => getReadonlyConditionStore().getEnableI18n());\n\n/** Return a string translation function for the current runtime. */\nexport const getGT: (messages?: Message[]) => Promise<GTFunctionType> =\n createIsomorphicFn()\n .server((messages?: Message[]) => {\n const conditionStore = getConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n })\n .client((messages?: Message[]) => {\n const conditionStore = getReadonlyConditionStore();\n return getGTInternal(\n {\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n },\n messages\n );\n });\n\n/** Return a registered-message translation function for the current runtime. */\nexport const getMessages: () => Promise<MFunctionType> = createIsomorphicFn()\n .server(() => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n })\n .client(() => {\n const conditionStore = getReadonlyConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n });\n\n/** Return a dictionary translation function for the current runtime. */\nexport const getTranslations: (rootId?: string) => Promise<TFunctionType> =\n createIsomorphicFn()\n .server((rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n })\n .client((rootId?: string) => {\n const conditionStore = getReadonlyConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n });\n","import { createIsomorphicFn } from '@tanstack/react-start';\nimport { getRequest } from '@tanstack/react-start/server';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getCookieValue } from 'gt-i18n/internal';\nimport type { LocaleResolverConfig } from 'gt-i18n/internal/types';\nimport {\n getConditionStore,\n isConditionStoreInitialized,\n} from '../condition-store/singleton';\nimport { resolveRequestConditions } from './requestConditions';\nimport { getLocale } from './runtime';\n\nexport const determineLocale = createIsomorphicFn()\n .server(determineLocaleServer)\n .client(() => getLocale());\n\n/**\n * Resolve the user's locale for the current TanStack Start request or browser.\n *\n * @deprecated Use `getLocale()` with `gtMiddleware` instead. This function is\n * retained as a fallback for server setups that have not initialized request\n * scope through the middleware.\n */\nexport function parseLocale(): string {\n const i18nConfig = getI18nConfig();\n return determineLocale({\n defaultLocale: i18nConfig.getDefaultLocale(),\n locales: i18nConfig.getLocales(),\n customMapping: i18nConfig.getCustomMapping(),\n });\n}\n\nfunction determineLocaleServer({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig) {\n if (isConditionStoreInitialized()) {\n const conditionStore = getConditionStore();\n if (conditionStore.hasActiveScope()) {\n return conditionStore.getLocale();\n }\n }\n\n return resolveRequestConditions(getRequest(), {\n defaultLocale,\n locales,\n customMapping,\n }).locale;\n}\n\n/** Read the server-synchronized locale cookie during client initialization. */\nexport function determineLocaleClient({\n defaultLocale,\n locales,\n customMapping,\n}: LocaleResolverConfig): string {\n const i18nConfig = getI18nConfig();\n const localeCookieName = i18nConfig.getLocaleCookieName();\n const candidates: string[] = [];\n\n const cookie = getCookieValue(document.cookie, localeCookieName);\n if (cookie) candidates.push(cookie);\n\n if (candidates.length === 0) {\n console.warn(\n 'gt-tanstack-start(client): no locales could be determined for this request'\n );\n }\n\n return i18nConfig.resolveSupportedLocale(candidates, {\n defaultLocale,\n locales,\n customMapping,\n });\n}\n","import {\n createOrUpdateBrowserConditionStore,\n initializeGT as initializeReactGT,\n} from 'gt-react';\nimport { determineLocaleClient } from '../functions/parseLocale';\n\ntype InitializeGTParams = Parameters<typeof initializeReactGT>[0];\n\n/** Initialize GT and its browser condition store from the locale cookie. */\nexport function initializeGT(config: InitializeGTParams): void {\n initializeReactGT(config);\n createOrUpdateBrowserConditionStore({\n ...config,\n locale: determineLocaleClient(config),\n });\n}\n"],"mappings":";;;;;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OA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e,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"}
@@ -1,14 +1,40 @@
1
+ import { RequestMiddlewareAfterServer } from "@tanstack/react-start";
1
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
+
2
5
  //#region src/functions/parseLocale.d.ts
3
6
  /**
4
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.
5
12
  */
6
13
  declare function parseLocale(): string;
7
14
  //#endregion
8
- //#region src/setup/initializeGT.d.ts
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
9
35
  type InitializeGTParams = Parameters<typeof initializeGT$1>[0];
10
36
  /** Initialize GT and its server request condition store. */
11
37
  declare function initializeGT(config: InitializeGTParams): void;
12
38
  //#endregion
13
- 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 };
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 };
14
40
  //# sourceMappingURL=index.server.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.server.d.mts","names":[],"sources":["../src/functions/parseLocale.ts","../src/setup/initializeGT.ts"],"mappings":";;;;;iBAkBgB,WAAA,CAAA;;;KCdX,kBAAA,GAAqB,UAAA,QAAkB,cAAA;;iBAG5B,YAAA,CAAa,MAAA,EAAQ,kBAAA"}
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"}
@@ -1,7 +1,7 @@
1
- import { createIsomorphicFn } from "@tanstack/react-start";
1
+ import { createIsomorphicFn, createMiddleware } from "@tanstack/react-start";
2
2
  import { getRequest, setCookie } from "@tanstack/react-start/server";
3
- import { getI18nConfig } from "@generaltranslation/react-core/pure";
4
- import { createGlobalSingleton, getCookieValue, parseAcceptLanguage } from "gt-i18n/internal";
3
+ import { getI18nConfig, getReadonlyConditionStore } from "@generaltranslation/react-core/pure";
4
+ import { createGlobalSingleton, getCookieValue, getGTInternal, getMessagesInternal, getTranslationsInternal, parseAcceptLanguage } from "gt-i18n/internal";
5
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
6
  import { AsyncLocalStorage } from "node:async_hooks";
7
7
  //#region ../core/dist/api-BOEGbEF6.mjs
@@ -98,10 +98,64 @@ function resolveRequestConditions(request, localeConfig) {
98
98
  };
99
99
  }
100
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
101
151
  //#region src/functions/parseLocale.ts
102
- const determineLocale = createIsomorphicFn().server(determineLocaleServer).client(determineLocaleClient);
152
+ const determineLocale = createIsomorphicFn().server(determineLocaleServer).client(() => getLocale());
103
153
  /**
104
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.
105
159
  */
106
160
  function parseLocale() {
107
161
  const i18nConfig = getI18nConfig();
@@ -122,19 +176,15 @@ function determineLocaleServer({ defaultLocale, locales, customMapping }) {
122
176
  customMapping
123
177
  }).locale;
124
178
  }
125
- function determineLocaleClient({ defaultLocale, locales, customMapping }) {
126
- const i18nConfig = getI18nConfig();
127
- const localeCookieName = i18nConfig.getLocaleCookieName();
128
- const candidates = [];
129
- const cookie = getCookieValue(document.cookie, localeCookieName);
130
- if (cookie) candidates.push(cookie);
131
- if (candidates.length === 0) console.warn("gt-tanstack-start(client): no locales could be determined for this request");
132
- return i18nConfig.resolveSupportedLocale(candidates, {
133
- defaultLocale,
134
- locales,
135
- customMapping
136
- });
137
- }
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
+ });
138
188
  //#endregion
139
189
  //#region src/condition-store/AsyncLocalConditionStore.ts
140
190
  const missingRequestScopeError = createDiagnosticMessage({
@@ -142,7 +192,7 @@ const missingRequestScopeError = createDiagnosticMessage({
142
192
  severity: "Error",
143
193
  whatHappened: "Cannot read GT request state outside a request scope",
144
194
  why: "the gt-tanstack-start request middleware has not initialized the ConditionStore for this request",
145
- fix: "Register gtMiddleware from 'gt-tanstack-start/server' as global TanStack Start request middleware."
195
+ fix: "Register gtMiddleware from 'gt-tanstack-start' as global TanStack Start request middleware."
146
196
  });
147
197
  /**
148
198
  * Read-only ConditionStore backed by request-scoped AsyncLocalStorage.
@@ -172,13 +222,13 @@ var AsyncLocalConditionStore = class {
172
222
  }
173
223
  };
174
224
  //#endregion
175
- //#region src/setup/initializeGT.ts
225
+ //#region src/setup/initializeGT.server.ts
176
226
  /** Initialize GT and its server request condition store. */
177
227
  function initializeGT(config) {
178
228
  initializeGT$1(config);
179
229
  setConditionStore(new AsyncLocalConditionStore(config));
180
230
  }
181
231
  //#endregion
182
- 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 };
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 };
183
233
 
184
234
  //# sourceMappingURL=index.server.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.server.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/requestConditions.ts","../src/functions/parseLocale.ts","../src/condition-store/AsyncLocalConditionStore.ts","../src/setup/initializeGT.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 { 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';\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 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\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","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/server' 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,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,YAAW,KAAK,OAAO;AAEnC,KAAI,WAAW,WAAW,EACxB,SAAQ,KACN,6EACD;AAGH,QAAO,WAAW,uBAAuB,YAAY;EACnD;EACA;EACA;EACD,CAAC;;;;ACxDJ,MAAM,2BAA2B,wBAAwB;CACvD,QAAQ;CACR,UAAU;CACV,cAAc;CACd,KAAK;CACL,KAAK;CACN,CAAC;;;;AAKF,IAAa,2BAAb,MAAiF;CAG/E,YAAY,QAA2C;AAA1B,OAAA,SAAA;iBAFF,IAAI,mBAAsC;yBAa3C,KAAK,eAAe,CAAC;yBAET,KAAK,eAAe,CAAC;6BAE5B,KAAK,eAAe,CAAC;oBAEvC,YAA0B;oBAE1B,YAAsC;wBAElC,gBAA+B;;CAnBhD,IAAO,SAAkB,UAAsB;EAC7C,MAAM,aAAa,yBAAyB,SAAS,KAAK,OAAO;AACjE,SAAO,KAAK,QAAQ,IAAI,YAAY,SAAS;;CAG/C,iBAA0B;AACxB,SAAO,KAAK,QAAQ,UAAU,KAAK,KAAA;;CAerC,gBAA2C;EACzC,MAAM,aAAa,KAAK,QAAQ,UAAU;AAC1C,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,yBAAyB;AAC1D,SAAO;;;;;;AC7CX,SAAgB,aAAa,QAAkC;AAC7D,gBAAkB,OAAO;AACzB,mBAAkB,IAAI,yBAAyB,OAAO,CAAC"}
1
+ {"version":3,"file":"index.server.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/functions/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,O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MAAM,iBAAiB,mBAAmB;AAC1C,MAAI,eAAe,gBAAgB,CACjC,QAAO,eAAe,WAAW;;AAIrC,QAAO,yBAAyB,YAAY,EAAE;EAC5C;EACA;EACA;EACD,CAAC,CAAC;;;;;;;;ACtCL,MAAa,eAIT,kBAAkB,CAAC,QAAQ,EAAE,SAAS,WAAW;AACnD,QAAO,mBAAmB,CAAC,IAAI,eAAe,MAAM,CAAC;EACrD;;;ACJF,MAAM,2BAA2B,wBAAwB;CACvD,QAAQ;CACR,UAAU;CACV,cAAc;CACd,KAAK;CACL,KAAK;CACN,CAAC;;;;AAKF,IAAa,2BAAb,MAAiF;CAG/E,YAAY,QAA2C;AAA1B,OAAA,SAAA;iBAFF,IAAI,mBAAsC;yBAa3C,KAAK,eAAe,CAAC;yBAET,KAAK,eAAe,CAAC;6BAE5B,KAAK,eAAe,CAAC;oBAEvC,YAA0B;oBAE1B,YAAsC;wBAElC,gBAA+B;;CAnBhD,IAAO,SAAkB,UAAsB;EAC7C,MAAM,aAAa,yBAAyB,SAAS,KAAK,OAAO;AACjE,SAAO,KAAK,QAAQ,IAAI,YAAY,SAAS;;CAG/C,iBAA0B;AACxB,SAAO,KAAK,QAAQ,UAAU,KAAK,KAAA;;CAerC,gBAA2C;EACzC,MAAM,aAAa,KAAK,QAAQ,UAAU;AAC1C,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,yBAAyB;AAC1D,SAAO;;;;;;AC7CX,SAAgB,aAAa,QAAkC;AAC7D,gBAAkB,OAAO;AACzB,mBAAkB,IAAI,yBAAyB,OAAO,CAAC"}
package/dist/server.d.mts CHANGED
@@ -1,24 +1,18 @@
1
- import * as _$_tanstack_react_start0 from "@tanstack/react-start";
1
+ import { RequestMiddlewareAfterServer } from "@tanstack/react-start";
2
2
  import * as _$gt_i18n_types0 from "gt-i18n/types";
3
- import { Message } from "gt-i18n/types";
4
3
 
5
- //#region src/middleware/gtMiddleware.d.ts
6
- /**
7
- * Establish request-scoped GT conditions for SSR, server routes, and server
8
- * functions.
9
- */
10
- declare const gtMiddleware: _$_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>;
11
- //#endregion
12
- //#region src/functions/server.d.ts
13
- /** Return the locale associated with the current server request. */
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. */
14
8
  declare const getLocale: () => string;
15
- /** Return whether internationalization is enabled for the current request. */
9
+ /** @deprecated Import `getEnableI18n` from `gt-tanstack-start` instead. */
16
10
  declare const getEnableI18n: () => boolean;
17
- /** Return a string translation function for the current server request. */
18
- declare const getGT: (messages?: Message[]) => Promise<_$gt_i18n_types0.SyncResolutionFunctionWithFallback>;
19
- /** Return a registered-message translation function for the current request. */
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. */
20
14
  declare const getMessages: () => Promise<_$gt_i18n_types0.MFunctionType>;
21
- /** Return a dictionary translation function for the current server request. */
15
+ /** @deprecated Import `getTranslations` from `gt-tanstack-start` instead. */
22
16
  declare const getTranslations: (rootId?: string) => Promise<_$gt_i18n_types0.TFunctionType>;
23
17
  //#endregion
24
18
  export { getEnableI18n, getGT, getLocale, getMessages, getTranslations, gtMiddleware };
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.mts","names":[],"sources":["../src/middleware/gtMiddleware.ts","../src/functions/server.ts"],"mappings":";;;;;;;;;cAOa,YAAA,EAEX,wBAAA,CAFuB,4BAAA;;;;cCGZ,SAAA;;cAKA,aAAA;ADRb;AAAA,cCaa,KAAA,GAAK,QAAA,GAAwC,OAAA,OAAS,OAAA,CAAF,gBAAA,CAAE,kCAAA;;cAYtD,WAAA,QAAW,OAAA,CAMtB,gBAAA,CANsB,aAAA;;cASX,eAAA,GAAe,MAAA,cAA4C,OAAA,CAOtE,gBAAA,CAPsE,aAAA"}
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 CHANGED
@@ -1,5 +1,6 @@
1
- import { createMiddleware, createServerOnlyFn } from "@tanstack/react-start";
1
+ import { createIsomorphicFn, createMiddleware } from "@tanstack/react-start";
2
2
  import { createGlobalSingleton, getGTInternal, getMessagesInternal, getTranslationsInternal } from "gt-i18n/internal";
3
+ import { getReadonlyConditionStore } from "@generaltranslation/react-core/pure";
3
4
  //#region ../core/dist/api-BOEGbEF6.mjs
4
5
  function ensureSentence(text) {
5
6
  const trimmed = text.trim();
@@ -64,45 +65,74 @@ conditionStoreSingleton.isInitialized;
64
65
  * Establish request-scoped GT conditions for SSR, server routes, and server
65
66
  * functions.
66
67
  */
67
- const gtMiddleware = createMiddleware().server(({ request, next }) => {
68
+ const gtMiddleware$1 = createMiddleware().server(({ request, next }) => {
68
69
  return getConditionStore().run(request, () => next());
69
70
  });
70
71
  //#endregion
71
- //#region src/functions/server.ts
72
- /** Return the locale associated with the current server request. */
73
- const getLocale = createServerOnlyFn(() => {
74
- return getConditionStore().getLocale();
75
- });
76
- /** Return whether internationalization is enabled for the current request. */
77
- const getEnableI18n = createServerOnlyFn(() => {
78
- return getConditionStore().getEnableI18n();
79
- });
80
- /** Return a string translation function for the current server request. */
81
- const getGT = createServerOnlyFn(async (messages) => {
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) => {
82
79
  const conditionStore = getConditionStore();
83
80
  return getGTInternal({
84
81
  locale: conditionStore.getLocale(),
85
82
  enableI18n: conditionStore.getEnableI18n()
86
83
  }, messages);
84
+ }).client((messages) => {
85
+ const conditionStore = getReadonlyConditionStore();
86
+ return getGTInternal({
87
+ locale: conditionStore.getLocale(),
88
+ enableI18n: conditionStore.getEnableI18n()
89
+ }, messages);
87
90
  });
88
- /** Return a registered-message translation function for the current request. */
89
- const getMessages = createServerOnlyFn(async () => {
91
+ /** Return a registered-message translation function for the current runtime. */
92
+ const getMessages$1 = createIsomorphicFn().server(() => {
90
93
  const conditionStore = getConditionStore();
91
94
  return getMessagesInternal({
92
95
  locale: conditionStore.getLocale(),
93
96
  enableI18n: conditionStore.getEnableI18n()
94
97
  });
98
+ }).client(() => {
99
+ const conditionStore = getReadonlyConditionStore();
100
+ return getMessagesInternal({
101
+ locale: conditionStore.getLocale(),
102
+ enableI18n: conditionStore.getEnableI18n()
103
+ });
95
104
  });
96
- /** Return a dictionary translation function for the current server request. */
97
- const getTranslations = createServerOnlyFn(async (rootId) => {
105
+ /** Return a dictionary translation function for the current runtime. */
106
+ const getTranslations$1 = createIsomorphicFn().server((rootId) => {
98
107
  const conditionStore = getConditionStore();
99
108
  return getTranslationsInternal({
100
109
  locale: conditionStore.getLocale(),
101
110
  enableI18n: conditionStore.getEnableI18n(),
102
111
  rootId
103
112
  });
113
+ }).client((rootId) => {
114
+ const conditionStore = getReadonlyConditionStore();
115
+ return getTranslationsInternal({
116
+ locale: conditionStore.getLocale(),
117
+ enableI18n: conditionStore.getEnableI18n(),
118
+ rootId
119
+ });
104
120
  });
105
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
106
136
  export { getEnableI18n, getGT, getLocale, getMessages, getTranslations, gtMiddleware };
107
137
 
108
138
  //# sourceMappingURL=server.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.mjs","names":[],"sources":["../../core/dist/api-BOEGbEF6.mjs","../src/condition-store/singleton.ts","../src/middleware/gtMiddleware.ts","../src/functions/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 { createMiddleware } 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 = createMiddleware().server(({ request, next }) => {\n return getConditionStore().run(request, () => next());\n});\n","import { createServerOnlyFn } from '@tanstack/react-start';\nimport {\n getGTInternal,\n getMessagesInternal,\n getTranslationsInternal,\n} from 'gt-i18n/internal';\nimport type { Message } from 'gt-i18n/types';\nimport { getConditionStore } from '../condition-store/singleton';\n\n/** Return the locale associated with the current server request. */\nexport const getLocale = createServerOnlyFn((): string => {\n return getConditionStore().getLocale();\n});\n\n/** Return whether internationalization is enabled for the current request. */\nexport const getEnableI18n = createServerOnlyFn((): boolean => {\n return getConditionStore().getEnableI18n();\n});\n\n/** Return a string translation function for the current server request. */\nexport const getGT = createServerOnlyFn(async (messages?: Message[]) => {\n const conditionStore = getConditionStore();\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 request. */\nexport const getMessages = createServerOnlyFn(async () => {\n const conditionStore = getConditionStore();\n return getMessagesInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n });\n});\n\n/** Return a dictionary translation function for the current server request. */\nexport const getTranslations = createServerOnlyFn(async (rootId?: string) => {\n const conditionStore = getConditionStore();\n return getTranslationsInternal({\n locale: conditionStore.getLocale(),\n enableI18n: conditionStore.getEnableI18n(),\n rootId,\n });\n});\n"],"mappings":";;;AAKA,SAAS,eAAe,MAAM;CAC7B,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAEvD,SAAS,cAAc,MAAM;CAC5B,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACf,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OAAO,SAAS,IAAK;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,MAAM,eAAe;EACpB;EACA;EACA,sBAAsB,GAAG,cAAc,IAAI,CA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,eAAe;EAC1C;EACD,CAAC;EACF"}
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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Ae;EAC1C;EACD,CAAC;EACF,CACD,QAAQ,WAAoB;CAC3B,MAAM,iBAAiB,2BAA2B;AAClD,QAAO,wBAAwB;EAC7B,QAAQ,eAAe,WAAW;EAClC,YAAY,eAAe,eAAe;EAC1C;EACD,CAAC;EACF;;;;ACzEN,MAAa,eAITC;;AAGJ,MAAa,YAAYC;;AAGzB,MAAa,gBAAgBC;;AAG7B,MAAa,QAAQC;;AAGrB,MAAa,cAAcC;;AAG3B,MAAa,kBAAkBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt-tanstack-start",
3
- "version": "11.0.12",
3
+ "version": "11.0.13",
4
4
  "description": "TanStack Start integration for General Translation",
5
5
  "main": "./dist/index.server.mjs",
6
6
  "module": "./dist/index.server.mjs",
@@ -16,8 +16,8 @@
16
16
  "@tanstack/react-start": ">=1.159.0"
17
17
  },
18
18
  "dependencies": {
19
- "gt-react": "11.0.12",
20
- "@generaltranslation/react-core": "11.0.12",
19
+ "gt-react": "11.0.13",
20
+ "@generaltranslation/react-core": "11.0.13",
21
21
  "gt-i18n": "1.0.7",
22
22
  "generaltranslation": "9.0.3"
23
23
  },