@i18n-micro/types 2.0.1 → 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 +58 -2
- package/dist/index.d.ts +58 -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.
|
|
@@ -278,11 +307,13 @@ export interface ModuleOptions {
|
|
|
278
307
|
*/
|
|
279
308
|
translationDir?: string;
|
|
280
309
|
/**
|
|
281
|
-
* Extra directories
|
|
282
|
-
* `
|
|
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.
|
|
283
313
|
*
|
|
284
314
|
* Merge order: each entry in array order (across layers), then `translationDir` (wins on conflicts).
|
|
285
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.
|
|
286
317
|
*
|
|
287
318
|
* Example: `translationDir: 'frontend'`, `additionalTranslationDirs: ['common']` → `common/en.json` then `frontend/en.json`.
|
|
288
319
|
* @default []
|
|
@@ -365,6 +396,24 @@ export interface ModuleOptions {
|
|
|
365
396
|
* @default undefined (no fallback; returns the raw key)
|
|
366
397
|
*/
|
|
367
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;
|
|
368
417
|
/**
|
|
369
418
|
* Cookie name for persisting the user's locale preference across sessions.
|
|
370
419
|
* Set to `null` to disable cookie-based persistence.
|
|
@@ -373,6 +422,13 @@ export interface ModuleOptions {
|
|
|
373
422
|
* @default null
|
|
374
423
|
*/
|
|
375
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;
|
|
376
432
|
/**
|
|
377
433
|
* Enable verbose debug logging for locale detection, route generation, and translation loading.
|
|
378
434
|
* @default false
|
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.
|
|
@@ -278,11 +307,13 @@ export interface ModuleOptions {
|
|
|
278
307
|
*/
|
|
279
308
|
translationDir?: string;
|
|
280
309
|
/**
|
|
281
|
-
* Extra directories
|
|
282
|
-
* `
|
|
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.
|
|
283
313
|
*
|
|
284
314
|
* Merge order: each entry in array order (across layers), then `translationDir` (wins on conflicts).
|
|
285
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.
|
|
286
317
|
*
|
|
287
318
|
* Example: `translationDir: 'frontend'`, `additionalTranslationDirs: ['common']` → `common/en.json` then `frontend/en.json`.
|
|
288
319
|
* @default []
|
|
@@ -365,6 +396,24 @@ export interface ModuleOptions {
|
|
|
365
396
|
* @default undefined (no fallback; returns the raw key)
|
|
366
397
|
*/
|
|
367
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;
|
|
368
417
|
/**
|
|
369
418
|
* Cookie name for persisting the user's locale preference across sessions.
|
|
370
419
|
* Set to `null` to disable cookie-based persistence.
|
|
@@ -373,6 +422,13 @@ export interface ModuleOptions {
|
|
|
373
422
|
* @default null
|
|
374
423
|
*/
|
|
375
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;
|
|
376
432
|
/**
|
|
377
433
|
* Enable verbose debug logging for locale detection, route generation, and translation loading.
|
|
378
434
|
* @default false
|