@i18n-micro/types 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +69 -2
- package/dist/index.d.ts +69 -2
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -121,6 +121,10 @@ export interface DefineI18nRouteConfig {
|
|
|
121
121
|
export type I18nRouteParams = Record<LocaleCode, Record<string, string>> | null;
|
|
122
122
|
/** Interpolation parameters passed to the `t()` function. */
|
|
123
123
|
export type Params = Record<string, string | number | boolean>;
|
|
124
|
+
/** A list for `{0}`, `{1}`: what `t()` takes besides `Params`. */
|
|
125
|
+
export type ListParams = readonly (string | number | boolean)[];
|
|
126
|
+
/** What `t()` and `interpolate` take: named params or a list. `PluralFunc` keeps `Params`. */
|
|
127
|
+
export type TranslateParams = Params | ListParams;
|
|
124
128
|
/** Getter function signature used by pluralization to resolve nested keys. */
|
|
125
129
|
export type Getter = (key: TranslationKey, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
126
130
|
/**
|
|
@@ -143,6 +147,31 @@ export type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'pre
|
|
|
143
147
|
* Useful for logging, reporting, or providing dynamic fallbacks.
|
|
144
148
|
*/
|
|
145
149
|
export type MissingHandler = (locale: string, key: TranslationKey, routeName: string, instance?: unknown, type?: string) => void;
|
|
150
|
+
/** Attributes of the locale cookie (`localeCookieOptions`). */
|
|
151
|
+
export interface LocaleCookieOptions {
|
|
152
|
+
/** `Domain`: e.g. `.example.com` to share the cookie across subdomains. Unset: the host only. */
|
|
153
|
+
domain?: string;
|
|
154
|
+
/** `Path`. @default '/' */
|
|
155
|
+
path?: string;
|
|
156
|
+
/** `Secure`: sent over HTTPS only. Required by browsers with `sameSite: 'none'`. @default false */
|
|
157
|
+
secure?: boolean;
|
|
158
|
+
/** `SameSite`. `'none'` (e.g. an app inside an iframe) needs `secure: true`. @default 'lax' */
|
|
159
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
160
|
+
/** Lifetime in seconds (`Max-Age` and `Expires`). @default 31536000 (one year) */
|
|
161
|
+
maxAge?: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The context of the `i18n:beforeLocaleSwitch` runtime hook. A subscriber may set `to` (another
|
|
165
|
+
* enabled locale) or `cancel: true`; an invalid `to` is ignored.
|
|
166
|
+
*/
|
|
167
|
+
export interface I18nBeforeLocaleSwitchContext {
|
|
168
|
+
/** The locale shown now. */
|
|
169
|
+
from: string;
|
|
170
|
+
/** The locale the switch goes to. */
|
|
171
|
+
to: string;
|
|
172
|
+
/** `true` stops the switch: the page and the stored preference stay. */
|
|
173
|
+
cancel: boolean;
|
|
174
|
+
}
|
|
146
175
|
export interface ModuleOptions {
|
|
147
176
|
/**
|
|
148
177
|
* List of supported locales.
|
|
@@ -214,6 +243,15 @@ export interface ModuleOptions {
|
|
|
214
243
|
* @default true
|
|
215
244
|
*/
|
|
216
245
|
redirects?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Redirect a locale prefix in another case or encoding to the page in its own spelling
|
|
248
|
+
* (`/DE/about` → `/de/about`, `/EN/about` → `/about` under `prefix_except_default`). The router
|
|
249
|
+
* matches the prefix case-insensitively, so without the redirect such a URL would show the page
|
|
250
|
+
* under a second address. When `false`, or when `redirects` is `false`, the URL is a 404. A URL
|
|
251
|
+
* with no page behind it in its own spelling is a 404 either way.
|
|
252
|
+
* @default true
|
|
253
|
+
*/
|
|
254
|
+
prefixCaseRedirect?: boolean;
|
|
217
255
|
/**
|
|
218
256
|
* Register the core i18n plugin that provides `$t()`, `$tc()`, `$getLocale()`,
|
|
219
257
|
* `$switchLocale()`, and other runtime helpers.
|
|
@@ -269,11 +307,13 @@ export interface ModuleOptions {
|
|
|
269
307
|
*/
|
|
270
308
|
translationDir?: string;
|
|
271
309
|
/**
|
|
272
|
-
* Extra directories
|
|
273
|
-
* `
|
|
310
|
+
* Extra directories whose top-level `{locale}.json` files are deep-merged into the global
|
|
311
|
+
* dictionary before `translationDir`. A relative path is read in the project root and in each
|
|
312
|
+
* Nuxt layer root; an absolute path (a Nuxt module's own folder) is read once.
|
|
274
313
|
*
|
|
275
314
|
* Merge order: each entry in array order (across layers), then `translationDir` (wins on conflicts).
|
|
276
315
|
* Only root `{locale}.json` files are read — `pages/` under these dirs is ignored.
|
|
316
|
+
* Entries other modules add to `nuxt.options.i18n.additionalTranslationDirs` count, whatever their order.
|
|
277
317
|
*
|
|
278
318
|
* Example: `translationDir: 'frontend'`, `additionalTranslationDirs: ['common']` → `common/en.json` then `frontend/en.json`.
|
|
279
319
|
* @default []
|
|
@@ -356,6 +396,24 @@ export interface ModuleOptions {
|
|
|
356
396
|
* @default undefined (no fallback; returns the raw key)
|
|
357
397
|
*/
|
|
358
398
|
fallbackLocale?: string;
|
|
399
|
+
/**
|
|
400
|
+
* HTTP status of every redirect the server answers for the module: the preferred locale (cookie,
|
|
401
|
+
* `Accept-Language`), a prefix in another case, and under `hashMode` + `prefix` the move into the
|
|
402
|
+
* hash. `301` and `308` are cached by browsers: a visitor who later changes the preference is still
|
|
403
|
+
* sent where the first answer said. One of 301, 302, 303, 307, 308; any other value warns at build
|
|
404
|
+
* and 302 is used.
|
|
405
|
+
* @default 302
|
|
406
|
+
*/
|
|
407
|
+
redirectStatusCode?: number;
|
|
408
|
+
/**
|
|
409
|
+
* Resolve linked messages (`@:key`, `@.upper:key`, `@.lower:key`, `@.capitalize:key`, `@:{'key'}`)
|
|
410
|
+
* in each built dictionary, so the runtime never parses them. A link to a missing key, or a
|
|
411
|
+
* cycle, leaves the message as written and warns at build. Translations added at runtime
|
|
412
|
+
* (`$mergeTranslations`, `i18n:register`, inline `$defineI18nRoute`) are not resolved.
|
|
413
|
+
* Off by default: `@:` may already be plain text in your messages.
|
|
414
|
+
* @default false
|
|
415
|
+
*/
|
|
416
|
+
linkedMessages?: boolean;
|
|
359
417
|
/**
|
|
360
418
|
* Cookie name for persisting the user's locale preference across sessions.
|
|
361
419
|
* Set to `null` to disable cookie-based persistence.
|
|
@@ -364,6 +422,13 @@ export interface ModuleOptions {
|
|
|
364
422
|
* @default null
|
|
365
423
|
*/
|
|
366
424
|
localeCookie?: string | null;
|
|
425
|
+
/**
|
|
426
|
+
* Attributes of the locale cookie (and of the hash cookie under `hashMode`), as the server and
|
|
427
|
+
* the browser write it. Unset fields keep the defaults: `path: '/'`, `sameSite: 'lax'`, a year,
|
|
428
|
+
* no `Domain`, no `Secure`. Build config only: no request decides them.
|
|
429
|
+
* @default {}
|
|
430
|
+
*/
|
|
431
|
+
localeCookieOptions?: LocaleCookieOptions;
|
|
367
432
|
/**
|
|
368
433
|
* Enable verbose debug logging for locale detection, route generation, and translation loading.
|
|
369
434
|
* @default false
|
|
@@ -631,6 +696,8 @@ export interface ModuleOptionsExtend extends ModuleOptions {
|
|
|
631
696
|
disablePageLocales: boolean;
|
|
632
697
|
/** Resolved flag: whether locale-based redirects are enabled. */
|
|
633
698
|
redirects?: boolean;
|
|
699
|
+
/** Resolved flag: whether a locale prefix in another case or encoding redirects to its own spelling. */
|
|
700
|
+
prefixCaseRedirect?: boolean;
|
|
634
701
|
/** Resolved translation payload loading strategy. */
|
|
635
702
|
translationPayloadMode?: 'premerged' | 'source';
|
|
636
703
|
/** Premerged files are in `public/`, so they can sit on `app.cdnURL`. */
|
package/dist/index.d.ts
CHANGED
|
@@ -121,6 +121,10 @@ export interface DefineI18nRouteConfig {
|
|
|
121
121
|
export type I18nRouteParams = Record<LocaleCode, Record<string, string>> | null;
|
|
122
122
|
/** Interpolation parameters passed to the `t()` function. */
|
|
123
123
|
export type Params = Record<string, string | number | boolean>;
|
|
124
|
+
/** A list for `{0}`, `{1}`: what `t()` takes besides `Params`. */
|
|
125
|
+
export type ListParams = readonly (string | number | boolean)[];
|
|
126
|
+
/** What `t()` and `interpolate` take: named params or a list. `PluralFunc` keeps `Params`. */
|
|
127
|
+
export type TranslateParams = Params | ListParams;
|
|
124
128
|
/** Getter function signature used by pluralization to resolve nested keys. */
|
|
125
129
|
export type Getter = (key: TranslationKey, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
126
130
|
/**
|
|
@@ -143,6 +147,31 @@ export type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'pre
|
|
|
143
147
|
* Useful for logging, reporting, or providing dynamic fallbacks.
|
|
144
148
|
*/
|
|
145
149
|
export type MissingHandler = (locale: string, key: TranslationKey, routeName: string, instance?: unknown, type?: string) => void;
|
|
150
|
+
/** Attributes of the locale cookie (`localeCookieOptions`). */
|
|
151
|
+
export interface LocaleCookieOptions {
|
|
152
|
+
/** `Domain`: e.g. `.example.com` to share the cookie across subdomains. Unset: the host only. */
|
|
153
|
+
domain?: string;
|
|
154
|
+
/** `Path`. @default '/' */
|
|
155
|
+
path?: string;
|
|
156
|
+
/** `Secure`: sent over HTTPS only. Required by browsers with `sameSite: 'none'`. @default false */
|
|
157
|
+
secure?: boolean;
|
|
158
|
+
/** `SameSite`. `'none'` (e.g. an app inside an iframe) needs `secure: true`. @default 'lax' */
|
|
159
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
160
|
+
/** Lifetime in seconds (`Max-Age` and `Expires`). @default 31536000 (one year) */
|
|
161
|
+
maxAge?: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The context of the `i18n:beforeLocaleSwitch` runtime hook. A subscriber may set `to` (another
|
|
165
|
+
* enabled locale) or `cancel: true`; an invalid `to` is ignored.
|
|
166
|
+
*/
|
|
167
|
+
export interface I18nBeforeLocaleSwitchContext {
|
|
168
|
+
/** The locale shown now. */
|
|
169
|
+
from: string;
|
|
170
|
+
/** The locale the switch goes to. */
|
|
171
|
+
to: string;
|
|
172
|
+
/** `true` stops the switch: the page and the stored preference stay. */
|
|
173
|
+
cancel: boolean;
|
|
174
|
+
}
|
|
146
175
|
export interface ModuleOptions {
|
|
147
176
|
/**
|
|
148
177
|
* List of supported locales.
|
|
@@ -214,6 +243,15 @@ export interface ModuleOptions {
|
|
|
214
243
|
* @default true
|
|
215
244
|
*/
|
|
216
245
|
redirects?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Redirect a locale prefix in another case or encoding to the page in its own spelling
|
|
248
|
+
* (`/DE/about` → `/de/about`, `/EN/about` → `/about` under `prefix_except_default`). The router
|
|
249
|
+
* matches the prefix case-insensitively, so without the redirect such a URL would show the page
|
|
250
|
+
* under a second address. When `false`, or when `redirects` is `false`, the URL is a 404. A URL
|
|
251
|
+
* with no page behind it in its own spelling is a 404 either way.
|
|
252
|
+
* @default true
|
|
253
|
+
*/
|
|
254
|
+
prefixCaseRedirect?: boolean;
|
|
217
255
|
/**
|
|
218
256
|
* Register the core i18n plugin that provides `$t()`, `$tc()`, `$getLocale()`,
|
|
219
257
|
* `$switchLocale()`, and other runtime helpers.
|
|
@@ -269,11 +307,13 @@ export interface ModuleOptions {
|
|
|
269
307
|
*/
|
|
270
308
|
translationDir?: string;
|
|
271
309
|
/**
|
|
272
|
-
* Extra directories
|
|
273
|
-
* `
|
|
310
|
+
* Extra directories whose top-level `{locale}.json` files are deep-merged into the global
|
|
311
|
+
* dictionary before `translationDir`. A relative path is read in the project root and in each
|
|
312
|
+
* Nuxt layer root; an absolute path (a Nuxt module's own folder) is read once.
|
|
274
313
|
*
|
|
275
314
|
* Merge order: each entry in array order (across layers), then `translationDir` (wins on conflicts).
|
|
276
315
|
* Only root `{locale}.json` files are read — `pages/` under these dirs is ignored.
|
|
316
|
+
* Entries other modules add to `nuxt.options.i18n.additionalTranslationDirs` count, whatever their order.
|
|
277
317
|
*
|
|
278
318
|
* Example: `translationDir: 'frontend'`, `additionalTranslationDirs: ['common']` → `common/en.json` then `frontend/en.json`.
|
|
279
319
|
* @default []
|
|
@@ -356,6 +396,24 @@ export interface ModuleOptions {
|
|
|
356
396
|
* @default undefined (no fallback; returns the raw key)
|
|
357
397
|
*/
|
|
358
398
|
fallbackLocale?: string;
|
|
399
|
+
/**
|
|
400
|
+
* HTTP status of every redirect the server answers for the module: the preferred locale (cookie,
|
|
401
|
+
* `Accept-Language`), a prefix in another case, and under `hashMode` + `prefix` the move into the
|
|
402
|
+
* hash. `301` and `308` are cached by browsers: a visitor who later changes the preference is still
|
|
403
|
+
* sent where the first answer said. One of 301, 302, 303, 307, 308; any other value warns at build
|
|
404
|
+
* and 302 is used.
|
|
405
|
+
* @default 302
|
|
406
|
+
*/
|
|
407
|
+
redirectStatusCode?: number;
|
|
408
|
+
/**
|
|
409
|
+
* Resolve linked messages (`@:key`, `@.upper:key`, `@.lower:key`, `@.capitalize:key`, `@:{'key'}`)
|
|
410
|
+
* in each built dictionary, so the runtime never parses them. A link to a missing key, or a
|
|
411
|
+
* cycle, leaves the message as written and warns at build. Translations added at runtime
|
|
412
|
+
* (`$mergeTranslations`, `i18n:register`, inline `$defineI18nRoute`) are not resolved.
|
|
413
|
+
* Off by default: `@:` may already be plain text in your messages.
|
|
414
|
+
* @default false
|
|
415
|
+
*/
|
|
416
|
+
linkedMessages?: boolean;
|
|
359
417
|
/**
|
|
360
418
|
* Cookie name for persisting the user's locale preference across sessions.
|
|
361
419
|
* Set to `null` to disable cookie-based persistence.
|
|
@@ -364,6 +422,13 @@ export interface ModuleOptions {
|
|
|
364
422
|
* @default null
|
|
365
423
|
*/
|
|
366
424
|
localeCookie?: string | null;
|
|
425
|
+
/**
|
|
426
|
+
* Attributes of the locale cookie (and of the hash cookie under `hashMode`), as the server and
|
|
427
|
+
* the browser write it. Unset fields keep the defaults: `path: '/'`, `sameSite: 'lax'`, a year,
|
|
428
|
+
* no `Domain`, no `Secure`. Build config only: no request decides them.
|
|
429
|
+
* @default {}
|
|
430
|
+
*/
|
|
431
|
+
localeCookieOptions?: LocaleCookieOptions;
|
|
367
432
|
/**
|
|
368
433
|
* Enable verbose debug logging for locale detection, route generation, and translation loading.
|
|
369
434
|
* @default false
|
|
@@ -631,6 +696,8 @@ export interface ModuleOptionsExtend extends ModuleOptions {
|
|
|
631
696
|
disablePageLocales: boolean;
|
|
632
697
|
/** Resolved flag: whether locale-based redirects are enabled. */
|
|
633
698
|
redirects?: boolean;
|
|
699
|
+
/** Resolved flag: whether a locale prefix in another case or encoding redirects to its own spelling. */
|
|
700
|
+
prefixCaseRedirect?: boolean;
|
|
634
701
|
/** Resolved translation payload loading strategy. */
|
|
635
702
|
translationPayloadMode?: 'premerged' | 'source';
|
|
636
703
|
/** Premerged files are in `public/`, so they can sit on `app.cdnURL`. */
|