From ebb4ec416511c02108704e3909c565aa47890b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=AB=E9=A2=93?= Date: Sun, 22 Oct 2023 16:23:00 +0800 Subject: [PATCH] feat(i18n): support for i18n in .ts files (#683) (cherry picked from commit 732313bfc32a514ef064ca0f90304ff05e2e7ef3) --- src/plugins/i18n.plugin.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/i18n.plugin.ts b/src/plugins/i18n.plugin.ts index 8e0b2d33..7ef2c98f 100644 --- a/src/plugins/i18n.plugin.ts +++ b/src/plugins/i18n.plugin.ts @@ -29,3 +29,9 @@ export const i18nPlugin: Plugin = { app.use(i18n); }, }; + +export const translate = function (localeKey: string) { + // @ts-expect-error global + const hasKey = i18n.global.te(localeKey, i18n.global.locale); + return hasKey ? i18n.global.t(localeKey) : localeKey; +};