feat: add i18n support for notification templates#3105
feat: add i18n support for notification templates#3105jeff-se wants to merge 1 commit intoccfos:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds configurable i18n support for the built-in notification templates used by “Chinese messaging platform” channels, allowing center deployments to switch default templates to English via a new [Center].NotificationLang setting.
Changes:
- Introduces
Center.NotificationLangconfig field and wires it into center startup. - Adds
ApplyNotificationLang()to overrideNewTplMapwith English template strings (newTplMapEn) when configured. - Switches message-template initialization to rebuild templates from
NewTplMapat call time (buildMsgTplMap()), so language overrides take effect.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
models/message_tpl.go |
Adds English template map, language-override hook, and rebuilds template list at init time to honor overrides. |
center/center.go |
Calls models.ApplyNotificationLang(config.Center.NotificationLang) before starting alert initialization. |
center/cconf/conf.go |
Adds NotificationLang to center config struct. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // buildMsgTplMap rebuilds the template list from NewTplMap at call time, | ||
| // ensuring it reflects any language overrides applied by ApplyNotificationLang. | ||
| func buildMsgTplMap() []MessageTemplate { | ||
| return []MessageTemplate{ | ||
| {Name: "Jira", Ident: Jira, Weight: 18, Content: map[string]string{"content": NewTplMap[Jira]}}, |
There was a problem hiding this comment.
MsgTplMap is still defined as a package-level slice initialized from NewTplMap. Since that initialization happens before ApplyNotificationLang() runs, any future/accidental use of MsgTplMap would silently bypass the language override. To avoid two sources of truth (and a potential regression later), consider removing MsgTplMap entirely or refactoring so callers can only obtain templates via buildMsgTplMap() (or an exported function that rebuilds from NewTplMap).
| func ApplyNotificationLang(lang string) { | ||
| if lang == "" || strings.HasPrefix(lang, "zh") { | ||
| return | ||
| } | ||
| if lang == "en" { | ||
| for k, v := range newTplMapEn { | ||
| NewTplMap[k] = v | ||
| } | ||
| } |
There was a problem hiding this comment.
ApplyNotificationLang does strict, case-sensitive matching on lang (e.g. only exactly "en" enables English). Since this comes from config, it would be more robust to normalize first (e.g. trim whitespace and lower-case) and optionally accept common variants like "en-US"/"en_US" (similar to how "zh*" is handled).
1e4e1df to
f0e9e17
Compare
|
@710leo Kind ping — could you take a look when you have a moment? Copilot's review comments have been addressed. Thanks! |
Add English translations for all notification template channels
(Dingtalk, Email, Feishu, FeishuCard, Lark, LarkCard, Telegram,
Wecom, Mattermost) controlled via config.toml:
[Center]
NotificationLang = "en"
Default behavior is unchanged — without this setting, all existing
Chinese templates are preserved. Channels already in English (Slack,
Discord, Jira) are unaffected.
English label terminology is aligned with the existing upstream
English templates (Jira, Discord) for consistency:
Severity, Rule Name, Rule Note, Metrics, Monitor Target,
Trigger Value, Trigger Time, Recovery Time, Duration, etc.
d3ec621 to
ea1830f
Compare
What type of PR is this?
Feature
What this PR does / why we need it:
Currently all notification templates for Chinese messaging platforms (Dingtalk, Feishu, Lark, Wecom, Telegram, Email, Mattermost) are hardcoded in Chinese, while international platforms (Slack, Discord, Jira) are already in English. There is no way to switch the language for Chinese-platform templates when deploying in international environments.
This PR adds a
NotificationLangconfig option under[Center]:Implementation:
newTplMapEnmap holds English translations for all Chinese-language channelsApplyNotificationLang()is called beforeInitMessageTemplateto overrideNewTplMapbuildMsgTplMap()replaces the staticMsgTplMapvar to readNewTplMapat call time, ensuring language overrides take effectWhich issue(s) this PR fixes:
N/A - new feature
Special notes for your reviewer:
models/message_tpl.gocontains substantial changes (+280 lines, all English template strings); the other two files are one-line wiring changes