jointrashposs/composables/useGSwitchLocalePath.ts

12 lines
473 B
TypeScript
Raw Normal View History

import type { LocaleCodes } from '@/assets/data/locales';
import { locales } from "@/assets/data/locales";
2024-01-21 09:27:49 +01:00
/** useSwitchLocalePathのラッパー関数。 */
export function useGSwitchLocalePath() {
const switchLocalePath = useSwitchLocalePath();
return (locale: LocaleCodes) => {
const _path = switchLocalePath(locale);
return new RegExp(`^/(${locales.map((v) => v.code).join('|')})/`).test(_path) ? _path : `/${locales[0].code}${_path}`;
}
2024-01-21 09:27:49 +01:00
}