@mpgd/i18n 0.6.0 → 0.6.2

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.
Files changed (123) hide show
  1. package/dist/paraglide/messages/_index.d.ts +59 -58
  2. package/dist/paraglide/messages/_index.js +6 -6
  3. package/dist/paraglide/messages/action_interstitial_ads.d.ts +4 -4
  4. package/dist/paraglide/messages/action_interstitial_ads.js +2 -2
  5. package/dist/paraglide/messages/action_leaderboard.d.ts +4 -4
  6. package/dist/paraglide/messages/action_leaderboard.js +2 -2
  7. package/dist/paraglide/messages/action_localization.d.ts +4 -4
  8. package/dist/paraglide/messages/action_localization.js +2 -2
  9. package/dist/paraglide/messages/action_purchases.d.ts +4 -4
  10. package/dist/paraglide/messages/action_purchases.js +2 -2
  11. package/dist/paraglide/messages/action_reward_ads.d.ts +4 -4
  12. package/dist/paraglide/messages/action_reward_ads.js +2 -2
  13. package/dist/paraglide/messages/app_title.d.ts +4 -4
  14. package/dist/paraglide/messages/app_title.js +2 -2
  15. package/dist/paraglide/messages/availability_off.d.ts +4 -4
  16. package/dist/paraglide/messages/availability_off.js +2 -2
  17. package/dist/paraglide/messages/availability_on.d.ts +4 -4
  18. package/dist/paraglide/messages/availability_on.js +2 -2
  19. package/dist/paraglide/messages/availability_unsupported.d.ts +4 -4
  20. package/dist/paraglide/messages/availability_unsupported.js +2 -2
  21. package/dist/paraglide/messages/cap_iap.d.ts +4 -4
  22. package/dist/paraglide/messages/cap_iap.js +2 -2
  23. package/dist/paraglide/messages/cap_leaderboard.d.ts +4 -4
  24. package/dist/paraglide/messages/cap_leaderboard.js +2 -2
  25. package/dist/paraglide/messages/cap_localization.d.ts +4 -4
  26. package/dist/paraglide/messages/cap_localization.js +2 -2
  27. package/dist/paraglide/messages/cap_rewarded_ads.d.ts +4 -4
  28. package/dist/paraglide/messages/cap_rewarded_ads.js +2 -2
  29. package/dist/paraglide/messages/cap_save.d.ts +4 -4
  30. package/dist/paraglide/messages/cap_save.js +2 -2
  31. package/dist/paraglide/messages/effective_config_summary.d.ts +8 -8
  32. package/dist/paraglide/messages/effective_config_summary.js +2 -2
  33. package/dist/paraglide/messages/feature_target_disabled.d.ts +6 -6
  34. package/dist/paraglide/messages/feature_target_disabled.js +2 -2
  35. package/dist/paraglide/messages/feature_unavailable.d.ts +6 -6
  36. package/dist/paraglide/messages/feature_unavailable.js +2 -2
  37. package/dist/paraglide/messages/feature_unsupported.d.ts +6 -6
  38. package/dist/paraglide/messages/feature_unsupported.js +2 -2
  39. package/dist/paraglide/messages/leaderboard_action.d.ts +4 -4
  40. package/dist/paraglide/messages/leaderboard_action.js +2 -2
  41. package/dist/paraglide/messages/leaderboard_action_unavailable.d.ts +4 -4
  42. package/dist/paraglide/messages/leaderboard_action_unavailable.js +2 -2
  43. package/dist/paraglide/messages/leaderboard_opened.d.ts +4 -4
  44. package/dist/paraglide/messages/leaderboard_opened.js +2 -2
  45. package/dist/paraglide/messages/leaderboard_unavailable.d.ts +4 -4
  46. package/dist/paraglide/messages/leaderboard_unavailable.js +2 -2
  47. package/dist/paraglide/messages/loading_player.d.ts +4 -4
  48. package/dist/paraglide/messages/loading_player.js +2 -2
  49. package/dist/paraglide/messages/mock_only.d.ts +4 -4
  50. package/dist/paraglide/messages/mock_only.js +2 -2
  51. package/dist/paraglide/messages/opening_purchase.d.ts +4 -4
  52. package/dist/paraglide/messages/opening_purchase.js +2 -2
  53. package/dist/paraglide/messages/play_again.d.ts +4 -4
  54. package/dist/paraglide/messages/play_again.js +2 -2
  55. package/dist/paraglide/messages/player.d.ts +6 -6
  56. package/dist/paraglide/messages/player.js +2 -2
  57. package/dist/paraglide/messages/preparing_demo.d.ts +4 -4
  58. package/dist/paraglide/messages/preparing_demo.js +2 -2
  59. package/dist/paraglide/messages/purchase_action.d.ts +4 -4
  60. package/dist/paraglide/messages/purchase_action.js +2 -2
  61. package/dist/paraglide/messages/purchase_completed.d.ts +4 -4
  62. package/dist/paraglide/messages/purchase_completed.js +2 -2
  63. package/dist/paraglide/messages/purchase_status.d.ts +6 -6
  64. package/dist/paraglide/messages/purchase_status.js +2 -2
  65. package/dist/paraglide/messages/purchase_unavailable.d.ts +4 -4
  66. package/dist/paraglide/messages/purchase_unavailable.js +2 -2
  67. package/dist/paraglide/messages/reward_ad_action.d.ts +4 -4
  68. package/dist/paraglide/messages/reward_ad_action.js +2 -2
  69. package/dist/paraglide/messages/reward_ad_unavailable.d.ts +4 -4
  70. package/dist/paraglide/messages/reward_ad_unavailable.js +2 -2
  71. package/dist/paraglide/messages/reward_granted.d.ts +4 -4
  72. package/dist/paraglide/messages/reward_granted.js +2 -2
  73. package/dist/paraglide/messages/reward_unavailable.d.ts +6 -6
  74. package/dist/paraglide/messages/reward_unavailable.js +2 -2
  75. package/dist/paraglide/messages/save_summary.d.ts +7 -7
  76. package/dist/paraglide/messages/save_summary.js +2 -2
  77. package/dist/paraglide/messages/saved.d.ts +4 -4
  78. package/dist/paraglide/messages/saved.js +2 -2
  79. package/dist/paraglide/messages/saved_and_submitted.d.ts +4 -4
  80. package/dist/paraglide/messages/saved_and_submitted.js +2 -2
  81. package/dist/paraglide/messages/saving_result.d.ts +4 -4
  82. package/dist/paraglide/messages/saving_result.js +2 -2
  83. package/dist/paraglide/messages/score.d.ts +6 -6
  84. package/dist/paraglide/messages/score.js +2 -2
  85. package/dist/paraglide/messages/sdk_summary.d.ts +6 -6
  86. package/dist/paraglide/messages/sdk_summary.js +2 -2
  87. package/dist/paraglide/messages/showing_rewarded_ad.d.ts +4 -4
  88. package/dist/paraglide/messages/showing_rewarded_ad.js +2 -2
  89. package/dist/paraglide/messages/status_cleared.d.ts +4 -4
  90. package/dist/paraglide/messages/status_cleared.js +2 -2
  91. package/dist/paraglide/messages/status_try_again.d.ts +4 -4
  92. package/dist/paraglide/messages/status_try_again.js +2 -2
  93. package/dist/paraglide/messages/tap_to_start.d.ts +4 -4
  94. package/dist/paraglide/messages/tap_to_start.js +2 -2
  95. package/dist/paraglide/messages/target.d.ts +6 -6
  96. package/dist/paraglide/messages/target.js +2 -2
  97. package/dist/paraglide/messages/target_availability_summary.d.ts +7 -7
  98. package/dist/paraglide/messages/target_availability_summary.js +2 -2
  99. package/dist/paraglide/messages/target_config_unavailable.d.ts +4 -4
  100. package/dist/paraglide/messages/target_config_unavailable.js +2 -2
  101. package/dist/paraglide/messages/target_feature_iap.d.ts +4 -4
  102. package/dist/paraglide/messages/target_feature_iap.js +2 -2
  103. package/dist/paraglide/messages/target_feature_interstitial_ads.d.ts +4 -4
  104. package/dist/paraglide/messages/target_feature_interstitial_ads.js +2 -2
  105. package/dist/paraglide/messages/target_feature_leaderboard.d.ts +4 -4
  106. package/dist/paraglide/messages/target_feature_leaderboard.js +2 -2
  107. package/dist/paraglide/messages/target_feature_localization.d.ts +4 -4
  108. package/dist/paraglide/messages/target_feature_localization.js +2 -2
  109. package/dist/paraglide/messages/target_feature_rewarded_ads.d.ts +4 -4
  110. package/dist/paraglide/messages/target_feature_rewarded_ads.js +2 -2
  111. package/dist/paraglide/messages/viewport.d.ts +8 -8
  112. package/dist/paraglide/messages/viewport.js +2 -2
  113. package/dist/paraglide/messages/viewport_orientation_mismatch.d.ts +7 -7
  114. package/dist/paraglide/messages/viewport_orientation_mismatch.js +2 -2
  115. package/dist/paraglide/messages/viewport_orientation_policy.d.ts +6 -6
  116. package/dist/paraglide/messages/viewport_orientation_policy.js +2 -2
  117. package/dist/paraglide/messages.d.ts +2 -2
  118. package/dist/paraglide/registry.d.ts +5 -5
  119. package/dist/paraglide/runtime.d.ts +548 -283
  120. package/dist/paraglide/runtime.js +545 -86
  121. package/dist/paraglide/server.d.ts +1 -1
  122. package/dist/paraglide/server.js +20 -8
  123. package/package.json +5 -5
@@ -1,20 +1,110 @@
1
1
  /**
2
- * Returns the strategy to use for a specific URL.
2
+ * The project's base locale.
3
3
  *
4
- * If no route strategy matches (or the matching rule is `exclude: true`),
5
- * the global strategy is returned.
4
+ * @example
5
+ * if (locale === baseLocale) {
6
+ * // do something
7
+ * }
8
+ */
9
+ export declare const baseLocale = "en";
10
+ /**
11
+ * The project's locales that have been specified in the settings.
6
12
  *
7
- * @param {string | URL} url
8
- * @returns {typeof strategy}
13
+ * @example
14
+ * if (locales.includes(userSelectedLocale) === false) {
15
+ * throw new Error('Locale is not available');
16
+ * }
9
17
  */
10
- export function getStrategyForUrl(url: string | URL): typeof strategy;
18
+ export declare const locales: readonly ["en", "ko"];
19
+ /** @type {string} */
20
+ export declare const cookieName: string;
21
+ /** @type {number} */
22
+ export declare const cookieMaxAge: number;
23
+ /** @type {string} */
24
+ export declare const cookieDomain: string;
25
+ /** @type {string} */
26
+ export declare const localStorageKey: string;
11
27
  /**
12
- * Returns whether the given URL is excluded from middleware i18n processing.
28
+ * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
29
+ */
30
+ export declare const strategy: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
31
+ /**
32
+ * Route-level strategy overrides.
13
33
  *
14
- * @param {string | URL} url
15
- * @returns {boolean}
34
+ * `match` uses URLPattern syntax.
35
+ *
36
+ * @type {Array<{
37
+ * match: string;
38
+ * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
39
+ * exclude?: boolean;
40
+ * }>}
41
+ */
42
+ export declare const routeStrategies: Array<{
43
+ match: string;
44
+ strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
45
+ exclude?: boolean;
46
+ }>;
47
+ /**
48
+ * The used URL patterns.
49
+ *
50
+ * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
51
+ */
52
+ export declare const urlPatterns: Array<{
53
+ pattern: string;
54
+ localized: Array<[Locale, string]>;
55
+ }>;
56
+ /**
57
+ * Controls trailing slash canonicalization for localized URLs.
58
+ *
59
+ * @type {"always" | "never" | undefined}
60
+ */
61
+ export declare const trailingSlash: "always" | "never" | undefined;
62
+ export type ParaglideAsyncLocalStorage = {
63
+ getStore(): {
64
+ locale?: Locale;
65
+ origin?: string;
66
+ messageCalls?: Set<string>;
67
+ } | undefined;
68
+ run: (store: {
69
+ locale?: Locale;
70
+ origin?: string;
71
+ messageCalls?: Set<string>;
72
+ }, cb: any) => any;
73
+ };
74
+ /**
75
+ * @typedef {{
76
+ * getStore(): {
77
+ * locale?: Locale,
78
+ * origin?: string,
79
+ * messageCalls?: Set<string>
80
+ * } | undefined,
81
+ * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set<string>},
82
+ * cb: any) => any
83
+ * }} ParaglideAsyncLocalStorage
84
+ */
85
+ /**
86
+ * Server side async local storage that is set by `serverMiddleware()`.
87
+ *
88
+ * The variable is used to retrieve the locale and origin in a server-side
89
+ * rendering context without effecting other requests.
90
+ *
91
+ * @type {ParaglideAsyncLocalStorage | undefined}
92
+ */
93
+ export declare let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
94
+ /**
95
+ * Returns the current server-side async local storage instance.
96
+ *
97
+ * Accessing the mutable value through a function keeps it observable when
98
+ * module interceptors wrap exported bindings and snapshot their initial value.
99
+ *
100
+ * @returns {ParaglideAsyncLocalStorage | undefined}
16
101
  */
17
- export function isExcludedByRouteStrategy(url: string | URL): boolean;
102
+ export declare function getServerAsyncLocalStorage(): ParaglideAsyncLocalStorage | undefined;
103
+ export declare const disableAsyncLocalStorage = false;
104
+ export declare const experimentalMiddlewareLocaleSplitting = false;
105
+ export declare const isServer: boolean;
106
+ /** @type {Locale | undefined} */
107
+ export declare const experimentalStaticLocale: Locale | undefined;
18
108
  /**
19
109
  * Sets the server side async local storage.
20
110
  *
@@ -25,14 +115,49 @@ export function isExcludedByRouteStrategy(url: string | URL): boolean;
25
115
  *
26
116
  * @param {ParaglideAsyncLocalStorage | undefined} value
27
117
  */
28
- export function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStorage | undefined): void;
118
+ export declare function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStorage | undefined): void;
119
+ /**
120
+ * Get the current locale.
121
+ *
122
+ * The locale is resolved using your configured strategies (URL, cookie, localStorage, etc.)
123
+ * in the order they are defined. In SSR contexts, the locale is retrieved from AsyncLocalStorage
124
+ * which is set by the `paraglideMiddleware()`.
125
+ *
126
+ * @see https://paraglidejs.com/strategy - Configure locale detection strategies
127
+ *
128
+ * @example
129
+ * if (getLocale() === 'de') {
130
+ * console.log('Germany 🇩🇪');
131
+ * } else if (getLocale() === 'nl') {
132
+ * console.log('Netherlands 🇳🇱');
133
+ * }
134
+ *
135
+ * @returns {Locale} The current locale.
136
+ */
137
+ export declare let getLocale: () => Locale;
29
138
  /**
30
139
  * Resolve locale for a given URL using route-aware strategies.
31
140
  *
32
141
  * @param {string | URL} url
33
142
  * @returns {Locale}
34
143
  */
35
- export function getLocaleForUrl(url: string | URL): Locale;
144
+ export declare function getLocaleForUrl(url: string | URL): Locale;
145
+ /**
146
+ * Overwrite the `getLocale()` function.
147
+ *
148
+ * Use this function to overwrite how the locale is resolved. This is useful
149
+ * for custom locale resolution or advanced use cases like SSG with concurrent rendering.
150
+ *
151
+ * @see https://paraglidejs.com/strategy
152
+ *
153
+ * @example
154
+ * overwriteGetLocale(() => {
155
+ * return Cookies.get('locale') ?? baseLocale
156
+ * });
157
+ *
158
+ * @param {() => Locale} fn - The new implementation for `getLocale()`.
159
+ */
160
+ export declare const overwriteGetLocale: (fn: () => Locale) => void;
36
161
  /**
37
162
  * Get writing direction for a locale.
38
163
  *
@@ -47,14 +172,79 @@ export function getLocaleForUrl(url: string | URL): Locale;
47
172
  * @param {string} [locale] - Target locale. If not provided, uses `getLocale()`
48
173
  * @returns {"ltr" | "rtl"}
49
174
  */
50
- export function getTextDirection(locale?: string): "ltr" | "rtl";
175
+ export declare function getTextDirection(locale?: string): "ltr" | "rtl";
176
+ export type SetLocaleFn = (newLocale: Locale, options?: {
177
+ reload?: boolean;
178
+ }) => void | Promise<void>;
179
+ /**
180
+ * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
181
+ */
182
+ /**
183
+ * Set the locale.
184
+ *
185
+ * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
186
+ * By default, this navigates the client to the localized URL or reloads the current
187
+ * document to reflect the new locale. `reload: false` is a narrow browser-only escape
188
+ * hatch for a fully client-rendered, non-URL-routed surface that owns its reactive
189
+ * updates and document state. It does not re-render the UI or update the document.
190
+ * Do not use it for normal locale pickers, URL-routed pages, or switching an SSR,
191
+ * SSG, or hydrated document. It is incompatible with per-locale builds.
192
+ *
193
+ * If any custom strategy's `setLocale` function is async, then this function
194
+ * will become async as well.
195
+ *
196
+ * @see https://paraglidejs.com/strategy
197
+ *
198
+ * @example
199
+ * setLocale('en');
200
+ *
201
+ * @example
202
+ * setLocale('en', { reload: false });
203
+ *
204
+ * @type {SetLocaleFn}
205
+ */
206
+ export declare let setLocale: SetLocaleFn;
207
+ /**
208
+ * Overwrite the `setLocale()` function.
209
+ *
210
+ * Use this function to overwrite how the locale is set. For example,
211
+ * modify a cookie, env variable, or a user's preference.
212
+ *
213
+ * @example
214
+ * overwriteSetLocale((newLocale) => {
215
+ * // set the locale in a cookie
216
+ * return Cookies.set('locale', newLocale)
217
+ * });
218
+ *
219
+ * @param {SetLocaleFn} fn
220
+ */
221
+ export declare const overwriteSetLocale: (fn: SetLocaleFn) => void;
222
+ /**
223
+ * The origin of the current URL.
224
+ *
225
+ * Defaults to "http://example.com" in non-browser environments. If this
226
+ * behavior is not desired, the implementation can be overwritten
227
+ * by `overwriteGetUrlOrigin()`.
228
+ *
229
+ * @type {() => string}
230
+ */
231
+ export declare let getUrlOrigin: () => string;
232
+ /**
233
+ * Overwrite the getUrlOrigin function.
234
+ *
235
+ * Use this function in server environments to
236
+ * define how the URL origin is resolved.
237
+ *
238
+ * @param {() => string} fn - The new implementation for `getUrlOrigin()`.
239
+ */
240
+ export declare let overwriteGetUrlOrigin: (fn: () => string) => void;
51
241
  /**
52
242
  * Coerces a locale-like string to the canonical locale value used by the runtime.
53
243
  *
54
244
  * @param {unknown} value
55
245
  * @returns {Locale | undefined}
56
246
  */
