Skip to content

Collection of handy online tools for developers, with great UX.

feat(i18n): support for i18n in .ts files (#683)

莫颓ebb4ec416511
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;
+};