mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-28 05:39:34 +08:00
wip: multi-language support
This commit is contained in:
@@ -14,9 +14,7 @@ function isAuth(el: Element, binding: any) {
|
||||
const value = binding.value;
|
||||
if (!value) return;
|
||||
if (!hasPermission(value)) {
|
||||
if (el.parentNode) {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
el.parentNode?.removeChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ const repeatDirective: Directive = {
|
||||
beforeMount(el: Element, binding: DirectiveBinding<any>) {
|
||||
let interval: Nullable<IntervalHandle> = null;
|
||||
let startTime = 0;
|
||||
const handler = (): void => binding.value && binding.value();
|
||||
const handler = (): void => binding?.value();
|
||||
const clear = (): void => {
|
||||
if (Date.now() - startTime < 100) {
|
||||
handler();
|
||||
|
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { errorStore, ErrorInfo } from '/@/store/modules/error';
|
||||
import { useSetting } from '/@/hooks/core/useSetting';
|
||||
import { useProjectSetting } from '/@/settings/use';
|
||||
import { ErrorTypeEnum } from '/@/enums/exceptionEnum';
|
||||
import { App } from 'vue';
|
||||
|
||||
@@ -89,7 +89,7 @@ export function scriptErrorHandler(
|
||||
const errorInfo: Partial<ErrorInfo> = {};
|
||||
colno = colno || (window.event && (window.event as any).errorCharacter) || 0;
|
||||
errorInfo.message = event as string;
|
||||
if (error && error.stack) {
|
||||
if (error?.stack) {
|
||||
errorInfo.stack = error.stack;
|
||||
} else {
|
||||
errorInfo.stack = '';
|
||||
@@ -160,8 +160,7 @@ function registerResourceErrorHandler() {
|
||||
* @param app
|
||||
*/
|
||||
export function setupErrorHandle(app: App) {
|
||||
const { projectSetting } = useSetting();
|
||||
const { useErrorHandle } = projectSetting;
|
||||
const { useErrorHandle } = useProjectSetting();
|
||||
if (!useErrorHandle) return;
|
||||
// Vue exception monitoring;
|
||||
app.config.errorHandler = vueErrorHandler;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import type { App } from 'vue';
|
||||
import type { I18n, Locale, I18nOptions } from 'vue-i18n';
|
||||
import { App, unref } from 'vue';
|
||||
import type { I18n, I18nOptions } from 'vue-i18n';
|
||||
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import localeMessages from '/@/locales';
|
||||
import { useLocale } from '/@/hooks/web/useLocale';
|
||||
import { useLocaleSetting } from '/@/settings/use/useLocaleSetting';
|
||||
|
||||
const { getLocale } = useLocale();
|
||||
const { setupLocale } = useLocale();
|
||||
|
||||
const { getLang, getAvailableLocales, getFallbackLocale } = useLocaleSetting();
|
||||
const localeData: I18nOptions = {
|
||||
legacy: false,
|
||||
locale: getLocale(),
|
||||
// TODO: setting fallback inside settings
|
||||
fallbackLocale: 'en',
|
||||
locale: unref(getLang),
|
||||
fallbackLocale: unref(getFallbackLocale),
|
||||
messages: localeMessages,
|
||||
// availableLocales: ['ru'],
|
||||
availableLocales: unref(getAvailableLocales),
|
||||
sync: true, //If you don’t want to inherit locale from global scope, you need to set sync of i18n component option to false.
|
||||
silentTranslationWarn: false, // true - warning off
|
||||
silentFallbackWarn: true,
|
||||
@@ -24,12 +25,10 @@ let i18n: I18n;
|
||||
// setup i18n instance with glob
|
||||
export function setupI18n(app: App) {
|
||||
i18n = createI18n(localeData) as I18n;
|
||||
setI18nLanguage(getLocale());
|
||||
setupLocale();
|
||||
app.use(i18n);
|
||||
}
|
||||
|
||||
export function setI18nLanguage(locale: Locale): void {
|
||||
// @ts-ignore
|
||||
i18n.global.locale.value = locale;
|
||||
// i18n.global.setLocaleMessage(locale, messages);
|
||||
export function getI18n(): I18n {
|
||||
return i18n;
|
||||
}
|
||||
|
Reference in New Issue
Block a user