feat(i18n): enhance notification templates with raw message handling

Updated the notification system to utilize the `tm` function for template resolution, ensuring that placeholders like `{name}` and `{role}` remain intact for proper rendering. This change improves the display of workspace and role information in login and tenant switch notifications, allowing for better localization and visual consistency across the application. Adjustments were made in `App.vue`, `Login.vue`, and related utility functions to accommodate the new template handling.
This commit is contained in:
wizardchen
2026-05-18 20:37:31 +08:00
committed by lyingbug
parent 559b5a6e20
commit 4344765cf9
4 changed files with 99 additions and 121 deletions
+9 -3
View File
@@ -18,7 +18,7 @@ import zhCNConfig from 'tdesign-vue-next/esm/locale/zh_CN'
import koKRConfig from 'tdesign-vue-next/esm/locale/ko_KR'
import ruRUConfig from 'tdesign-vue-next/esm/locale/ru_RU'
const { locale, t } = useI18n()
const { locale, t, tm } = useI18n()
const { formatRole, roleIcon } = useRoleLabel()
const router = useRouter()
const authStore = useAuthStore()
@@ -144,7 +144,7 @@ const handleGlobalOIDCCallback = async () => {
if (response.success) {
clearOIDCCallbackState('/')
await persistOIDCLoginResponse(response)
notifyLoginSuccess(response, t, formatRole, roleIcon)
notifyLoginSuccess(response, t, tm, formatRole, roleIcon)
return
}
@@ -207,10 +207,16 @@ const showPendingTenantSwitchToast = () => {
const templateKey = pending.role
? 'tenant.switchSuccessContentWithRole'
: 'tenant.switchSuccessContent'
// Use tm() not t() — vue-i18n v11's `t()` replaces unspecified named
// placeholders with empty strings, which would strip {name}/{role}
// before the chip renderer can split on them. tm() returns the raw
// message verbatim.
const rawTemplate = tm(templateKey)
const template = typeof rawTemplate === 'string' ? rawTemplate : ''
NotifyPlugin.success({
title: t('tenant.switchSuccessTitle'),
content: renderWorkspaceNotifyContent({
template: t(templateKey),
template,
name: pending.name,
roleLabel: pending.role,
roleEnum: pending.roleEnum,