wip: multi-language support

This commit is contained in:
vben
2020-11-23 00:35:15 +08:00
parent b49950a390
commit 737b1b190c
59 changed files with 512 additions and 272 deletions

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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 dont 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;
}