tera-system-ui 0.1.50 → 0.1.63
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/dist/components/accordion/Accordion.d.ts +15 -13
- package/dist/components/accordion/index.d.ts +1 -0
- package/dist/components/avatar/Avatar.d.ts +5 -3
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/brand-logo/BrandLogo.d.ts +7 -4
- package/dist/components/brand-logo/BrandLogo.js +1 -1
- package/dist/components/brand-logo/index.d.ts +1 -0
- package/dist/components/button/Button.d.ts +58 -14
- package/dist/components/button/Button.js +90 -27
- package/dist/components/button/Button.svelte +35 -30
- package/dist/components/button/Button.svelte.d.ts +1 -4
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/checkbox/Checkbox.d.ts +5 -2
- package/dist/components/checkbox/Checkbox.svelte +15 -8
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/combobox/Combobox.d.ts +5 -2
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/dialog/Dialog.d.ts +8 -6
- package/dist/components/dialog/Dialog.svelte +1 -1
- package/dist/components/dialog/index.d.ts +1 -0
- package/dist/components/dropdown-menu/DropdownMenu.d.ts +26 -8
- package/dist/components/dropdown-menu/index.d.ts +1 -0
- package/dist/components/header/Header.d.ts +6 -3
- package/dist/components/header/Header.svelte.d.ts +1 -1
- package/dist/components/header/index.d.ts +1 -0
- package/dist/components/input/Input.d.ts +22 -6
- package/dist/components/input/Input.js +19 -10
- package/dist/components/input/Input.svelte +42 -9
- package/dist/components/input/index.d.ts +1 -0
- package/dist/components/label/Label.d.ts +33 -3
- package/dist/components/label/Label.js +14 -3
- package/dist/components/label/Label.svelte +7 -7
- package/dist/components/label/Label.svelte.d.ts +2 -2
- package/dist/components/label/index.d.ts +1 -0
- package/dist/components/language-picker-button/LanguagePickerButton.d.ts +5 -2
- package/dist/components/language-picker-button/index.d.ts +1 -0
- package/dist/components/light-dark-toggle/LightDarkToggle.d.ts +5 -2
- package/dist/components/light-dark-toggle/index.d.ts +1 -0
- package/dist/components/popover/Popover.d.ts +6 -3
- package/dist/components/popover/Popover.js +0 -1
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover-responsive/PopoverResponsive.d.ts +5 -2
- package/dist/components/popover-responsive/index.d.ts +1 -0
- package/dist/components/select/Select.d.ts +19 -5
- package/dist/components/select/Select.js +18 -9
- package/dist/components/select/Select.svelte +17 -4
- package/dist/components/select/Select.svelte.d.ts +1 -1
- package/dist/components/select/index.d.ts +1 -0
- package/dist/components/side-navigation/SideNavigation.d.ts +6 -3
- package/dist/components/side-navigation/index.d.ts +1 -1
- package/dist/components/slider/Slider.d.ts +7 -4
- package/dist/components/slider/Slider.svelte +27 -52
- package/dist/components/slider/index.d.ts +1 -0
- package/dist/components/star-rating/StarRating.d.ts +5 -2
- package/dist/components/star-rating/StarRating.svelte +5 -5
- package/dist/components/star-rating/index.d.ts +1 -0
- package/dist/components/switch/Switch.d.ts +6 -2
- package/dist/components/switch/Switch.svelte +13 -7
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/tabs/Tabs.svelte.d.ts +23 -3
- package/dist/components/tabs/index.d.ts +1 -0
- package/dist/components/tera-ui-context/TeraUiContext.d.ts +4 -6
- package/dist/components/tera-ui-context/TeraUiContext.svelte +0 -2
- package/dist/components/tera-ui-context/index.d.ts +1 -0
- package/dist/components/text-area/TextArea.d.ts +22 -8
- package/dist/components/text-area/TextArea.js +19 -10
- package/dist/components/text-area/TextArea.svelte +35 -29
- package/dist/components/text-area/index.d.ts +1 -0
- package/dist/components/user-avatar-with-menu/UserAvatarWithMenu.d.ts +5 -2
- package/dist/components/user-avatar-with-menu/index.d.ts +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/paraglide/README.md +93 -0
- package/dist/paraglide/messages/_index.d.ts +22 -7
- package/dist/paraglide/messages/_index.js +487 -8
- package/dist/paraglide/messages/ar.d.ts +9 -0
- package/dist/paraglide/messages/ar.js +31 -0
- package/dist/paraglide/messages/bg.d.ts +9 -0
- package/dist/paraglide/messages/bg.js +31 -0
- package/dist/paraglide/messages/bn.d.ts +9 -0
- package/dist/paraglide/messages/bn.js +31 -0
- package/dist/paraglide/messages/ca.d.ts +9 -0
- package/dist/paraglide/messages/ca.js +31 -0
- package/dist/paraglide/messages/cs.d.ts +9 -0
- package/dist/paraglide/messages/cs.js +31 -0
- package/dist/paraglide/messages/da.d.ts +9 -0
- package/dist/paraglide/messages/da.js +31 -0
- package/dist/paraglide/messages/de.d.ts +9 -0
- package/dist/paraglide/messages/de.js +31 -0
- package/dist/paraglide/messages/el.d.ts +9 -0
- package/dist/paraglide/messages/el.js +31 -0
- package/dist/paraglide/messages/en.d.ts +9 -0
- package/dist/paraglide/messages/en.js +31 -0
- package/dist/paraglide/messages/es.d.ts +9 -0
- package/dist/paraglide/messages/es.js +31 -0
- package/dist/paraglide/messages/fi.d.ts +9 -0
- package/dist/paraglide/messages/fi.js +31 -0
- package/dist/paraglide/messages/fr.d.ts +9 -0
- package/dist/paraglide/messages/fr.js +31 -0
- package/dist/paraglide/messages/he.d.ts +9 -0
- package/dist/paraglide/messages/he.js +31 -0
- package/dist/paraglide/messages/hi.d.ts +9 -0
- package/dist/paraglide/messages/hi.js +31 -0
- package/dist/paraglide/messages/hu.d.ts +9 -0
- package/dist/paraglide/messages/hu.js +31 -0
- package/dist/paraglide/messages/id.d.ts +9 -0
- package/dist/paraglide/messages/id.js +31 -0
- package/dist/paraglide/messages/it.d.ts +9 -0
- package/dist/paraglide/messages/it.js +31 -0
- package/dist/paraglide/messages/ja.d.ts +9 -0
- package/dist/paraglide/messages/ja.js +31 -0
- package/dist/paraglide/messages/ko.d.ts +9 -0
- package/dist/paraglide/messages/ko.js +31 -0
- package/dist/paraglide/messages/lt.d.ts +9 -0
- package/dist/paraglide/messages/lt.js +31 -0
- package/dist/paraglide/messages/lv.d.ts +9 -0
- package/dist/paraglide/messages/lv.js +31 -0
- package/dist/paraglide/messages/ms.d.ts +9 -0
- package/dist/paraglide/messages/ms.js +31 -0
- package/dist/paraglide/messages/nl.d.ts +9 -0
- package/dist/paraglide/messages/nl.js +31 -0
- package/dist/paraglide/messages/no.d.ts +9 -0
- package/dist/paraglide/messages/no.js +31 -0
- package/dist/paraglide/messages/pl.d.ts +9 -0
- package/dist/paraglide/messages/pl.js +31 -0
- package/dist/paraglide/messages/pt.d.ts +9 -0
- package/dist/paraglide/messages/pt.js +31 -0
- package/dist/paraglide/messages/ro.d.ts +9 -0
- package/dist/paraglide/messages/ro.js +31 -0
- package/dist/paraglide/messages/ru.d.ts +9 -0
- package/dist/paraglide/messages/ru.js +31 -0
- package/dist/paraglide/messages/sk.d.ts +9 -0
- package/dist/paraglide/messages/sk.js +31 -0
- package/dist/paraglide/messages/sl.d.ts +9 -0
- package/dist/paraglide/messages/sl.js +31 -0
- package/dist/paraglide/messages/sq.d.ts +9 -0
- package/dist/paraglide/messages/sq.js +31 -0
- package/dist/paraglide/messages/sr.d.ts +9 -0
- package/dist/paraglide/messages/sr.js +31 -0
- package/dist/paraglide/messages/sv.d.ts +9 -0
- package/dist/paraglide/messages/sv.js +31 -0
- package/dist/paraglide/messages/sw.d.ts +9 -0
- package/dist/paraglide/messages/sw.js +31 -0
- package/dist/paraglide/messages/ta.d.ts +9 -0
- package/dist/paraglide/messages/ta.js +31 -0
- package/dist/paraglide/messages/te.d.ts +9 -0
- package/dist/paraglide/messages/te.js +31 -0
- package/dist/paraglide/messages/th.d.ts +9 -0
- package/dist/paraglide/messages/th.js +31 -0
- package/dist/paraglide/messages/tl.d.ts +9 -0
- package/dist/paraglide/messages/tl.js +31 -0
- package/dist/paraglide/messages/tr.d.ts +9 -0
- package/dist/paraglide/messages/tr.js +31 -0
- package/dist/paraglide/messages/uk.d.ts +9 -0
- package/dist/paraglide/messages/uk.js +31 -0
- package/dist/paraglide/messages/vi.d.ts +9 -0
- package/dist/paraglide/messages/vi.js +31 -0
- package/dist/paraglide/messages/zh-CN.d.ts +9 -0
- package/dist/paraglide/messages/zh-CN.js +31 -0
- package/dist/paraglide/messages/zh-TW.d.ts +9 -0
- package/dist/paraglide/messages/zh-TW.js +31 -0
- package/dist/paraglide/messages.js +1 -1
- package/dist/paraglide/registry.js +1 -1
- package/dist/paraglide/runtime.d.ts +221 -45
- package/dist/paraglide/runtime.js +378 -65
- package/dist/paraglide/server.d.ts +40 -4
- package/dist/paraglide/server.js +83 -46
- package/dist/tera-i18n/projects/tera-system-ui/project.inlang/.meta.json +3 -0
- package/dist/tera-i18n/projects/tera-system-ui/project.inlang/README.md +103 -0
- package/dist/themes/tera-ui-base.css +70 -7
- package/dist/types/index.d.ts +25 -0
- package/dist/types/index.js +3 -0
- package/package.json +150 -36
- package/scripts/add-component-template.js +1 -1
- package/scripts/generate-ts-index.js +38 -12
- package/dist/paraglide/messages/text_account_settings.d.ts +0 -3
- package/dist/paraglide/messages/text_account_settings.js +0 -238
- package/dist/paraglide/messages/text_calces_documentation.d.ts +0 -3
- package/dist/paraglide/messages/text_calces_documentation.js +0 -238
- package/dist/paraglide/messages/text_calces_scientific_calculator.d.ts +0 -3
- package/dist/paraglide/messages/text_calces_scientific_calculator.js +0 -238
- package/dist/paraglide/messages/text_currency_converter.d.ts +0 -3
- package/dist/paraglide/messages/text_currency_converter.js +0 -238
- package/dist/paraglide/messages/text_logout.d.ts +0 -3
- package/dist/paraglide/messages/text_logout.js +0 -238
- package/dist/paraglide/messages/text_select_language.d.ts +0 -3
- package/dist/paraglide/messages/text_select_language.js +0 -238
- package/dist/paraglide/messages/text_unit_converter.d.ts +0 -3
- package/dist/paraglide/messages/text_unit_converter.js +0 -238
|
@@ -59,6 +59,8 @@ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
|
|
|
59
59
|
* For client-side UI components, use `localizeHref()` instead, which provides
|
|
60
60
|
* a more convenient API with relative paths and automatic locale detection.
|
|
61
61
|
*
|
|
62
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
|
|
63
|
+
*
|
|
62
64
|
* @example
|
|
63
65
|
* ```typescript
|
|
64
66
|
* // Server middleware example
|
|
@@ -104,6 +106,8 @@ export function localizeUrl(url: string | URL, options?: {
|
|
|
104
106
|
* For client-side UI components, use `deLocalizeHref()` instead, which provides
|
|
105
107
|
* a more convenient API with relative paths.
|
|
106
108
|
*
|
|
109
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
|
|
110
|
+
*
|
|
107
111
|
* @example
|
|
108
112
|
* ```typescript
|
|
109
113
|
* // Server middleware example
|
|
@@ -133,6 +137,61 @@ export function localizeUrl(url: string | URL, options?: {
|
|
|
133
137
|
*/
|
|
134
138
|
export function deLocalizeUrl(url: string | URL): URL;
|
|
135
139
|
export function aggregateGroups(match: any): Record<string, string | null | undefined>;
|
|
140
|
+
/**
|
|
141
|
+
* @typedef {object} ShouldRedirectServerInput
|
|
142
|
+
* @property {Request} request
|
|
143
|
+
* @property {string | URL} [url]
|
|
144
|
+
* @property {ReturnType<typeof assertIsLocale>} [locale]
|
|
145
|
+
*
|
|
146
|
+
* @typedef {object} ShouldRedirectClientInput
|
|
147
|
+
* @property {undefined} [request]
|
|
148
|
+
* @property {string | URL} [url]
|
|
149
|
+
* @property {ReturnType<typeof assertIsLocale>} [locale]
|
|
150
|
+
*
|
|
151
|
+
* @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
|
|
152
|
+
*
|
|
153
|
+
* @typedef {object} ShouldRedirectResult
|
|
154
|
+
* @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
|
|
155
|
+
* @property {ReturnType<typeof assertIsLocale>} locale - Locale resolved using the configured strategies.
|
|
156
|
+
* @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* Determines whether a redirect is required to align the current URL with the active locale.
|
|
160
|
+
*
|
|
161
|
+
* This helper mirrors the logic that powers `paraglideMiddleware`, but works in both server
|
|
162
|
+
* and client environments. It evaluates the configured strategies in order, computes the
|
|
163
|
+
* canonical localized URL, and reports when the current URL does not match.
|
|
164
|
+
*
|
|
165
|
+
* When called in the browser without arguments, the current `window.location.href` is used.
|
|
166
|
+
*
|
|
167
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing#client-side-redirects
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* // Client side usage (e.g. TanStack Router beforeLoad hook)
|
|
171
|
+
* async function beforeLoad({ location }) {
|
|
172
|
+
* const decision = await shouldRedirect({ url: location.href });
|
|
173
|
+
*
|
|
174
|
+
* if (decision.shouldRedirect) {
|
|
175
|
+
* throw redirect({ to: decision.redirectUrl.href });
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* // Server side usage with a Request
|
|
181
|
+
* export async function handle(request) {
|
|
182
|
+
* const decision = await shouldRedirect({ request });
|
|
183
|
+
*
|
|
184
|
+
* if (decision.shouldRedirect) {
|
|
185
|
+
* return Response.redirect(decision.redirectUrl, 307);
|
|
186
|
+
* }
|
|
187
|
+
*
|
|
188
|
+
* return render(request, decision.locale);
|
|
189
|
+
* }
|
|
190
|
+
*
|
|
191
|
+
* @param {ShouldRedirectInput} [input]
|
|
192
|
+
* @returns {Promise<ShouldRedirectResult>}
|
|
193
|
+
*/
|
|
194
|
+
export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedirectResult>;
|
|
136
195
|
/**
|
|
137
196
|
* High-level URL localization function optimized for client-side UI usage.
|
|
138
197
|
*
|
|
@@ -144,6 +203,8 @@ export function aggregateGroups(match: any): Record<string, string | null | unde
|
|
|
144
203
|
* - Automatically detects current locale if not specified
|
|
145
204
|
* - Handles string input/output instead of URL objects
|
|
146
205
|
*
|
|
206
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
|
|
207
|
+
*
|
|
147
208
|
* @example
|
|
148
209
|
* ```typescript
|
|
149
210
|
* // In a React/Vue/Svelte component
|
|
@@ -184,6 +245,8 @@ export function localizeHref(href: string, options?: {
|
|
|
184
245
|
* - Returns relative paths when possible
|
|
185
246
|
* - Handles string input/output instead of URL objects
|
|
186
247
|
*
|
|
248
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
|
|
249
|
+
*
|
|
187
250
|
* @example
|
|
188
251
|
* ```typescript
|
|
189
252
|
* // In a React/Vue/Svelte component
|
|
@@ -211,7 +274,6 @@ export function localizeHref(href: string, options?: {
|
|
|
211
274
|
*
|
|
212
275
|
* @param {string} href - The href to de-localize (can be relative or absolute)
|
|
213
276
|
* @returns {string} The de-localized href, relative if input was relative
|
|
214
|
-
* @see deLocalizeUrl - For low-level URL de-localization in server contexts
|
|
215
277
|
*/
|
|
216
278
|
export function deLocalizeHref(href: string): string;
|
|
217
279
|
/**
|
|
@@ -220,53 +282,76 @@ export function deLocalizeHref(href: string): string;
|
|
|
220
282
|
*/
|
|
221
283
|
export function trackMessageCall(safeModuleId: string, locale: Locale): void;
|
|
222
284
|
/**
|
|
223
|
-
* Generates
|
|
285
|
+
* Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
|
|
224
286
|
*
|
|
225
|
-
* This is
|
|
226
|
-
*
|
|
287
|
+
* This function is essential for Static Site Generation (SSG) where you need to tell your framework
|
|
288
|
+
* which pages to pre-render at build time. It's also useful for generating sitemaps and
|
|
289
|
+
* `<link rel="alternate" hreflang>` tags for SEO.
|
|
290
|
+
*
|
|
291
|
+
* The function respects your `urlPatterns` configuration - if you have translated pathnames
|
|
292
|
+
* (e.g., `/about` → `/ueber-uns` for German), it will generate the correct localized paths.
|
|
293
|
+
*
|
|
294
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/static-site-generation
|
|
227
295
|
*
|
|
228
296
|
* @example
|
|
229
|
-
*
|
|
230
|
-
* const
|
|
231
|
-
* "
|
|
232
|
-
* "
|
|
297
|
+
* // Basic usage - generate all locale variants for a list of paths
|
|
298
|
+
* const localizedUrls = generateStaticLocalizedUrls([
|
|
299
|
+
* "/",
|
|
300
|
+
* "/about",
|
|
301
|
+
* "/blog/post-1",
|
|
233
302
|
* ]);
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
303
|
+
* // Returns URL objects for each locale:
|
|
304
|
+
* // ["/en/", "/de/", "/en/about", "/de/about", "/en/blog/post-1", "/de/blog/post-1"]
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* // Use with framework SSG APIs
|
|
308
|
+
* // SvelteKit
|
|
309
|
+
* export function entries() {
|
|
310
|
+
* const paths = ["/", "/about", "/contact"];
|
|
311
|
+
* return generateStaticLocalizedUrls(paths).map(url => ({
|
|
312
|
+
* locale: extractLocaleFromUrl(url)
|
|
313
|
+
* }));
|
|
314
|
+
* }
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* // Sitemap generation
|
|
318
|
+
* const allPages = ["/", "/about", "/blog"];
|
|
319
|
+
* const sitemapUrls = generateStaticLocalizedUrls(allPages);
|
|
240
320
|
*
|
|
241
|
-
* @param {(string | URL)[]} urls - List of URLs to generate localized versions for.
|
|
242
|
-
*
|
|
321
|
+
* @param {(string | URL)[]} urls - List of canonical URLs or paths to generate localized versions for.
|
|
322
|
+
* Can be absolute URLs (`https://example.com/about`) or paths (`/about`).
|
|
323
|
+
* Paths are resolved against `http://localhost` internally.
|
|
324
|
+
* @returns {URL[]} Array of URL objects representing all localized variants.
|
|
325
|
+
* The order follows each input URL with all its locale variants before moving to the next URL.
|
|
243
326
|
*/
|
|
244
327
|
export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
|
|
245
328
|
/**
|
|
246
329
|
* Checks if the given strategy is a custom strategy.
|
|
247
330
|
*
|
|
248
331
|
* @param {any} strategy The name of the custom strategy to validate.
|
|
249
|
-
* Must be a string that starts with "custom-" followed by alphanumeric characters.
|
|
332
|
+
* Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
|
|
250
333
|
* @returns {boolean} Returns true if it is a custom strategy, false otherwise.
|
|
251
334
|
*/
|
|
252
335
|
export function isCustomStrategy(strategy: any): boolean;
|
|
253
336
|
/**
|
|
254
337
|
* Defines a custom strategy that is executed on the server.
|
|
255
338
|
*
|
|
256
|
-
* @
|
|
257
|
-
*
|
|
339
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
|
|
340
|
+
*
|
|
341
|
+
* @param {any} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
|
|
258
342
|
* @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
|
|
259
|
-
* the method
|
|
343
|
+
* the method getLocale.
|
|
260
344
|
* @returns {void}
|
|
261
345
|
*/
|
|
262
346
|
export function defineCustomServerStrategy(strategy: any, handler: CustomServerStrategyHandler): void;
|
|
263
347
|
/**
|
|
264
348
|
* Defines a custom strategy that is executed on the client.
|
|
265
349
|
*
|
|
266
|
-
* @
|
|
267
|
-
*
|
|
350
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
|
|
351
|
+
*
|
|
352
|
+
* @param {any} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
|
|
268
353
|
* @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
|
|
269
|
-
* methods
|
|
354
|
+
* methods getLocale and setLocale.
|
|
270
355
|
* @returns {void}
|
|
271
356
|
*/
|
|
272
357
|
export function defineCustomClientStrategy(strategy: any, handler: CustomClientStrategyHandler): void;
|
|
@@ -332,9 +417,17 @@ export let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
|
|
|
332
417
|
export const disableAsyncLocalStorage: false;
|
|
333
418
|
export const experimentalMiddlewareLocaleSplitting: false;
|
|
334
419
|
export const isServer: any;
|
|
420
|
+
/** @type {Locale | undefined} */
|
|
421
|
+
export const experimentalStaticLocale: Locale | undefined;
|
|
335
422
|
/**
|
|
336
423
|
* Get the current locale.
|
|
337
424
|
*
|
|
425
|
+
* The locale is resolved using your configured strategies (URL, cookie, localStorage, etc.)
|
|
426
|
+
* in the order they are defined. In SSR contexts, the locale is retrieved from AsyncLocalStorage
|
|
427
|
+
* which is set by the `paraglideMiddleware()`.
|
|
428
|
+
*
|
|
429
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy - Configure locale detection strategies
|
|
430
|
+
*
|
|
338
431
|
* @example
|
|
339
432
|
* if (getLocale() === 'de') {
|
|
340
433
|
* console.log('Germany 🇩🇪');
|
|
@@ -346,28 +439,36 @@ export const isServer: any;
|
|
|
346
439
|
*/
|
|
347
440
|
export let getLocale: () => Locale;
|
|
348
441
|
/**
|
|
349
|
-
* Overwrite the
|
|
442
|
+
* Overwrite the `getLocale()` function.
|
|
350
443
|
*
|
|
351
|
-
* Use this function to overwrite how the locale is resolved.
|
|
352
|
-
*
|
|
353
|
-
*
|
|
444
|
+
* Use this function to overwrite how the locale is resolved. This is useful
|
|
445
|
+
* for custom locale resolution or advanced use cases like SSG with concurrent rendering.
|
|
446
|
+
*
|
|
447
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy
|
|
354
448
|
*
|
|
355
449
|
* @example
|
|
356
450
|
* overwriteGetLocale(() => {
|
|
357
|
-
* // resolve the locale from a cookie. fallback to the base locale.
|
|
358
451
|
* return Cookies.get('locale') ?? baseLocale
|
|
359
|
-
* }
|
|
452
|
+
* });
|
|
360
453
|
*
|
|
361
454
|
* @type {(fn: () => Locale) => void}
|
|
362
455
|
*/
|
|
363
456
|
export const overwriteGetLocale: (fn: () => Locale) => void;
|
|
457
|
+
/**
|
|
458
|
+
* @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
|
|
459
|
+
*/
|
|
364
460
|
/**
|
|
365
461
|
* Set the locale.
|
|
366
462
|
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* to reflect the new locale.
|
|
463
|
+
* Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
|
|
464
|
+
* By default, this reloads the page on the client to reflect the new locale. Reloading
|
|
465
|
+
* can be disabled by passing `reload: false` as an option, but you'll need to ensure
|
|
466
|
+
* the UI updates to reflect the new locale.
|
|
467
|
+
*
|
|
468
|
+
* If any custom strategy's `setLocale` function is async, then this function
|
|
469
|
+
* will become async as well.
|
|
470
|
+
*
|
|
471
|
+
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy
|
|
371
472
|
*
|
|
372
473
|
* @example
|
|
373
474
|
* setLocale('en');
|
|
@@ -375,12 +476,10 @@ export const overwriteGetLocale: (fn: () => Locale) => void;
|
|
|
375
476
|
* @example
|
|
376
477
|
* setLocale('en', { reload: false });
|
|
377
478
|
*
|
|
378
|
-
* @type {
|
|
479
|
+
* @type {SetLocaleFn}
|
|
379
480
|
*/
|
|
380
|
-
export let setLocale:
|
|
381
|
-
|
|
382
|
-
}) => void;
|
|
383
|
-
export function overwriteSetLocale(fn: (newLocale: Locale) => void): void;
|
|
481
|
+
export let setLocale: SetLocaleFn;
|
|
482
|
+
export function overwriteSetLocale(fn: SetLocaleFn): void;
|
|
384
483
|
/**
|
|
385
484
|
* The origin of the current URL.
|
|
386
485
|
*
|
|
@@ -410,12 +509,45 @@ export let overwriteGetUrlOrigin: (fn: () => string) => void;
|
|
|
410
509
|
* they are defined. If a strategy returns an invalid locale,
|
|
411
510
|
* it will fall back to the next strategy.
|
|
412
511
|
*
|
|
512
|
+
* Note: Custom server strategies are not supported in this synchronous version.
|
|
513
|
+
* Use `extractLocaleFromRequestAsync` if you need custom server strategies with async getLocale methods.
|
|
514
|
+
*
|
|
413
515
|
* @example
|
|
414
516
|
* const locale = extractLocaleFromRequest(request);
|
|
415
517
|
*
|
|
416
518
|
* @type {(request: Request) => Locale}
|
|
417
519
|
*/
|
|
418
520
|
export const extractLocaleFromRequest: (request: Request) => Locale;
|
|
521
|
+
/**
|
|
522
|
+
* Asynchronously extracts a locale from a request.
|
|
523
|
+
*
|
|
524
|
+
* This function supports async custom server strategies, unlike the synchronous
|
|
525
|
+
* `extractLocaleFromRequest`. Use this function when you have custom server strategies
|
|
526
|
+
* that need to perform asynchronous operations (like database calls) in their getLocale method.
|
|
527
|
+
*
|
|
528
|
+
* The function first processes any custom server strategies asynchronously, then falls back
|
|
529
|
+
* to the synchronous `extractLocaleFromRequest` for all other strategies.
|
|
530
|
+
*
|
|
531
|
+
* @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* // Basic usage
|
|
535
|
+
* const locale = await extractLocaleFromRequestAsync(request);
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* // With custom async server strategy
|
|
539
|
+
* defineCustomServerStrategy("custom-database", {
|
|
540
|
+
* getLocale: async (request) => {
|
|
541
|
+
* const userId = extractUserIdFromRequest(request);
|
|
542
|
+
* return await getUserLocaleFromDatabase(userId);
|
|
543
|
+
* }
|
|
544
|
+
* });
|
|
545
|
+
*
|
|
546
|
+
* const locale = await extractLocaleFromRequestAsync(request);
|
|
547
|
+
*
|
|
548
|
+
* @type {(request: Request) => Promise<Locale>}
|
|
549
|
+
*/
|
|
550
|
+
export const extractLocaleFromRequestAsync: (request: Request) => Promise<Locale>;
|
|
419
551
|
/**
|
|
420
552
|
* @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
|
|
421
553
|
*/
|
|
@@ -429,13 +561,40 @@ export const extractLocaleFromRequest: (request: Request) => Locale;
|
|
|
429
561
|
* @typedef {Array<Strategy>} Strategies
|
|
430
562
|
*/
|
|
431
563
|
/**
|
|
432
|
-
* @typedef {{ getLocale: (request?: Request) => string | undefined }} CustomServerStrategyHandler
|
|
564
|
+
* @typedef {{ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined) }} CustomServerStrategyHandler
|
|
433
565
|
*/
|
|
434
566
|
/**
|
|
435
|
-
* @typedef {{ getLocale: () => string | undefined, setLocale: (locale: string) => void }} CustomClientStrategyHandler
|
|
567
|
+
* @typedef {{ getLocale: () => Promise<string|undefined> | (string | undefined), setLocale: (locale: string) => Promise<void> | void }} CustomClientStrategyHandler
|
|
436
568
|
*/
|
|
437
|
-
|
|
438
|
-
export const
|
|
569
|
+
/** @type {Map<string, CustomServerStrategyHandler>} */
|
|
570
|
+
export const customServerStrategies: Map<string, CustomServerStrategyHandler>;
|
|
571
|
+
/** @type {Map<string, CustomClientStrategyHandler>} */
|
|
572
|
+
export const customClientStrategies: Map<string, CustomClientStrategyHandler>;
|
|
573
|
+
export type ShouldRedirectServerInput = {
|
|
574
|
+
request: Request;
|
|
575
|
+
url?: string | URL | undefined;
|
|
576
|
+
locale?: "id" | "no" | "ar" | "bg" | "bn" | "ca" | "cs" | "da" | "de" | "el" | "en" | "es" | "fi" | "fr" | "he" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "lv" | "ms" | "nl" | "pl" | "pt" | "ro" | "ru" | "sk" | "sl" | "sq" | "sr" | "sv" | "sw" | "ta" | "te" | "th" | "tl" | "tr" | "uk" | "vi" | "zh-CN" | "zh-TW" | undefined;
|
|
577
|
+
};
|
|
578
|
+
export type ShouldRedirectClientInput = {
|
|
579
|
+
request?: undefined;
|
|
580
|
+
url?: string | URL | undefined;
|
|
581
|
+
locale?: "id" | "no" | "ar" | "bg" | "bn" | "ca" | "cs" | "da" | "de" | "el" | "en" | "es" | "fi" | "fr" | "he" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "lv" | "ms" | "nl" | "pl" | "pt" | "ro" | "ru" | "sk" | "sl" | "sq" | "sr" | "sv" | "sw" | "ta" | "te" | "th" | "tl" | "tr" | "uk" | "vi" | "zh-CN" | "zh-TW" | undefined;
|
|
582
|
+
};
|
|
583
|
+
export type ShouldRedirectInput = ShouldRedirectServerInput | ShouldRedirectClientInput;
|
|
584
|
+
export type ShouldRedirectResult = {
|
|
585
|
+
/**
|
|
586
|
+
* - Indicates whether the consumer should perform a redirect.
|
|
587
|
+
*/
|
|
588
|
+
shouldRedirect: boolean;
|
|
589
|
+
/**
|
|
590
|
+
* - Locale resolved using the configured strategies.
|
|
591
|
+
*/
|
|
592
|
+
locale: ReturnType<typeof assertIsLocale>;
|
|
593
|
+
/**
|
|
594
|
+
* - Destination URL when a redirect is required.
|
|
595
|
+
*/
|
|
596
|
+
redirectUrl: URL | undefined;
|
|
597
|
+
};
|
|
439
598
|
export type ParaglideAsyncLocalStorage = {
|
|
440
599
|
getStore(): {
|
|
441
600
|
locale?: Locale;
|
|
@@ -448,18 +607,35 @@ export type ParaglideAsyncLocalStorage = {
|
|
|
448
607
|
messageCalls?: Set<string>;
|
|
449
608
|
}, cb: any) => any;
|
|
450
609
|
};
|
|
610
|
+
export type SetLocaleFn = (newLocale: Locale, options?: {
|
|
611
|
+
reload?: boolean;
|
|
612
|
+
}) => void | Promise<void>;
|
|
451
613
|
export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage";
|
|
452
614
|
export type CustomStrategy = `custom_${string}`;
|
|
453
615
|
export type Strategy = BuiltInStrategy | CustomStrategy;
|
|
454
616
|
export type Strategies = Array<Strategy>;
|
|
455
617
|
export type CustomServerStrategyHandler = {
|
|
456
|
-
getLocale: (request?: Request) => string | undefined;
|
|
618
|
+
getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined);
|
|
457
619
|
};
|
|
458
620
|
export type CustomClientStrategyHandler = {
|
|
459
|
-
getLocale: () => string | undefined;
|
|
460
|
-
setLocale: (locale: string) => void;
|
|
621
|
+
getLocale: () => Promise<string | undefined> | (string | undefined);
|
|
622
|
+
setLocale: (locale: string) => Promise<void> | void;
|
|
461
623
|
};
|
|
462
624
|
/**
|
|
463
625
|
* A locale that is available in the project.
|
|
464
626
|
*/
|
|
465
627
|
export type Locale = (typeof locales)[number];
|
|
628
|
+
/**
|
|
629
|
+
* A branded type representing a localized string.
|
|
630
|
+
*
|
|
631
|
+
* Message functions return this type instead of `string`, enabling TypeScript
|
|
632
|
+
* to distinguish translated strings from regular strings at compile time.
|
|
633
|
+
* This allows you to enforce that only properly localized content is used
|
|
634
|
+
* in your UI components.
|
|
635
|
+
*
|
|
636
|
+
* Since `LocalizedString` is a branded subtype of `string`, it remains fully
|
|
637
|
+
* backward compatible—you can pass it anywhere a `string` is expected.
|
|
638
|
+
*/
|
|
639
|
+
export type LocalizedString = string & {
|
|
640
|
+
readonly __brand: "LocalizedString";
|
|
641
|
+
};
|