mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-15 14:03:36 +08:00
perf: login
This commit is contained in:
38
src/layout/hooks/useTranslationLang.ts
Normal file
38
src/layout/hooks/useTranslationLang.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useNav } from "./nav";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute } from "vue-router";
|
||||
import { watch, getCurrentInstance } from "vue";
|
||||
|
||||
export default function useTranslationLang() {
|
||||
const { changeTitle, changeWangeditorLanguage } = useNav();
|
||||
const { locale, t } = useI18n();
|
||||
const route = useRoute();
|
||||
const instance =
|
||||
getCurrentInstance().appContext.config.globalProperties.$storage;
|
||||
|
||||
function translationCh() {
|
||||
instance.locale = { locale: "zh" };
|
||||
locale.value = "zh";
|
||||
}
|
||||
|
||||
function translationEn() {
|
||||
instance.locale = { locale: "en" };
|
||||
locale.value = "en";
|
||||
}
|
||||
|
||||
watch(
|
||||
() => locale.value,
|
||||
() => {
|
||||
changeTitle(route.meta);
|
||||
locale.value === "en"
|
||||
? changeWangeditorLanguage(locale.value)
|
||||
: changeWangeditorLanguage("zh-CN");
|
||||
}
|
||||
);
|
||||
return {
|
||||
t,
|
||||
locale,
|
||||
translationCh,
|
||||
translationEn
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user