nuxt-i18n-micro 3.30.3 → 4.0.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.
Files changed (111) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/dist/client/200.html +1 -1
  4. package/dist/client/404.html +1 -1
  5. package/dist/client/_nuxt/BVna_KKx.js +3 -0
  6. package/dist/client/_nuxt/Bw81RhAv.js +1 -0
  7. package/dist/client/_nuxt/CPz_jhsD.js +1 -0
  8. package/dist/client/_nuxt/CmvObVGq.js +1 -0
  9. package/dist/client/_nuxt/DKUOBR6F.js +5 -0
  10. package/dist/client/_nuxt/builds/latest.json +1 -1
  11. package/dist/client/_nuxt/builds/meta/f0c8d4bf-40d2-4915-8b4a-ebe46bde61c8.json +1 -0
  12. package/dist/client/_nuxt/{entry.BM-mexAv.css → entry.PSWtHhay.css} +1 -1
  13. package/dist/client/_nuxt/error-404.xs3fxhVJ.css +1 -0
  14. package/dist/client/_nuxt/error-500.C2S-4iLg.css +1 -0
  15. package/dist/client/index.html +1 -1
  16. package/dist/module.d.mts +14 -5
  17. package/dist/module.json +4 -1
  18. package/dist/module.mjs +850 -475
  19. package/dist/runtime/components/i18n-group.d.vue.ts +17 -9
  20. package/dist/runtime/components/i18n-group.vue +2 -4
  21. package/dist/runtime/components/i18n-group.vue.d.ts +17 -9
  22. package/dist/runtime/components/i18n-link.d.vue.ts +9 -6
  23. package/dist/runtime/components/i18n-link.vue +7 -28
  24. package/dist/runtime/components/i18n-link.vue.d.ts +9 -6
  25. package/dist/runtime/components/i18n-switcher.d.vue.ts +128 -54
  26. package/dist/runtime/components/i18n-switcher.vue +56 -156
  27. package/dist/runtime/components/i18n-switcher.vue.d.ts +128 -54
  28. package/dist/runtime/components/i18n-t.d.vue.ts +59 -116
  29. package/dist/runtime/components/i18n-t.vue +24 -71
  30. package/dist/runtime/components/i18n-t.vue.d.ts +59 -116
  31. package/dist/runtime/composables/useI18n.js +2 -38
  32. package/dist/runtime/composables/useI18nHead.js +21 -6
  33. package/dist/runtime/composables/useI18nLocale.d.ts +4 -1
  34. package/dist/runtime/composables/useI18nLocale.js +20 -22
  35. package/dist/runtime/composables/useLocaleHead.d.ts +26 -31
  36. package/dist/runtime/composables/useLocaleHead.js +47 -167
  37. package/dist/runtime/devtools/bridge.d.ts +2 -2
  38. package/dist/runtime/devtools/vue-devtools.d.ts +2 -2
  39. package/dist/runtime/devtools/vue-devtools.js +5 -5
  40. package/dist/runtime/middleware/i18n-redirect.global.d.ts +3 -2
  41. package/dist/runtime/middleware/i18n-redirect.global.js +30 -41
  42. package/dist/runtime/plugins/01.plugin.d.ts +156 -34
  43. package/dist/runtime/plugins/01.plugin.js +184 -138
  44. package/dist/runtime/plugins/02.meta.js +36 -43
  45. package/dist/runtime/plugins/04.vue-devtools.js +1 -1
  46. package/dist/runtime/plugins/06.redirect.d.ts +3 -3
  47. package/dist/runtime/plugins/06.redirect.js +65 -91
  48. package/dist/runtime/server/{utils → internal}/dev-live-translations.js +4 -3
  49. package/dist/runtime/server/internal/server-translation-cache.d.ts +9 -0
  50. package/dist/runtime/server/internal/server-translation-cache.js +10 -0
  51. package/dist/runtime/server/internal/shared-cache.d.ts +24 -0
  52. package/dist/runtime/server/internal/shared-cache.js +71 -0
  53. package/dist/runtime/server/internal/translation-watcher.d.ts +79 -0
  54. package/dist/runtime/server/internal/translation-watcher.js +105 -0
  55. package/dist/runtime/server/middleware/i18n.global.js +24 -37
  56. package/dist/runtime/server/payload-source.assets.d.ts +1 -0
  57. package/dist/runtime/server/payload-source.assets.js +3 -8
  58. package/dist/runtime/server/payload-source.fs.d.ts +1 -0
  59. package/dist/runtime/server/payload-source.fs.js +18 -7
  60. package/dist/runtime/server/plugins/failed-read.d.ts +7 -0
  61. package/dist/runtime/server/plugins/failed-read.js +23 -0
  62. package/dist/runtime/server/plugins/payload-cache.d.ts +6 -0
  63. package/dist/runtime/server/plugins/payload-cache.js +16 -0
  64. package/dist/runtime/server/plugins/watcher.dev.js +15 -79
  65. package/dist/runtime/server/routes/i18n.js +13 -14
  66. package/dist/runtime/server/utils/locale-detector.d.ts +32 -2
  67. package/dist/runtime/server/utils/locale-detector.js +48 -27
  68. package/dist/runtime/server/utils/locale-server-middleware.js +14 -33
  69. package/dist/runtime/server/utils/payload-cache.d.ts +4 -0
  70. package/dist/runtime/server/utils/payload-cache.js +13 -0
  71. package/dist/runtime/server/utils/server-loader.d.ts +17 -6
  72. package/dist/runtime/server/utils/server-loader.js +105 -51
  73. package/dist/runtime/server/utils/translation-server-middleware.js +18 -35
  74. package/dist/runtime/utils/cache-keys.d.ts +6 -0
  75. package/dist/runtime/utils/cache-keys.js +2 -0
  76. package/dist/runtime/utils/i18n-api.d.ts +185 -0
  77. package/dist/runtime/utils/i18n-api.js +196 -0
  78. package/dist/runtime/utils/i18n-config.d.ts +18 -0
  79. package/dist/runtime/utils/i18n-config.js +47 -0
  80. package/dist/runtime/utils/i18n-navigation.d.ts +26 -0
  81. package/dist/runtime/utils/i18n-navigation.js +96 -0
  82. package/dist/runtime/utils/nuxt-i18n-server.d.ts +26 -0
  83. package/dist/runtime/utils/nuxt-i18n-server.js +83 -0
  84. package/dist/runtime/utils/nuxt-i18n.d.ts +81 -96
  85. package/dist/runtime/utils/nuxt-i18n.js +180 -252
  86. package/dist/runtime/utils/page-head.d.ts +12 -0
  87. package/dist/runtime/utils/page-head.js +6 -0
  88. package/dist/runtime/utils/request-url.d.ts +6 -0
  89. package/dist/runtime/utils/request-url.js +11 -0
  90. package/dist/runtime/utils/storage.d.ts +31 -19
  91. package/dist/runtime/utils/storage.js +100 -49
  92. package/dist/runtime/utils/translation-entry.d.ts +6 -0
  93. package/dist/runtime/utils/translation-entry.js +16 -0
  94. package/dist/types.d.mts +4 -6
  95. package/internals.d.mts +9 -2
  96. package/package.json +78 -79
  97. package/dist/client/_nuxt/BOxWElQP.js +0 -21
  98. package/dist/client/_nuxt/CUWB4CwN.js +0 -3
  99. package/dist/client/_nuxt/CmUbe-uv.js +0 -1
  100. package/dist/client/_nuxt/DAzShkZF.js +0 -1
  101. package/dist/client/_nuxt/MokPP5zi.js +0 -1
  102. package/dist/client/_nuxt/builds/meta/60974e48-d00e-4f9b-9467-9d4b322519da.json +0 -1
  103. package/dist/client/_nuxt/error-404.D9Svp6Hk.css +0 -1
  104. package/dist/client/_nuxt/error-500.B-mjI9_9.css +0 -1
  105. package/dist/runtime/plugins/03.define.d.ts +0 -7
  106. package/dist/runtime/plugins/03.define.js +0 -42
  107. package/dist/runtime/plugins/05.hooks.d.ts +0 -2
  108. package/dist/runtime/plugins/05.hooks.js +0 -47
  109. package/dist/runtime/server/utils/server-translation-cache.d.ts +0 -11
  110. package/dist/runtime/server/utils/server-translation-cache.js +0 -20
  111. /package/dist/runtime/server/{utils → internal}/dev-live-translations.d.ts +0 -0