57
- export function toLocale(value: unknown): Locale | undefined;
247
+ export declare function toLocale(value: unknown): Locale | undefined;
58
248
  /**
59
249
  * Check if something is an available locale with the canonical project casing.
60
250
  *
@@ -70,7 +260,7 @@ export function toLocale(value: unknown): Locale | undefined;
70
260
  * @param {unknown} locale
71
261
  * @returns {locale is Locale}
72
262
  */
73
- export function isLocale(locale: unknown): locale is Locale;
263
+ export declare function isLocale(locale: unknown): locale is Locale;
74
264
  /**
75
265
  * Asserts that the input can be normalized to a locale.
76
266
  *
@@ -78,7 +268,81 @@ export function isLocale(locale: unknown): locale is Locale;
78
268
  * @returns {Locale} The input normalized to a Locale.
79
269
  * @throws {Error} If the input is not a locale.
80
270
  */
81
- export function assertIsLocale(input: unknown): Locale;
271
+ export declare function assertIsLocale(input: unknown): Locale;
272
+ export type ExtractLocaleFromRequestOptions = {
273
+ /**
274
+ * - Effective request URL to use for route matching and locale detection with the URL strategy.
275
+ */
276
+ effectiveRequestUrl?: string | URL;
277
+ };
278
+ /**
279
+ * @typedef {object} ExtractLocaleFromRequestOptions
280
+ * @property {string | URL} [effectiveRequestUrl] - Effective request URL to use for route matching and locale detection with the URL strategy.
281
+ */
282
+ /**
283
+ * Extracts a locale from a request.
284
+ *
285
+ * Use the function on the server to extract the locale
286
+ * from a request.
287
+ *
288
+ * The function goes through the strategies in the order
289
+ * they are defined. If a strategy returns an invalid locale,
290
+ * it will fall back to the next strategy.
291
+ *
292
+ * Note: Custom server strategies are not supported in this synchronous version.
293
+ * Use `extractLocaleFromRequestAsync` if you need custom server strategies with async getLocale methods.
294
+ *
295
+ * @example
296
+ * const locale = extractLocaleFromRequest(request);
297
+ *
298
+ * @param {Request} request
299
+ * @param {ExtractLocaleFromRequestOptions} [options]
300
+ * @returns {Locale}
301
+ */
302
+ export declare const extractLocaleFromRequest: (request: Request, options?: ExtractLocaleFromRequestOptions) => Locale;
303
+ /**
304
+ * Extracts a locale from a request using the provided strategy order.
305
+ *
306
+ * @param {Request} request
307
+ * @param {typeof strategy} strategies
308
+ * @param {string | URL} [url]
309
+ * @returns {Locale}
310
+ */
311
+ export declare const extractLocaleFromRequestWithStrategies: (request: Request, strategies: typeof strategy, url?: string | URL) => Locale;
312
+ /**
313
+ * Asynchronously extracts a locale from a request.
314
+ *
315
+ * This function supports async custom server strategies, unlike the synchronous
316
+ * `extractLocaleFromRequest`. Use this function when you have custom server strategies
317
+ * that need to perform asynchronous operations (like database calls) in their getLocale method.
318
+ *
319
+ * The function first processes any custom server strategies asynchronously, then falls back
320
+ * to the synchronous `extractLocaleFromRequest` for all other strategies.
321
+ *
322
+ * @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
323
+ *
324
+ * @example
325
+ * // Basic usage
326
+ * const locale = await extractLocaleFromRequestAsync(request);
327
+ *
328
+ * @example
329
+ * // With custom async server strategy
330
+ * defineCustomServerStrategy("custom-database", {
331
+ * getLocale: async (request) => {
332
+ * const userId = extractUserIdFromRequest(request);
333
+ * return await getUserLocaleFromDatabase(userId);
334
+ * }
335
+ * });
336
+ *
337
+ * const locale = await extractLocaleFromRequestAsync(request);
338
+ *
339
+ * @param {Request} request - The request object to extract the locale from.
340
+ * @param {{ effectiveRequestUrl?: string | URL }} [options] - Effective request URL to use for route matching and locale detection with the URL strategy.
341
+ * @returns {Promise<Locale>} The extracted locale.
342
+ */
343
+ export declare const extractLocaleFromRequestAsync: (request: Request, options?: {
344
+ effectiveRequestUrl?: string | URL;
345
+ }) => Promise<Locale>;
82
346
  /**
83
347
  * Extracts a cookie from the document.
84
348
  *
@@ -87,7 +351,7 @@ export function assertIsLocale(input: unknown): Locale;
87
351
  *
88
352
  * @returns {Locale | undefined}
89
353
  */
90
- export function extractLocaleFromCookie(): Locale | undefined;
354
+ export declare function extractLocaleFromCookie(): Locale | undefined;
91
355
  /**
92
356
  * Extracts a locale from the accept-language header.
93
357
  *
@@ -100,7 +364,7 @@ export function extractLocaleFromCookie(): Locale | undefined;
100
364
  * @param {Request} request - The request object to extract the locale from.
101
365
  * @returns {Locale | undefined} The negotiated preferred language.
102
366
  */
