Skip to content

feat: add i18n support for notification templates#3105

Open
jeff-se wants to merge 1 commit intoccfos:mainfrom
jeff-se:feat/i18n-notification-templates
Open

feat: add i18n support for notification templates#3105
jeff-se wants to merge 1 commit intoccfos:mainfrom
jeff-se:feat/i18n-notification-templates

Conversation

@jeff-se
Copy link
Copy Markdown

@jeff-se jeff-se commented Mar 28, 2026

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 NotificationLang config option under [Center]:

[Center]
NotificationLang = "en"
  • Default behavior unchanged — without this setting, all existing Chinese templates are preserved
  • English label terminology aligned with existing upstream Slack/Discord/Jira templates (Severity, Rule Name, Trigger Value, Recovery Time, Duration, etc.)
  • No database schema changes required
  • Channels already in English (Slack, Discord, Jira, Mattermost) are unaffected

Implementation:

  • newTplMapEn map holds English translations for all Chinese-language channels
  • ApplyNotificationLang() is called before InitMessageTemplate to override NewTplMap
  • buildMsgTplMap() replaces the static MsgTplMap var to read NewTplMap at call time, ensuring language overrides take effect

Which issue(s) this PR fixes:
N/A - new feature

Special notes for your reviewer:

  • Tested with Lark Card notifications in production — English templates render correctly with proper formatting
  • Only models/message_tpl.go contains substantial changes (+280 lines, all English template strings); the other two files are one-line wiring changes

Copilot AI review requested due to automatic review settings March 28, 2026 22:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.NotificationLang config field and wires it into center startup.
  • Adds ApplyNotificationLang() to override NewTplMap with English template strings (newTplMapEn) when configured.
  • Switches message-template initialization to rebuild templates from NewTplMap at 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.

Comment thread models/message_tpl.go Outdated
Comment on lines +666 to +670
// 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]}},
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment thread models/message_tpl.go
Comment on lines +988 to +996
func ApplyNotificationLang(lang string) {
if lang == "" || strings.HasPrefix(lang, "zh") {
return
}
if lang == "en" {
for k, v := range newTplMapEn {
NewTplMap[k] = v
}
}
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@jeff-se jeff-se force-pushed the feat/i18n-notification-templates branch 2 times, most recently from 1e4e1df to f0e9e17 Compare March 31, 2026 22:47
@jeff-se
Copy link
Copy Markdown
Author

jeff-se commented Apr 19, 2026

@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.
@jeff-se jeff-se force-pushed the feat/i18n-notification-templates branch from d3ec621 to ea1830f Compare April 23, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants