- Added support for German (de), French (fr), and Japanese (ja) languages, expanding the localization capabilities of the application. - Updated the LanguageSwitcher component to include new language options and a search feature for better user experience. - Enhanced the HeroSection with dynamic download URLs and a release version badge for improved visibility of updates. - Refactored the ScreenshotsSection to utilize a new data structure for screenshots, improving maintainability and performance. - Improved the styling of various components, including the addition of search functionality in the LanguageSwitcher and adjustments to the layout of the HeroSection. - Fixed type handling in several components to ensure better TypeScript compatibility and reduce potential runtime errors.
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import { supportedLocales } from "~/data/i18n";
|
|
import { useLocaleStore } from "~/stores/locale";
|
|
|
|
export const useLocation = () => {
|
|
const nuxtApp = useNuxtApp();
|
|
const i18n = nuxtApp.$i18n as { locale?: { value: string }; setLocale?: (code: string) => void } | undefined;
|
|
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: readonly string[] = 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 };
|
|
};
|