@i18n-micro/types 1.2.5 → 1.2.7

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/README.md CHANGED
@@ -111,6 +111,21 @@ Represents global route configurations for different locales.
111
111
 
112
112
  Represents a key-value pair of translations.
113
113
 
114
+ #### Page-level SEO head (`useI18nHead`)
115
+
116
+ Types for per-page i18n SEO overrides: `I18nHeadInput`, `I18nHeadLink`, `I18nHeadMeta`, and `I18nHeadDisableGroup`. Use them in page helpers or when calling `useI18nHead` from `@i18n-micro/types` for typed `meta`, `link`, `replace`, and `disable` options.
117
+
118
+ ```typescript
119
+ import type { I18nHeadInput } from '@i18n-micro/types'
120
+
121
+ export function buildArticleHead(article: Article): I18nHeadInput {
122
+ return {
123
+ meta: [{ property: 'og:title', content: article.title }],
124
+ replace: { canonical: article.canonicalUrl, ogUrl: article.canonicalUrl },
125
+ }
126
+ }
127
+ ```
128
+
114
129
  #### `Translation`
115
130
 
116
131
  Represents a translation value, which can be a string, number, boolean, nested translations, or `null`.
package/dist/index.d.cts CHANGED
@@ -401,6 +401,47 @@ export interface ModuleOptions {
401
401
  * @default 0
402
402
  */
403
403
  cacheTtl?: number;
404
+ /**
405
+ * Named number formats per locale (Vue I18n-compatible).
406
+ * Enables `$tn(1000, 'currency')` style calls.
407
+ *
408
+ * @example
409
+ * numberFormats: {
410
+ * en: { currency: { style: 'currency', currency: 'USD' } },
411
+ * de: { currency: { style: 'currency', currency: 'EUR' } },
412
+ * }
413
+ */
414
+ numberFormats?: Record<string, Record<string, Intl.NumberFormatOptions>>;
415
+ /**
416
+ * Named datetime formats per locale (Vue I18n-compatible `datetimeFormats`).
417
+ * Enables `$td(date, 'short')` style calls.
418
+ *
419
+ * @example
420
+ * datetimeFormats: {
421
+ * en: { short: { year: 'numeric', month: 'short', day: 'numeric' } },
422
+ * de: { short: { year: 'numeric', month: 'short', day: 'numeric' } },
423
+ * }
424
+ */
425
+ datetimeFormats?: Record<string, Record<string, Intl.DateTimeFormatOptions>>;
426
+ /**
427
+ * HTTP `Cache-Control` max-age (seconds) for `/{apiBaseUrl}/:page/:locale/data.json`.
428
+ *
429
+ * Applies in full only while `dateBuild` busts the URL (`?v=...`), which is the default:
430
+ * the response is then `public, max-age=…, immutable` and safe for browsers and CDNs.
431
+ *
432
+ * - `dateBuild: 0`/`''` — the URL is stable, so this duration is *not* honoured; the
433
+ * response becomes `public, max-age=0, must-revalidate` instead. A long `max-age` on an
434
+ * unchanging URL pins the first payload a browser ever saw.
435
+ * - `0` — do not set `Cache-Control` at all (useful in local debugging)
436
+ * - Not applied in development (`import.meta.dev`) so HMR is not fought by the browser cache
437
+ * - Reaches only responses served through Nitro. Payloads copied into `public/` and served
438
+ * by the hosting platform take that platform's headers — see the Performance guide.
439
+ *
440
+ * Analogous to `@nuxtjs/i18n` experimental `httpCacheDuration` (v10.2.0), but as an
441
+ * explicit response header rather than Nitro `defineCachedEventHandler` maxAge.
442
+ * @default 31536000
443
+ */
444
+ httpCacheDuration?: number;
404
445
  /**
405
446
  * Value used for cache-busting translation requests (`?v=...`).
406
447
  *
@@ -444,14 +485,14 @@ export interface TranslationPayloadOptions {
444
485
  /**
445
486
  * Copy translation payload files into Nitro public assets during production builds.
446
487
  * In `source` mode this copies the compact source directory, not a pre-merged matrix.
447
- * @default true in `premerged` mode, `false` in `source` mode
488
+ * @default true in premerged mode, false in source mode
448
489
  */
449
490
  publicAssets?: boolean;
450
491
  /**
451
492
  * Add translation data routes to Nuxt/Nitro prerender output.
452
493
  * Disable this when `_locales` payloads are served from an external host/CDN or should not be
453
494
  * materialized into public output.
454
- * @default true in `premerged` mode, `false` in `source` mode
495
+ * @default true in premerged mode, false in source mode
455
496
  */
456
497
  prerenderRoutes?: boolean;
457
498
  /**
@@ -533,5 +574,39 @@ export type Translation = CleanTranslation | unknown;
533
574
  export interface Translations {
534
575
  [key: string]: Translation;
535
576
  }
577
+ /** Link entry for page-level i18n head overrides (`useI18nHead`). */
578
+ export interface I18nHeadLink {
579
+ rel: string;
580
+ href: string;
581
+ hreflang?: string;
582
+ [key: string]: string | undefined;
583
+ }
584
+ /** Meta entry for page-level i18n head overrides (`useI18nHead`). */
585
+ export interface I18nHeadMeta {
586
+ [key: string]: string | undefined;
587
+ }
588
+ /** Groups of built-in i18n SEO tags that can be disabled per page. */
589
+ export type I18nHeadDisableGroup = 'hreflang' | 'x-default' | 'canonical' | 'og' | 'og-alternates' | 'html';
590
+ /** Page-level overrides merged on top of `useLocaleHead` output. */
591
+ export interface I18nHeadInput {
592
+ /** Extra or overriding `<html>` attributes. */
593
+ htmlAttrs?: Record<string, string>;
594
+ /** Meta tags appended after base i18n tags (deduped by `id` / `property` / `name`). */
595
+ meta?: I18nHeadMeta[];
596
+ /** Link tags appended after base i18n tags (deduped by `id` / `rel` + `hreflang`). */
597
+ link?: I18nHeadLink[];
598
+ /** Replace or remove specific built-in i18n SEO tags. */
599
+ replace?: {
600
+ canonical?: string | false;
601
+ hreflang?: I18nHeadLink[] | false;
602
+ xDefault?: I18nHeadLink | false;
603
+ ogLocale?: string | false;
604
+ ogUrl?: string | false;
605
+ /** Locale codes for `og:locale:alternate` (resolved via `locale.og` / `iso`). */
606
+ ogAlternates?: string[] | false;
607
+ };
608
+ /** Disable built-in i18n SEO tag groups for this page. */
609
+ disable?: I18nHeadDisableGroup[];
610
+ }
536
611
  declare const init: () => void;
537
612
  export { init };
package/dist/index.d.ts CHANGED
@@ -401,6 +401,47 @@ export interface ModuleOptions {
401
401
  * @default 0
402
402
  */
403
403
  cacheTtl?: number;
404
+ /**
405
+ * Named number formats per locale (Vue I18n-compatible).
406
+ * Enables `$tn(1000, 'currency')` style calls.
407
+ *
408
+ * @example
409
+ * numberFormats: {
410
+ * en: { currency: { style: 'currency', currency: 'USD' } },
411
+ * de: { currency: { style: 'currency', currency: 'EUR' } },
412
+ * }
413
+ */
414
+ numberFormats?: Record<string, Record<string, Intl.NumberFormatOptions>>;
415
+ /**
416
+ * Named datetime formats per locale (Vue I18n-compatible `datetimeFormats`).
417
+ * Enables `$td(date, 'short')` style calls.
418
+ *
419
+ * @example
420
+ * datetimeFormats: {
421
+ * en: { short: { year: 'numeric', month: 'short', day: 'numeric' } },
422
+ * de: { short: { year: 'numeric', month: 'short', day: 'numeric' } },
423
+ * }
424
+ */
425
+ datetimeFormats?: Record<string, Record<string, Intl.DateTimeFormatOptions>>;
426
+ /**
427
+ * HTTP `Cache-Control` max-age (seconds) for `/{apiBaseUrl}/:page/:locale/data.json`.
428
+ *
429
+ * Applies in full only while `dateBuild` busts the URL (`?v=...`), which is the default:
430
+ * the response is then `public, max-age=…, immutable` and safe for browsers and CDNs.
431
+ *
432
+ * - `dateBuild: 0`/`''` — the URL is stable, so this duration is *not* honoured; the
433
+ * response becomes `public, max-age=0, must-revalidate` instead. A long `max-age` on an
434
+ * unchanging URL pins the first payload a browser ever saw.
435
+ * - `0` — do not set `Cache-Control` at all (useful in local debugging)
436
+ * - Not applied in development (`import.meta.dev`) so HMR is not fought by the browser cache
437
+ * - Reaches only responses served through Nitro. Payloads copied into `public/` and served
438
+ * by the hosting platform take that platform's headers — see the Performance guide.
439
+ *
440
+ * Analogous to `@nuxtjs/i18n` experimental `httpCacheDuration` (v10.2.0), but as an
441
+ * explicit response header rather than Nitro `defineCachedEventHandler` maxAge.
442
+ * @default 31536000
443
+ */
444
+ httpCacheDuration?: number;
404
445
  /**
405
446
  * Value used for cache-busting translation requests (`?v=...`).
406
447
  *
@@ -444,14 +485,14 @@ export interface TranslationPayloadOptions {
444
485
  /**
445
486
  * Copy translation payload files into Nitro public assets during production builds.
446
487
  * In `source` mode this copies the compact source directory, not a pre-merged matrix.
447
- * @default true in `premerged` mode, `false` in `source` mode
488
+ * @default true in premerged mode, false in source mode
448
489
  */
449
490
  publicAssets?: boolean;
450
491
  /**
451
492
  * Add translation data routes to Nuxt/Nitro prerender output.
452
493
  * Disable this when `_locales` payloads are served from an external host/CDN or should not be
453
494
  * materialized into public output.
454
- * @default true in `premerged` mode, `false` in `source` mode
495
+ * @default true in premerged mode, false in source mode
455
496
  */
456
497
  prerenderRoutes?: boolean;
457
498
  /**
@@ -533,5 +574,39 @@ export type Translation = CleanTranslation | unknown;
533
574
  export interface Translations {
534
575
  [key: string]: Translation;
535
576
  }
577
+ /** Link entry for page-level i18n head overrides (`useI18nHead`). */
578
+ export interface I18nHeadLink {
579
+ rel: string;
580
+ href: string;
581
+ hreflang?: string;
582
+ [key: string]: string | undefined;
583
+ }
584
+ /** Meta entry for page-level i18n head overrides (`useI18nHead`). */
585
+ export interface I18nHeadMeta {
586
+ [key: string]: string | undefined;
587
+ }
588
+ /** Groups of built-in i18n SEO tags that can be disabled per page. */
589
+ export type I18nHeadDisableGroup = 'hreflang' | 'x-default' | 'canonical' | 'og' | 'og-alternates' | 'html';
590
+ /** Page-level overrides merged on top of `useLocaleHead` output. */
591
+ export interface I18nHeadInput {
592
+ /** Extra or overriding `<html>` attributes. */
593
+ htmlAttrs?: Record<string, string>;
594
+ /** Meta tags appended after base i18n tags (deduped by `id` / `property` / `name`). */
595
+ meta?: I18nHeadMeta[];
596
+ /** Link tags appended after base i18n tags (deduped by `id` / `rel` + `hreflang`). */
597
+ link?: I18nHeadLink[];
598
+ /** Replace or remove specific built-in i18n SEO tags. */
599
+ replace?: {
600
+ canonical?: string | false;
601
+ hreflang?: I18nHeadLink[] | false;
602
+ xDefault?: I18nHeadLink | false;
603
+ ogLocale?: string | false;
604
+ ogUrl?: string | false;
605
+ /** Locale codes for `og:locale:alternate` (resolved via `locale.og` / `iso`). */
606
+ ogAlternates?: string[] | false;
607
+ };
608
+ /** Disable built-in i18n SEO tag groups for this page. */
609
+ disable?: I18nHeadDisableGroup[];
610
+ }
536
611
  declare const init: () => void;
537
612
  export { init };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/types",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "TypeScript definitions for the Nuxt I18n Micro ecosystem.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -51,14 +51,16 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "publint": "^0.3.17",
54
- "vite": "^7.3.1",
55
- "vite-plugin-dts": "^4.5.4"
54
+ "vite": "^7.3.6",
55
+ "vite-plugin-dts": "^4.5.4",
56
+ "vitest": "^4.1.10"
56
57
  },
57
58
  "engines": {
58
59
  "node": ">=18"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "vite build",
62
- "check:package": "publint"
63
+ "check:package": "publint",
64
+ "test": "vitest run --typecheck"
63
65
  }
64
66
  }