103
- export function extractLocaleFromHeader(request: Request): Locale | undefined;
367
+ export declare function extractLocaleFromHeader(request: Request): Locale | undefined;
104
368
  /**
105
369
  * Negotiates a preferred language from navigator.languages.
106
370
  *
@@ -112,7 +376,7 @@ export function extractLocaleFromHeader(request: Request): Locale | undefined;
112
376
  *
113
377
  * @returns {Locale | undefined}
114
378
  */
115
- export function extractLocaleFromNavigator(): Locale | undefined;
379
+ export declare function extractLocaleFromNavigator(): Locale | undefined;
116
380
  /**
117
381
  * Extracts the locale from a given URL using native URLPattern.
118
382
  *
@@ -123,7 +387,7 @@ export function extractLocaleFromNavigator(): Locale | undefined;
123
387
  * @param {URL|string} url - The full URL from which to extract the locale.
124
388
  * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
125
389
  */
126
- export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
390
+ export declare function extractLocaleFromUrl(url: URL | string): Locale | undefined;
127
391
  /**
128
392
  * Lower-level URL localization function, primarily used in server contexts.
129
393
  *
@@ -168,7 +432,7 @@ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
168
432
  * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
169
433
  * @returns {URL} The localized URL, always absolute
170
434
  */
171
- export function localizeUrl(url: string | URL, options?: {
435
+ export declare function localizeUrl(url: string | URL, options?: {
172
436
  locale?: Locale;
173
437
  }): URL;
174
438
  /**
@@ -210,7 +474,7 @@ export function localizeUrl(url: string | URL, options?: {
210
474
  * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
211
475
  * @returns {URL} The de-localized URL, always absolute
212
476
  */
213
- export function deLocalizeUrl(url: string | URL): URL;
477
+ export declare function deLocalizeUrl(url: string | URL): URL;
214
478
  /**
215
479
  * Aggregates named groups from various parts of the URLPattern match result.
216
480
  *
@@ -218,7 +482,80 @@ export function deLocalizeUrl(url: string | URL): URL;
218
482
  * @param {any} match - The URLPattern match result object.
219
483
  * @returns {Record<string, string | null | undefined>} An object containing all named groups from the match.
220
484
  */
221
- export function aggregateGroups(match: any): Record<string, string | null | undefined>;
485
+ export declare function aggregateGroups(match: any): Record<string, string | null | undefined>;
486
+ export type FastPathPattern = {
487
+ protocol: string | undefined;
488
+ hostname: string | undefined;
489
+ port: string | undefined;
490
+ pathnamePrefix: string;
491
+ pathMode: "segments" | "catch-all-optional" | "catch-all-required";
492
+ };
493
+ export type FastPathRoute = {
494
+ base: FastPathPattern;
495
+ localized: Array<{
496
+ locale: string;
497
+ pattern: FastPathPattern;
498
+ }>;
499
+ };
500
+ /**
501
+ * Match route policy against both the public URL and its canonical URL.
502
+ *
503
+ * The function is deliberately separate from variables.js: configuration is
504
+ * inert data, while canonicalization and route selection form a routing layer.
505
+ *
506
+ * @param {string | URL} url
507
+ * @returns {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined}
508
+ */
509
+ export declare function findMatchingRouteStrategy(url: string | URL): {
510
+ match: string;
511
+ strategy?: typeof strategy;
512
+ exclude?: boolean;
513
+ } | undefined;
514
+ /**
515
+ * Returns the strategy to use for a specific URL.
516
+ *
517
+ * If no route strategy matches (or the matching rule is `exclude: true`),
518
+ * the global strategy is returned.
519
+ *
520
+ * @param {string | URL} url
521
+ * @returns {typeof strategy}
522
+ */
523
+ export declare function getStrategyForUrl(url: string | URL): typeof strategy;
524
+ /**
525
+ * Returns whether the given URL is excluded from middleware i18n processing.
526
+ *
527
+ * @param {string | URL} url
528
+ * @returns {boolean}
529
+ */
530
+ export declare function isExcludedByRouteStrategy(url: string | URL): boolean;
531
+ export type ShouldRedirectServerInput = {
532
+ request: Request;
533
+ /**
534
+ * - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
535
+ */
536
+ effectiveRequestUrl?: string | URL;
537
+ locale?: Locale;
538
+ };
539
+ export type ShouldRedirectClientInput = {
540
+ request?: undefined;
541
+ url?: string | URL;
542
+ locale?: Locale;
543
+ };
544
+ export type ShouldRedirectInput = ShouldRedirectServerInput | ShouldRedirectClientInput;
545
+ export type ShouldRedirectResult = {
546
+ /**
547
+ * - Indicates whether the consumer should perform a redirect.
548
+ */
549
+ shouldRedirect: boolean;
550
+ /**
551
+ * - Locale resolved using the configured strategies.
552
+ */
553
+ locale: Locale;
554
+ /**
555
+ * - Destination URL when a redirect is required.
556
+ */
557
+ redirectUrl: URL | undefined;
558
+ };
222
559
  /**
223
560
  * @typedef {object} ShouldRedirectServerInput
224
561
  * @property {Request} request
@@ -290,7 +627,7 @@ export function aggregateGroups(match: any): Record<string, string | null | unde
290
627
  * @param {ShouldRedirectInput} [input]
291
628
  * @returns {Promise<ShouldRedirectResult>}
292
629
  */
293
- export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedirectResult>;
630
+ export declare function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedirectResult>;
294
631
  /**
295
632
  * High-level URL localization function optimized for client-side UI usage.
296
633
  *
@@ -331,7 +668,7 @@ export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedir
331
668
  * @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
332
669
  * @returns {string} The localized href, relative if input was relative
333
670
  */
334
- export function localizeHref(href: string, options?: {
671
+ export declare function localizeHref(href: string, options?: {
335
672
  locale?: Locale;
336
673
  }): string;
337
674
  /**
@@ -374,12 +711,12 @@ export function localizeHref(href: string, options?: {
374
711
  * @param {string} href - The href to de-localize (can be relative or absolute)
375
712
  * @returns {string} The de-localized href, relative if input was relative
376
713
  */
377
- export function deLocalizeHref(href: string): string;
714
+ export declare function deLocalizeHref(href: string): string;
378
715
  /**
379
716
  * @param {string} safeModuleId
380
717
  * @param {Locale} locale
381
718
  */
382
- export function trackMessageCall(safeModuleId: string, locale: Locale): void;
719
+ export declare function trackMessageCall(safeModuleId: string, locale: Locale): void;
383
720
  /**
384
721
  * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
385
722
  *
@@ -423,163 +760,20 @@ export function trackMessageCall(safeModuleId: string, locale: Locale): void;
423
760
  * @returns {URL[]} Array of URL objects representing all localized variants.
424
761
  * The order follows each input URL with all its locale variants before moving to the next URL.
425
762
  */
426
- export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
763
+ export declare function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
764
+ export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage";
765
+ export type CustomStrategy = `custom_${string}`;
766
+ export type Strategy = BuiltInStrategy | CustomStrategy;
767
+ export type Strategies = Array<Strategy>;
768
+ export type CustomServerStrategyHandler = {
769
+ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined);
770
+ };
771
+ export type CustomClientStrategyHandler = {
772
+ getLocale: () => Promise<string | undefined> | (string | undefined);
773
+ setLocale: (locale: string) => Promise<void> | void;
774
+ };
427
775
  /**
428
- * Checks if the given strategy is a custom strategy.
429
- *
430
- * @param {unknown} strategy The name of the custom strategy to validate.
431
- * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
432
- * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
433
- */
434
- export function isCustomStrategy(strategy: unknown): boolean;
435
- /**
436
- * Defines a custom strategy that is executed on the server.
437
- *
438
- * @see https://paraglidejs.com/strategy#write-your-own-strategy
439
- *
440
- * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
441
- * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
442
- * the method getLocale.
443
- * @returns {void}
444
- */
445
- export function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void;
446
- /**
447
- * Defines a custom strategy that is executed on the client.
448
- *
449
- * @see https://paraglidejs.com/strategy#write-your-own-strategy
450
- *
451
- * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
452
- * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
453
- * methods getLocale and setLocale.
454
- * @returns {void}
455
- */
456
- export function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void;
457
- /**
458
- * The project's base locale.
459
- *
460
- * @example
461
- * if (locale === baseLocale) {
462
- * // do something
463
- * }
464
- */
465
- export const baseLocale: "en";
466
- /**
467
- * The project's locales that have been specified in the settings.
468
- *
469
- * @example
470
- * if (locales.includes(userSelectedLocale) === false) {
471
- * throw new Error('Locale is not available');
472
- * }
473
- */
474
- export const locales: readonly ["en", "ko"];
475
- /** @type {string} */
476
- export const cookieName: string;
477
- /** @type {number} */
478
- export const cookieMaxAge: number;
479
- /** @type {string} */
480
- export const cookieDomain: string;
481
- /** @type {string} */
482
- export const localStorageKey: string;
483
- /**
484
- * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
485
- */
486
- export const strategy: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
487
- /**
488
- * Route-level strategy overrides.
489
- *
490
- * `match` uses URLPattern syntax.
491
- *
492
- * @type {Array<{
493
- * match: string;
494
- * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
495
- * exclude?: boolean;
496
- * }>}
497
- */
498
- export const routeStrategies: Array<{
499
- match: string;
500
- strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
501
- exclude?: boolean;
502
- }>;
503
- /**
504
- * The used URL patterns.
505
- *
506
- * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
507
- */
508
- export const urlPatterns: Array<{
509
- pattern: string;
510
- localized: Array<[Locale, string]>;
511
- }>;
512
- /**
513
- * @typedef {{
514
- * getStore(): {
515
- * locale?: Locale,
516
- * origin?: string,
517
- * messageCalls?: Set<string>
518
- * } | undefined,
519
- * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set<string>},
520
- * cb: any) => any
521
- * }} ParaglideAsyncLocalStorage
522
- */
523
- /**
524
- * Server side async local storage that is set by `serverMiddleware()`.
525
- *
526
- * The variable is used to retrieve the locale and origin in a server-side
527
- * rendering context without effecting other requests.
528
- *
529
- * @type {ParaglideAsyncLocalStorage | undefined}
530
- */
531
- export let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
532
- export const disableAsyncLocalStorage: false;
533
- export const experimentalMiddlewareLocaleSplitting: false;
534
- export const isServer: boolean;
535
- /** @type {Locale | undefined} */
536
- export const experimentalStaticLocale: Locale | undefined;
537
- export function getLocale(): Locale;
538
- export function overwriteGetLocale(fn: () => Locale): void;
539
- /**
540
- * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
541
- */
542
- /**
543
- * Set the locale.
544
- *
545
- * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
546
- * By default, this reloads the page on the client to reflect the new locale. Reloading
547
- * can be disabled by passing `reload: false` as an option, but you'll need to ensure
548
- * the UI updates to reflect the new locale.
549
- *
550
- * If any custom strategy's `setLocale` function is async, then this function
551
- * will become async as well.
552
- *
553
- * @see https://paraglidejs.com/strategy
554
- *
555
- * @example
556
- * setLocale('en');
557
- *
558
- * @example
559
- * setLocale('en', { reload: false });
560
- *
561
- * @type {SetLocaleFn}
562
- */
563
- export let setLocale: SetLocaleFn;
564
- export function overwriteSetLocale(fn: SetLocaleFn): void;
565
- /**
566
- * The origin of the current URL.
567
- *
568
- * Defaults to "http://y.com" in non-browser environments. If this
569
- * behavior is not desired, the implementation can be overwritten
570
- * by `overwriteGetUrlOrigin()`.
571
- *
572
- * @type {() => string}
573
- */
574
- export let getUrlOrigin: () => string;
575
- export function overwriteGetUrlOrigin(fn: () => string): void;
576
- export function extractLocaleFromRequest(request: Request, options?: ExtractLocaleFromRequestOptions): Locale;
577
- export function extractLocaleFromRequestWithStrategies(request: Request, strategies: typeof strategy, url?: string | URL): Locale;
578
- export function extractLocaleFromRequestAsync(request: Request, options?: {
579
- effectiveRequestUrl?: string | URL;
580
- }): Promise<Locale>;
581
- /**
582
- * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
776
+ * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
583
777
  */
584
778
  /**
585
779
  * @typedef {`custom_${string}`} CustomStrategy
@@ -597,124 +791,60 @@ export function extractLocaleFromRequestAsync(request: Request, options?: {
597
791
  * @typedef {{ getLocale: () => Promise<string|undefined> | (string | undefined), setLocale: (locale: string) => Promise<void> | void }} CustomClientStrategyHandler
598
792
  */
599
793
  /** @type {Map<string, CustomServerStrategyHandler>} */
600
- export const customServerStrategies: Map<string, CustomServerStrategyHandler>;
794
+ export declare const customServerStrategies: Map<string, CustomServerStrategyHandler>;
601
795
  /** @type {Map<string, CustomClientStrategyHandler>} */
602
- export const customClientStrategies: Map<string, CustomClientStrategyHandler>;
603
- export type ShouldRedirectServerInput = {
604
- request: Request;
605
- /**
606
- * - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
607
- */
608
- effectiveRequestUrl?: string | URL;
609
- locale?: Locale;
610
- };
611
- export type ShouldRedirectClientInput = {
612
- request?: undefined;
613
- url?: string | URL;
614
- locale?: Locale;
615
- };
616
- export type ShouldRedirectInput = ShouldRedirectServerInput | ShouldRedirectClientInput;
617
- export type ShouldRedirectResult = {
618
- /**
619
- * - Indicates whether the consumer should perform a redirect.
620
- */
621
- shouldRedirect: boolean;
622
- /**
623
- * - Locale resolved using the configured strategies.
624
- */
625
- locale: Locale;
626
- /**
627
- * - Destination URL when a redirect is required.
628
- */
629
- redirectUrl: URL | undefined;
630
- };
631
- export type ParaglideAsyncLocalStorage = {
632
- getStore(): {
633
- locale?: Locale;
634
- origin?: string;
635
- messageCalls?: Set<string>;
636
- } | undefined;
637
- run: (store: {
638
- locale?: Locale;
639
- origin?: string;
640
- messageCalls?: Set<string>;
641
- }, cb: any) => any;
642
- };
643
- export type SetLocaleFn = (newLocale: Locale, options?: {
644
- reload?: boolean;
645
- }) => void | Promise<void>;
646
- export type ExtractLocaleFromRequestOptions = {
647
- /**
648
- * - Effective request URL to use for route matching and locale detection with the URL strategy.
649
- */
650
- effectiveRequestUrl?: string | URL;
651
- };
652
- export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage";
653
- export type CustomStrategy = `custom_${string}`;
654
- export type Strategy = BuiltInStrategy | CustomStrategy;
655
- export type Strategies = Array<Strategy>;
656
- export type CustomServerStrategyHandler = {
657
- getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined);
658
- };
659
- export type CustomClientStrategyHandler = {
660
- getLocale: () => Promise<string | undefined> | (string | undefined);
661
- setLocale: (locale: string) => Promise<void> | void;
662
- };
796
+ export declare const customClientStrategies: Map<string, CustomClientStrategyHandler>;
663
797
  /**
664
- * A locale that is available in the project.
798
+ * Checks if the given strategy is a custom strategy.
799
+ *
800
+ * @param {unknown} strategy The name of the custom strategy to validate.
801
+ * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
802
+ * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
665
803
  */
666
- export type Locale = (typeof locales)[number];
804
+ export declare function isCustomStrategy(strategy: unknown): boolean;
667
805
  /**
668
- * A branded type representing a localized string.
806
+ * Defines a custom strategy that is executed on the server.
669
807
  *
670
- * Message functions return this type instead of \`string\`, enabling TypeScript
671
- * to distinguish translated strings from regular strings at compile time.
672
- * This allows you to enforce that only properly localized content is used
673
- * in your UI components.
808
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
674
809
  *
675
- * Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
676
- * backward compatible—you can pass it anywhere a \`string\` is expected.
810
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
811
+ * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
812
+ * the method getLocale.
813
+ * @returns {void}
677
814
  */
678
- export type LocalizedString = string & {
679
- readonly __brand: "LocalizedString";
680
- };
815
+ export declare function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void;
681
816
  /**
682
- * A single markup option passed to a tag instance.
817
+ * Defines a custom strategy that is executed on the client.
818
+ *
819
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
820
+ *
821
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
822
+ * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
823
+ * methods getLocale and setLocale.
824
+ * @returns {void}
683
825
  */
826
+ export declare function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void;
827
+ export {};
828
+ export type Locale = typeof locales[number];
829
+ export type LocalizedString = string & {
830
+ readonly __brand: 'LocalizedString';
831
+ };
684
832
  export type MessageMarkupOption = {
685
833
  name: string;
686
834
  value: unknown;
687
835
  };
688
- /**
689
- * A single static markup attribute attached to a tag instance.
690
- */
691
836
  export type MessageMarkupAttribute = {
692
837
  name: string;
693
838
  value: string | true;
694
839
  };
695
- /**
696
- * Record of markup options for a tag instance.
697
- */
698
840
  export type MessageMarkupOptions = Record<string, unknown>;
699
- /**
700
- * Record of markup attributes for a tag instance.
701
- */
702
841
  export type MessageMarkupAttributes = Record<string, string | true>;
703
- /**
704
- * Type-level schema for a single markup tag.
705
- */
706
842
  export type MessageMarkupTag = {
707
843
  options: MessageMarkupOptions;
708
844
  attributes: MessageMarkupAttributes;
709
845
  children: boolean;
710
846
  };
711
- /**
712
- * Type-level schema for all markup tags in a message.
713
- */
714
847
  export type MessageMarkupSchema = Record<string, MessageMarkupTag>;
715
- /**
716
- * Type-only metadata attached to compiled message functions.
717
- */
718
848
  export type MessageMetadata<Inputs, Options, Markup extends MessageMarkupSchema = MessageMarkupSchema> = {
719
849
  readonly __paraglide?: {
720
850
  inputs: Inputs;
@@ -722,9 +852,6 @@ export type MessageMetadata<Inputs, Options, Markup extends MessageMarkupSchema
722
852
  markup: Markup;
723
853
  };
724
854
  };
725
- /**
726
- * A compiled, framework-neutral message part.
727
- */
728
855
  export type MessagePart = {
729
856
  type: "text";
730
857
  value: string;
@@ -744,15 +871,153 @@ export type MessagePart = {
744
871
  options: MessageMarkupOptions;
745
872
  attributes: MessageMarkupAttributes;
746
873
  };
874
+ export type MessageFunction = (inputs?: Record<string, never>) => LocalizedString;
875
+ export type MessageBundleFunction<T extends string> = (params: Record<string, never>, options: {
876
+ locale: T;
877
+ }) => LocalizedString;
878
+ /**
879
+ * A locale that is available in the project.
880
+ *
881
+ * @example
882
+ * setLocale(request.locale as Locale)
883
+ *
884
+ * @typedef {typeof locales[number]} Locale
885
+ */
886
+ /**
887
+ * A branded type representing a localized string.
888
+ *
889
+ * Message functions return this type instead of \`string\`, enabling TypeScript
890
+ * to distinguish translated strings from regular strings at compile time.
891
+ * This allows you to enforce that only properly localized content is used
892
+ * in your UI components.
893
+ *
894
+ * Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
895
+ * backward compatible—you can pass it anywhere a \`string\` is expected.
896
+ *
897
+ * @example
898
+ * // Enforce localized strings in your components
899
+ * function PageTitle(props: { title: LocalizedString }) {
900
+ * return <h1>{props.title}</h1>
901
+ * }
902
+ *
903
+ * // ✅ Correct: using a message function
904
+ * <PageTitle title={m.welcome_title()} />
905
+ *
906
+ * // ❌ Type error: raw strings are not LocalizedString
907
+ * <PageTitle title="Welcome" />
908
+ *
909
+ * @example
910
+ * // LocalizedString is assignable to string (backward compatible)
911
+ * const localized: LocalizedString = m.greeting()
912
+ * const str: string = localized // ✅ works fine
913
+ *
914
+ * // But string is not assignable to LocalizedString
915
+ * const raw: LocalizedString = "Hello" // ❌ Type error
916
+ *
917
+ * @example
918
+ * // Catches accidental string concatenation
919
+ * function showMessage(msg: LocalizedString) { ... }
920
+ *
921
+ * showMessage(m.hello()) // ✅
922
+ * showMessage("Hello " + userName) // ❌ Type error
923
+ * showMessage(m.hello_user({ name: userName })) // ✅ use params instead
924
+ *
925
+ * @typedef {string & { readonly __brand: 'LocalizedString' }} LocalizedString
926
+ */
927
+ /**
928
+ * A single markup option passed to a tag instance.
929
+ *
930
+ * @typedef {{
931
+ * name: string;
932
+ * value: unknown;
933
+ * }} MessageMarkupOption
934
+ */
935
+ /**
936
+ * A single static markup attribute attached to a tag instance.
937
+ *
938
+ * @typedef {{
939
+ * name: string;
940
+ * value: string | true;
941
+ * }} MessageMarkupAttribute
942
+ */
943
+ /**
944
+ * Record of markup options for a tag instance.
945
+ *
946
+ * @typedef {Record<string, unknown>} MessageMarkupOptions
947
+ */
948
+ /**
949
+ * Record of markup attributes for a tag instance.
950
+ *
951
+ * @typedef {Record<string, string | true>} MessageMarkupAttributes
952
+ */
953
+ /**
954
+ * Type-level schema for a single markup tag.
955
+ *
956
+ * @typedef {{
957
+ * options: MessageMarkupOptions;
958
+ * attributes: MessageMarkupAttributes;
959
+ * children: boolean;
960
+ * }} MessageMarkupTag
961
+ */
962
+ /**
963
+ * Type-level schema for all markup tags in a message.
964
+ *
965
+ * @typedef {Record<string, MessageMarkupTag>} MessageMarkupSchema
966
+ */
967
+ /**
968
+ * Type-only metadata attached to compiled message functions.
969
+ *
970
+ * @template Inputs
971
+ * @template Options
972
+ * @template {MessageMarkupSchema} [Markup = MessageMarkupSchema]
973
+ * @typedef {{
974
+ * readonly __paraglide?: {
975
+ * inputs: Inputs;
976
+ * options: Options;
977
+ * markup: Markup;
978
+ * };
979
+ * }} MessageMetadata
980
+ */
981
+ /**
982
+ * A compiled, framework-neutral message part.
983
+ *
984
+ * @typedef {{
985
+ * type: "text";
986
+ * value: string;
987
+ * } | {
988
+ * type: "markup-start";
989
+ * name: string;
990
+ * options: MessageMarkupOptions;
991
+ * attributes: MessageMarkupAttributes;
992
+ * } | {
993
+ * type: "markup-end";
994
+ * name: string;
995
+ * options: MessageMarkupOptions;
996
+ * attributes: MessageMarkupAttributes;
997
+ * } | {
998
+ * type: "markup-standalone";
999
+ * name: string;
1000
+ * options: MessageMarkupOptions;
1001
+ * attributes: MessageMarkupAttributes;
1002
+ * }} MessagePart
1003
+ */
747
1004
  /**
748
1005
  * A message function is a message for a specific locale.
1006
+ *
1007
+ * @example
1008
+ * m.hello({ name: 'world' })
1009
+ *
1010
+ * @typedef {(inputs?: Record<string, never>) => LocalizedString} MessageFunction
749
1011
  */
750
- export type MessageFunction = (inputs?: Record<string, never>) => LocalizedString;
751
1012
  /**
752
1013
  * A message bundle function that selects the message to be returned.
753
1014
  *
754
1015
  * Uses `getLocale()` under the hood to determine the locale with an option.
1016
+ *
1017
+ * @template {string} T
1018
+ *
1019
+ * @example
1020
+ * * m.hello({ name: 'world' }, { locale: "en" })
1021
+ *
1022
+ * @typedef {(params: Record<string, never>, options: { locale: T }) => LocalizedString} MessageBundleFunction
755
1023
  */
756
- export type MessageBundleFunction<T extends string> = (params: Record<string, never>, options: {
757
- locale: T;
758
- }) => LocalizedString;