agent-ecosystem/landing/composables/useLocation.ts
iliya 0bc8bf1fe9 feat(landing): enhance base URL handling and improve image paths
- Introduced baseURL configuration to dynamically set asset paths in the landing components.
- Updated AppLogo and HeroSection components to use baseURL for logo image sources.
- Refactored ScreenshotsSection to utilize a publicPath function for consistent image path handling.
- Improved LanguageSwitcher to synchronize the i18n locale with the store on mount.
- Enhanced TaskCommentInput to handle file uploads more robustly, including validation for empty files and improved error handling.
- Adjusted MessageComposer to conditionally support attachments based on team status.
2026-03-23 17:51:09 +02:00

43 lines
1.4 KiB
TypeScript

import { supportedLocales } from "~/data/i18n";
import { useLocaleStore } from "~/stores/locale";
export const useLocation = () => {
const nuxtApp = useNuxtApp();
const i18n = nuxtApp.$i18n;
const localeStore = useLocaleStore();
const cookie = useCookie("i18n_redirected", { default: () => "" });
const getBrowserLocale = () => {
if (!process.client) return "en";
const browserLocale = navigator.language || "en";
const normalized = browserLocale.split("-")[0].toLowerCase();
const supported = supportedLocales.map((item) => item.code);
return supported.includes(normalized) ? normalized : "en";
};
const initLocale = () => {
// Sync store with actual i18n locale (already resolved from route by nuxt-i18n)
const currentLocale = i18n?.locale?.value || "en";
if (cookie.value) {
// Cookie exists — sync store, but don't override route-based locale
localeStore.setLocale(currentLocale, false);
if (cookie.value !== currentLocale) {
cookie.value = currentLocale;
}
return;
}
// No cookie — detect from browser and set
const detected = getBrowserLocale();
localeStore.setLocale(detected, false);
if (i18n?.setLocale) {
i18n.setLocale(detected);
} else if (i18n?.locale?.value) {
i18n.locale.value = detected;
}
cookie.value = detected;
};
return { initLocale, getBrowserLocale };
};