| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { useNav } from "./useNav";
- import { useI18n } from "vue-i18n";
- import { useRoute } from "vue-router";
- import { watch, onBeforeMount, type Ref } from "vue";
- export function useTranslationLang(ref?: Ref) {
- const { $storage, changeTitle, handleResize } = useNav();
- const { locale, t } = useI18n();
- const route = useRoute();
- function translationCh() {
- $storage.locale = { locale: "zh" };
- locale.value = "zh";
- ref && handleResize(ref.value);
- }
- function translationEn() {
- $storage.locale = { locale: "en" };
- locale.value = "en";
- ref && handleResize(ref.value);
- }
- watch(
- () => locale.value,
- () => {
- changeTitle(route.meta);
- }
- );
- onBeforeMount(() => {
- locale.value = $storage.locale?.locale ?? "zh";
- });
- return {
- t,
- route,
- locale,
- translationCh,
- translationEn
- };
- }
|