|
1 | 1 | import { callWithNuxt } from '#app' |
2 | 2 | import { defu } from 'defu' |
3 | | -import { useRuntimeConfig, useState, useFetch, navigateTo, createError, useRoute, h, resolveComponent, setResponseStatus, useNuxtApp, useRequestHeaders, UseFetchOptions } from '#imports' |
| 3 | +import { useRuntimeConfig, useState, useFetch, navigateTo, createError, h, resolveComponent, setResponseStatus, useNuxtApp, useRequestHeaders, UseFetchOptions, ref, watch } from '#imports' |
4 | 4 |
|
5 | 5 | export const useDrupalCe = () => { |
6 | 6 |
|
@@ -71,10 +71,21 @@ export const useDrupalCe = () => { |
71 | 71 | * @param useFetchOptions Optional Nuxt useFetch options |
72 | 72 | */ |
73 | 73 | const fetchMenu = async (name: string, useFetchOptions:UseFetchOptions<any> = {}) => { |
74 | | - const menuPath = config.menuEndpoint.replace('$$$NAME$$$', name) |
| 74 | + const nuxtApp = useNuxtApp() |
75 | 75 | useFetchOptions = processFetchOptions(useFetchOptions) |
76 | 76 | useFetchOptions.key = `menu-${name}` |
77 | 77 |
|
| 78 | + const baseMenuPath = config.menuEndpoint.replace('$$$NAME$$$', name) |
| 79 | + const menuPath = ref(baseMenuPath) |
| 80 | + |
| 81 | + if (config.useLocalizedMenuEndpoint && nuxtApp.$i18n) { |
| 82 | + // API path with localization |
| 83 | + menuPath.value = nuxtApp.$localePath('/' + baseMenuPath) |
| 84 | + watch(nuxtApp.$i18n.locale, () => { |
| 85 | + menuPath.value = nuxtApp.$localePath('/' + baseMenuPath) |
| 86 | + }) |
| 87 | + } |
| 88 | + |
78 | 89 | const { data: menu, error } = await useFetch(menuPath, useFetchOptions) |
79 | 90 |
|
80 | 91 | if (error.value) { |
|
0 commit comments