From 7cb45d05a02b88c840c75c7085f8be6c0b50d36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Thu, 24 Feb 2022 00:00:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(i18n.ts):=20=E5=9B=BD=E9=99=85=E5=8C=96i18?= =?UTF-8?q?n=E5=B7=A5=E5=85=B7=E7=B1=BB=E5=92=8C=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=9B=BD=E9=99=85=E5=8C=96=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95generateTitle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/i18n.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/utils/i18n.ts diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts new file mode 100644 index 00000000..06d8dede --- /dev/null +++ b/src/utils/i18n.ts @@ -0,0 +1,12 @@ +// translate router.meta.title, be used in breadcrumb sidebar tagsview +import i18n from "@/lang/index"; + +export function generateTitle(title: any) { + // 判断是否存在国际化配置,如果没有原生返回 + const hasKey = i18n.global.te('route.' + title) + if (hasKey) { + const translatedTitle = i18n.global.t('route.' + title) + return translatedTitle + } + return title +} \ No newline at end of file