import type { VueI18n } from "vue-i18n"; import { usePB } from "~/composables/usePB"; import type { GenericResponse } from "~/types"; export default defineNuxtPlugin(async (nuxtApp) => { const loaded = [] as Array; const i18n = nuxtApp.$i18n as VueI18n; const pb = usePB(); i18n.onBeforeLanguageSwitch = async (oldLocale, newLocale) => { if (loaded.includes(newLocale)) return; try { // const translation = await pb.collection("translation").getList(1, 1, { // expand: "id_lang", // filter: `id_lang.iso='${newLocale}'`, // }); const { data } = await useMyFetch>( "/api/public/front/translation" ); i18n.setLocaleMessage(newLocale, data); loaded.push(newLocale); } catch (err) { console.error("❌ Failed to load translation for locale:", newLocale); throw err; } }; });