@frigear-nu/menu 0.0.7 → 0.0.8

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/module.d.mts CHANGED
@@ -16,7 +16,15 @@ type MenuItem = {
16
16
  * entries, so content-sourced and module-sourced items share the exact same shape.
17
17
  */
18
18
  label: string;
19
+ /**
20
+ * Optional i18n key (e.g. `users.menu.logout.label`). When `@nuxtjs/i18n` is installed and the
21
+ * key exists for the active locale, `useMenu` returns its translation as `label`; otherwise the
22
+ * plain `label` above is the fallback. Ids are always derived from the untranslated `label`.
23
+ */
24
+ labelKey?: string;
19
25
  description?: string;
26
+ /** Optional i18n key for `description`, resolved the same way as `labelKey`. */
27
+ descriptionKey?: string;
20
28
  icon?: string;
21
29
  to?: string;
22
30
  external?: boolean;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/menu",
3
3
  "configKey": "menus",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
@@ -1,6 +1,6 @@
1
1
  import { computed, unref } from "vue";
2
2
  import { useAsyncData, useNuxtApp, useRuntimeConfig } from "#imports";
3
- import { collectMenuItems, matchesMenuGroup, parseMenuPath, sortByOrder } from "../../utils/menu.js";
3
+ import { collectMenuItems, matchesMenuGroup, parseMenuPath, sortByOrder, translateMenuItem } from "../../utils/menu.js";
4
4
  import { menus } from "../utils/state.js";
5
5
  function useMenuLocale() {
6
6
  const nuxtApp = useNuxtApp();
@@ -29,7 +29,8 @@ export const useMenu = (path) => {
29
29
  return useAsyncData(
30
30
  () => `menu:${path}:${locale.value ?? ""}`,
31
31
  async () => {
32
- const registered = collectMenuItems(menus[menu], parsed);
32
+ const i18n = nuxtApp.$i18n?.t && nuxtApp.$i18n.te ? nuxtApp.$i18n : void 0;
33
+ const registered = collectMenuItems(menus[menu], parsed).map((item) => translateMenuItem(item, i18n));
33
34
  const content = await loadContentItems(menu, parsed, unref(locale));
34
35
  const result = sortByOrder([...content, ...registered]);
35
36
  await nuxtApp.callHook("menus:visible", menu);
@@ -37,6 +37,17 @@ export declare function collectMenuItems(groups: Record<string, MenuItem[]> | un
37
37
  export declare function sortByOrder(items: MenuItem[]): MenuItem[];
38
38
  /** Deterministic id for an item missing one: its `to` if present, else a slug of its `label`. */
39
39
  export declare function deriveMenuItemId(item: MenuItem): string;
40
+ /** The slice of `@nuxtjs/i18n`'s `$i18n` that `translateMenuItem` needs. */
41
+ export type MenuTranslator = {
42
+ t: (key: string) => string;
43
+ te: (key: string) => boolean;
44
+ };
45
+ /**
46
+ * Resolves an item's `labelKey`/`descriptionKey` against the active locale, falling back to the
47
+ * plain `label`/`description` when no translator is available or the key has no message. The
48
+ * `id` is derived first, so it stays identical across locales.
49
+ */
50
+ export declare function translateMenuItem(item: MenuItem, i18n?: MenuTranslator): MenuItem;
40
51
  /**
41
52
  * Build-time API for other modules to contribute static items to a menu, without the host app
42
53
  * wiring anything. Call it once during a module's own `setup()`:
@@ -46,6 +46,14 @@ function slugify(value) {
46
46
  export function deriveMenuItemId(item) {
47
47
  return item.id ?? item.to ?? slugify(item.label);
48
48
  }
49
+ export function translateMenuItem(item, i18n) {
50
+ if (!i18n || !item.labelKey && !item.descriptionKey) return item;
51
+ const id = deriveMenuItemId(item);
52
+ const translated = { ...item, id };
53
+ if (item.labelKey && i18n.te(item.labelKey)) translated.label = i18n.t(item.labelKey);
54
+ if (item.descriptionKey && i18n.te(item.descriptionKey)) translated.description = i18n.t(item.descriptionKey);
55
+ return translated;
56
+ }
49
57
  function normalizeItems(group, items) {
50
58
  const list = Array.isArray(items) ? items : [items];
51
59
  const seen = /* @__PURE__ */ new Set();
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@frigear-nu/menu",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Named, shareable navigation menus - modules contribute items (extendMenu / a runtime/menus.ts source) and/or Nuxt Content, consumers read them via useMenu and render them however they like.",
5
+ "homepage": "https://docs.frigear.dev/modules/menu",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "git+https://github.com/frigear-nu/frigear-nu.git",
@@ -30,7 +31,7 @@
30
31
  ],
31
32
  "dependencies": {
32
33
  "@nuxt/kit": "^4.6.0",
33
- "@frigear-nu/module-kit": "0.1.5",
34
+ "@frigear-nu/module-kit": "0.1.6",
34
35
  "zod": "^4.6.5"
35
36
  },
36
37
  "devDependencies": {