@@ -1,5 +1,6 @@
1
+ import { type I18nTRenderProps } from '@i18n-micro/core/render';
1
2
  import type { PluralFunc } from '@i18n-micro/types';
2
- import type { PropType, VNode } from 'vue';
3
+ import type { FunctionalComponent, PropType } from 'vue';
3
4
  /**
4
5
  * Renders one translation into an element, with pluralization, interpolation and
5
6
  * number/date formatting handled for you.
@@ -8,121 +9,63 @@ import type { PropType, VNode } from 'vue';
8
9
  * several are set the first of that list wins — the order the render function checks them.
9
10
  *
10
11
  * @slot default — receives `{ translation }`, for wrapping the resolved string in markup
11
- * @slot {name} — any other named slot replaces the `{name}` placeholder inside the translation
12
+ * @slot {name} — any other named slot replaces every `{name}` placeholder inside the translation
12
13
  */
13
14
  declare const _default: typeof __VLS_export;
14
15
  export default _default;
15
- declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
16
- /** Translation key to render. */
17
- keypath: {
18
- type: PropType<string>;
19
- required: true;
20
- };
21
- /** Count selecting the plural form. Set it to use `$tc` instead of `$t`. */
22
- plural: {
23
- type: PropType<number | string>;
24
- };
25
- /** Element to render. */
26
- tag: {
27
- type: PropType<string>;
28
- default: string;
29
- };
30
- /** Interpolation values substituted into the translation. */
31
- params: {
32
- type: PropType<Record<string, string | number | boolean>>;
33
- default: () => {};
34
- };
35
- /** Rendered instead of the component when `hideIfEmpty` suppresses an empty translation. */
36
- defaultValue: {
37
- type: PropType<string>;
38
- default: string;
39
- };
40
- /** Render the translation as HTML rather than text. Only for content you control. */
41
- html: {
42
- type: PropType<boolean>;
43
- default: boolean;
44
- };
45
- /** Render nothing when the translation resolves to an empty string. */
46
- hideIfEmpty: {
47
- type: PropType<boolean>;
48
- default: boolean;
49
- };
50
- /** Plural rule for this element only, overriding the configured one. */
51
- customPluralRule: {
52
- type: PropType<PluralFunc>;
53
- default: null;
54
- };
55
- /** Formats the value with `$tn` and passes it to the translation as `{number}`. */
56
- number: {
57
- type: PropType<number | string>;
58
- };
59
- /** Formats the value with `$td` and passes it to the translation as `{date}`. */
60
- date: {
61
- type: PropType<Date | string | number>;
62
- };
63
- /** Formats the value with `$tdr` and passes it to the translation as `{relativeDate}`. */
64
- relativeDate: {
65
- type: PropType<Date | string | number>;
66
- };
67
- }>, () => string | VNode<import("vue").RendererNode, import("vue").RendererElement, {
68
- [key: string]: any;
69
- }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
70
- /** Translation key to render. */
71
- keypath: {
72
- type: PropType<string>;
73
- required: true;
74
- };
75
- /** Count selecting the plural form. Set it to use `$tc` instead of `$t`. */
76
- plural: {
77
- type: PropType<number | string>;
78
- };
79
- /** Element to render. */
80
- tag: {
81
- type: PropType<string>;
82
- default: string;
83
- };
84
- /** Interpolation values substituted into the translation. */
85
- params: {
86
- type: PropType<Record<string, string | number | boolean>>;
87
- default: () => {};
88
- };
89
- /** Rendered instead of the component when `hideIfEmpty` suppresses an empty translation. */
90
- defaultValue: {
91
- type: PropType<string>;
92
- default: string;
93
- };
94
- /** Render the translation as HTML rather than text. Only for content you control. */
95
- html: {
96
- type: PropType<boolean>;
97
- default: boolean;
98
- };
99
- /** Render nothing when the translation resolves to an empty string. */
100
- hideIfEmpty: {
101
- type: PropType<boolean>;
102
- default: boolean;
103
- };
104
- /** Plural rule for this element only, overriding the configured one. */
105
- customPluralRule: {
106
- type: PropType<PluralFunc>;
107
- default: null;
108
- };
109
- /** Formats the value with `$tn` and passes it to the translation as `{number}`. */
110
- number: {
111
- type: PropType<number | string>;
112
- };
113
- /** Formats the value with `$td` and passes it to the translation as `{date}`. */
114
- date: {
115
- type: PropType<Date | string | number>;
116
- };
117
- /** Formats the value with `$tdr` and passes it to the translation as `{relativeDate}`. */
118
- relativeDate: {
119
- type: PropType<Date | string | number>;
120
- };
121
- }>> & Readonly<{}>, {
122
- params: Record<string, string | number | boolean>;
123
- tag: string;
124
- html: boolean;
125
- defaultValue: string;
126
- hideIfEmpty: boolean;
127
- customPluralRule: PluralFunc;
128
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
16
+ declare const __VLS_export: FunctionalComponent<I18nTRenderProps, {}, any, {}> & {
17
+ displayName: string;
18
+ inheritAttrs: boolean;
19
+ props: {
20
+ /** Translation key to render. */
21
+ keypath: {
22
+ type: PropType<string>;
23
+ required: boolean;
24
+ };
25
+ /** Count selecting the plural form. Set it to use `$tc` instead of `$t`. `null` means unset. */
26
+ plural: {
27
+ type: PropType<number | string | null>;
28
+ };
29
+ /** Element to render. */
30
+ tag: {
31
+ type: PropType<string>;
32
+ default: string;
33
+ };
34
+ /** Interpolation values substituted into the translation. */
35
+ params: {
36
+ type: PropType<Record<string, string | number | boolean>>;
37
+ };
38
+ /** Rendered instead of the component when `hideIfEmpty` suppresses an empty translation. */
39
+ defaultValue: {
40
+ type: PropType<string>;
41
+ default: string;
42
+ };
43
+ /** Render the translation as HTML rather than text. Only for translations you control: `params` are escaped, the translation is not. */
44
+ html: {
45
+ type: PropType<boolean>;
46
+ default: boolean;
47
+ };
48
+ /** Render nothing when the translation resolves to an empty string. */
49
+ hideIfEmpty: {
50
+ type: PropType<boolean>;
51
+ default: boolean;
52
+ };
53
+ /** Plural rule for this element only, overriding the configured one. Its answer is used as is; `null` renders empty. */
54
+ customPluralRule: {
55
+ type: PropType<PluralFunc>;
56
+ default: null;
57
+ };
58
+ /** Formats the value with `$tn` and passes it to the translation as `{number}`, alongside `params`. */
59
+ number: {
60
+ type: PropType<number | string | null>;
61
+ };
62
+ /** Formats the value with `$td` and passes it to the translation as `{date}`, alongside `params`. */
63
+ date: {
64
+ type: PropType<Date | string | number | null>;
65
+ };
66
+ /** Formats the value with `$tdr` and passes it to the translation as `{relativeDate}`, alongside `params`. */
67
+ relativeDate: {
68
+ type: PropType<Date | string | number | null>;
69
+ };
70
+ };
71
+ };
@@ -1,40 +1,4 @@
1
- import { useNuxtApp } from "#app";
1
+ import { useNuxtApp } from "#app/nuxt";
2
2
  export function useI18n() {
3
- const nuxtApp = useNuxtApp();
4
- const injections = {
5
- $i18nStrategy: nuxtApp.$i18nStrategy,
6
- $getI18nConfig: nuxtApp.$getI18nConfig,
7
- $defaultLocale: nuxtApp.$defaultLocale,
8
- $getLocale: nuxtApp.$getLocale,
9
- $getLocaleName: nuxtApp.$getLocaleName,
10
- $getLocales: nuxtApp.$getLocales,
11
- $getRouteName: nuxtApp.$getRouteName,
12
- $t: nuxtApp.$t,
13
- $_t: nuxtApp.$_t,
14
- $ts: nuxtApp.$ts,
15
- $_ts: nuxtApp.$_ts,
16
- $tn: nuxtApp.$tn,
17
- $td: nuxtApp.$td,
18
- $tdr: nuxtApp.$tdr,
19
- $has: nuxtApp.$has,
20
- $resolveTranslations: nuxtApp.$resolveTranslations,
21
- $setTranslation: nuxtApp.$setTranslation,
22
- $tc: nuxtApp.$tc,
23
- $mergeTranslations: nuxtApp.$mergeTranslations,
24
- $setI18nRouteParams: nuxtApp.$setI18nRouteParams,
25
- $switchLocaleRoute: nuxtApp.$switchLocaleRoute,
26
- $switchLocalePath: nuxtApp.$switchLocalePath,
27
- $switchLocale: nuxtApp.$switchLocale,
28
- $switchRoute: nuxtApp.$switchRoute,
29
- $localeRoute: nuxtApp.$localeRoute,
30
- $localePath: nuxtApp.$localePath,
31
- $loadPageTranslations: nuxtApp.$loadPageTranslations,
32
- $setMissingHandler: nuxtApp.$setMissingHandler,
33
- helper: nuxtApp.helper
34
- };
35
- const noDollarInjections = Object.fromEntries(Object.entries(injections).map(([key, value]) => [key.slice(1), value]));
36
- return {
37
- ...injections,
38
- ...noDollarInjections
39
- };
3
+ return useNuxtApp().$i18n;
40
4
  }
@@ -1,22 +1,37 @@
1
- import { toValue, watch } from "vue";
2
- import { useState } from "#app";
1
+ import { getCurrentInstance, onActivated, onBeforeUnmount, toValue, watch } from "vue";
2
+ import { useRouter } from "#app/composables/router";
3
+ import { useState } from "#app/composables/state";
4
+ import { usePageHead, usePageRoute } from "../utils/page-head.js";
3
5
  export function useI18nHead(input) {
4
- const pageHead = useState("i18n-head-page", () => null);
6
+ const pageHead = usePageHead();
5
7
  const localeState = useState("i18n-locale", () => null);
6
8
  const resetPageHead = () => {
7
9
  pageHead.value = null;
8
10
  };
9
11
  if (input !== void 0) {
12
+ const page = usePageRoute();
13
+ const router = useRouter();
14
+ let written = null;
15
+ const write = (value) => {
16
+ if (page && page.path !== router.currentRoute.value.path) return;
17
+ pageHead.value = value ?? null;
18
+ written = pageHead.value;
19
+ };
10
20
  watch(
11
21
  () => {
12
22
  localeState.value;
23
+ if (!page) router.currentRoute.value.path;
13
24
  return toValue(input);
14
25
  },
15
- (value) => {
16
- pageHead.value = value ?? null;
17
- },
26
+ write,
18
27
  { immediate: true, deep: true }
19
28
  );
29
+ if (getCurrentInstance()) {
30
+ onActivated(() => write(toValue(input)));
31
+ onBeforeUnmount(() => {
32
+ if (!page && pageHead.value === written) pageHead.value = null;
33
+ });
34
+ }
20
35
  }
21
36
  return { pageHead, resetPageHead };
22
37
  }
@@ -5,6 +5,10 @@ type CookieRef = {
5
5
  export type GetLocaleFromRoute = (route?: unknown) => string;
6
6
  export interface ResolveInitialLocaleOptions {
7
7
  route: unknown;
8
+ /** The locale the URL names, under a strategy that has one. */
9
+ urlLocale?: string | null;
10
+ /** What to remember when the URL's locale is not the visitor's: under no_prefix a record names one. */
11
+ preference?: string | null;
8
12
  serverLocale?: string | null;
9
13
  getLocaleFromRoute: GetLocaleFromRoute;
10
14
  }
@@ -18,7 +22,6 @@ export declare function useI18nLocale(): {
18
22
  hashCookie: CookieRef;
19
23
  getPreferredLocale: () => string | null;
20
24
  getLocale: () => string | null;
21
- getLocaleWithServerFallback: (serverLocale?: string | null) => string | null;
22
25
  getEffectiveLocale: (route: unknown, getLocaleFromRoute: GetLocaleFromRoute) => string;
23
26
  resolveInitialLocale: (options: ResolveInitialLocaleOptions) => string;
24
27
  setLocale: (locale: string | null) => void;
@@ -1,17 +1,21 @@
1
1
  import { getEnabledLocaleCodes } from "@i18n-micro/utils/active-locales";
2
2
  import { getHashCookieName, getLocaleCookieName, getLocaleCookieOptions } from "@i18n-micro/utils/cookie";
3
- import { resolveI18nConfigWithRuntimeOverrides } from "@i18n-micro/utils/runtime-config";
4
- import { useCookie, useNuxtApp, useState } from "#app";
5
- import { getI18nConfig } from "#build/i18n.strategy.mjs";
3
+ import { explicitLocale } from "@i18n-micro/utils/resolve-locale";
4
+ import { useCookie } from "#app/composables/cookie";
5
+ import { useState } from "#app/composables/state";
6
+ import { useNuxtApp } from "#app/nuxt";
7
+ import { cookies } from "#build/i18n.strategy.mjs";
8
+ import { useResolvedI18nConfig } from "../utils/i18n-config.js";
6
9
  export function useI18nLocale() {
7
10
  const nuxtApp = useNuxtApp();
8
- const i18nConfig = resolveI18nConfigWithRuntimeOverrides(nuxtApp.$getI18nConfig?.() ?? getI18nConfig());
11
+ const i18nConfig = useResolvedI18nConfig(nuxtApp);
9
12
  const validLocales = getEnabledLocaleCodes(i18nConfig.locales);
10
13
  const localeState = useState("i18n-locale", () => null);
11
14
  const localeCookieName = getLocaleCookieName(i18nConfig);
12
15
  const hashCookieName = getHashCookieName(i18nConfig);
13
- const localeCookie = localeCookieName ? useCookie(localeCookieName, getLocaleCookieOptions()) : { value: null };
14
- const hashCookie = hashCookieName ? useCookie(hashCookieName, getLocaleCookieOptions()) : { value: null };
16
+ const cookieRef = (name) => cookies && name ? useCookie(name, getLocaleCookieOptions()) : { value: null };
17
+ const localeCookie = cookieRef(localeCookieName);
18
+ const hashCookie = cookieRef(hashCookieName);
15
19
  const syncLocale = (locale) => {
16
20
  if (!locale) return;
17
21
  if (hashCookieName) hashCookie.value = locale;
@@ -23,41 +27,35 @@ export function useI18nLocale() {
23
27
  syncLocale(locale);
24
28
  }
25
29
  };
26
- const getPreferredLocale = () => {
27
- const preferred = localeState.value ?? (i18nConfig.hashMode ? hashCookie.value : localeCookie.value);
28
- return preferred && validLocales.includes(preferred) ? preferred : null;
29
- };
30
+ const preferenceCookie = i18nConfig.hashMode ? hashCookie : localeCookie;
31
+ const isValidLocale = (locale) => !!locale && validLocales.includes(locale);
32
+ const getPreferredLocale = () => explicitLocale({ validLocales, state: localeState.value, cookie: preferenceCookie.value });
30
33
  const getLocale = () => {
31
- return localeState.value ?? (i18nConfig.hashMode ? hashCookie.value : localeCookie.value) ?? null;
32
- };
33
- const getLocaleWithServerFallback = (serverLocale) => {
34
- return localeState.value ?? localeCookie.value ?? serverLocale ?? null;
34
+ return localeState.value ?? preferenceCookie.value ?? null;
35
35
  };
36
36
  const getEffectiveLocale = (route, getLocaleFromRoute) => {
37
37
  if (i18nConfig.hashMode && localeState.value !== null && localeState.value !== void 0) return localeState.value;
38
38
  return getLocaleFromRoute(route);
39
39
  };
40
40
  const resolveInitialLocale = (options) => {
41
- let locale = localeState.value;
42
- if (!locale && options.serverLocale) locale = options.serverLocale;
43
- if (!locale) locale = options.getLocaleFromRoute(options.route);
44
- if (locale && !localeState.value) {
41
+ const state = isValidLocale(localeState.value) ? localeState.value : null;
42
+ const locale = options.urlLocale || state || options.serverLocale || options.getLocaleFromRoute(options.route);
43
+ const remembered = options.preference ?? locale;
44
+ if (remembered && !state) {
45
45
  if (import.meta.server) {
46
- localeState.value = locale;
46
+ localeState.value = remembered;
47
47
  } else {
48
- setLocale(locale);
48
+ setLocale(remembered);
49
49
  }
50
50
  }
51
51
  return locale ?? "";
52
52
  };
53
- const isValidLocale = (locale) => !!locale && validLocales.includes(locale);
54
53
  return {
55
54
  locale: localeState,
56
55
  localeCookie,
57
56
  hashCookie,
58
57
  getPreferredLocale,
59
58
  getLocale,
60
- getLocaleWithServerFallback,
61
59
  getEffectiveLocale,
62
60
  resolveInitialLocale,
63
61
  setLocale,
@@ -1,22 +1,4 @@
1
- interface MetaLink {
2
- [key: string]: string | undefined;
3
- rel: string;
4
- href: string;
5
- hreflang?: string;
6
- }
7
- interface MetaTag {
8
- [key: string]: string;
9
- property: string;
10
- content: string;
11
- }
12
- interface MetaObject {
13
- htmlAttrs: {
14
- lang?: string;
15
- dir?: 'ltr' | 'rtl' | 'auto';
16
- };
17
- link: MetaLink[];
18
- meta: MetaTag[];
19
- }
1
+ import { type LocaleHead } from '@i18n-micro/utils/locale-head';
20
2
  interface UseLocaleHeadOptions {
21
3
  /** Set `dir` on `<html>` from the locale's direction. */
22
4
  addDirAttribute?: boolean;
@@ -36,41 +18,53 @@ interface UseLocaleHeadOptions {
36
18
  * Only needed when `meta` is disabled or the defaults need adjusting — with `meta: true`
37
19
  * the module registers the same tags itself.
38
20
  *
39
- * @returns a ref holding the head object, ready to pass to `useHead`
21
+ * @returns `metaObject`, a ref holding the head object ready to pass to `useHead`; `updateMeta`
22
+ * refreshes it; `build` computes the head object from the current route (reactive when read in
23
+ * a getter, e.g. `useHead(() => build())`)
40
24
  * @example
41
25
  * ```ts
42
- * const head = useLocaleHead({ addSeoAttributes: true })
43
- * useHead(head)
26
+ * const { metaObject } = useLocaleHead({ addSeoAttributes: true })
27
+ * useHead(metaObject)
44
28
  * ```
45
29
  */
46
30
  export declare const useLocaleHead: ({ addDirAttribute, identifierAttribute, addSeoAttributes, baseUrl, autoUpdate, }?: UseLocaleHeadOptions) => {
47
31
  metaObject: import("vue").Ref<{
48
32
  htmlAttrs: {
33
+ [x: string]: string | undefined;
49
34
  lang?: string | undefined;
50
35
  dir?: "ltr" | "rtl" | "auto" | undefined;
51
36
  };
52
- link: {
37
+ link: ({
53
38
  [x: string]: string | undefined;
54
- rel: string;
39
+ rel: "canonical";
55
40
  href: string;
56
- hreflang?: string | undefined;
57
- }[];
41
+ } | {
42
+ [x: string]: string | undefined;
43
+ rel: "alternate";
44
+ href: string;
45
+ hreflang: string;
46
+ })[];
58
47
  meta: {
59
48
  [x: string]: string;
60
49
  property: string;
61
50
  content: string;
62
51
  }[];
63
- }, MetaObject | {
52
+ }, LocaleHead | {
64
53
  htmlAttrs: {
54
+ [x: string]: string | undefined;
65
55
  lang?: string | undefined;
66
56
  dir?: "ltr" | "rtl" | "auto" | undefined;
67
57
  };
68
- link: {
58
+ link: ({
69
59
  [x: string]: string | undefined;
70
- rel: string;
60
+ rel: "canonical";
71
61
  href: string;
72
- hreflang?: string | undefined;
73
- }[];
62
+ } | {
63
+ [x: string]: string | undefined;
64
+ rel: "alternate";
65
+ href: string;
66
+ hreflang: string;
67
+ })[];
74
68
  meta: {
75
69
  [x: string]: string;
76
70
  property: string;
@@ -78,5 +72,6 @@ export declare const useLocaleHead: ({ addDirAttribute, identifierAttribute, add
78
72
  }[];
79
73
  }>;
80
74
  updateMeta: () => void;
75
+ build: () => LocaleHead;
81
76
  };
82
77
  export {};