From 250bb8ec991b970ea23c48d1e48b256ccd2b091a Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 2 Mar 2025 12:28:15 +0100 Subject: [PATCH] fix(i18n): pass language to notification mail function --- magefile.go | 8 +- pkg/models/main_test.go | 3 + pkg/models/notifications.go | 94 +++++++------- .../migration/handler/notifications.go | 6 +- pkg/notifications/main_test.go | 2 +- pkg/notifications/notification.go | 4 +- pkg/notifications/notification_test.go | 2 +- pkg/user/notifications.go | 118 +++++++++--------- 8 files changed, 118 insertions(+), 119 deletions(-) diff --git a/magefile.go b/magefile.go index 7341d24e0..016e07c59 100644 --- a/magefile.go +++ b/magefile.go @@ -536,7 +536,7 @@ func walkCodebaseForTranslationKeys(rootDir string) ([]TranslationKey, error) { return allKeys, err } -// extractTranslationKeysFromFile extracts all i18n.T and i18n.TWithParams calls from a file +// extractTranslationKeysFromFile extracts all i18n.T calls from a file func extractTranslationKeysFromFile(filePath string) ([]TranslationKey, error) { // Read the file content content, err := os.ReadFile(filePath) @@ -546,8 +546,8 @@ func extractTranslationKeysFromFile(filePath string) ([]TranslationKey, error) { var keys []TranslationKey - // Regex to match i18n.T and i18n.TWithParams calls - re := regexp.MustCompile(`i18n\.(T|TWithParams)\([^,]+,\s*"([^"]+)"`) + // Regex to match i18n.T calls + re := regexp.MustCompile(`i18n\.(T)\([^,]+,\s*"([^"]+)"`) matches := re.FindAllSubmatchIndex(content, -1) for _, match := range matches { @@ -1141,7 +1141,7 @@ type ` + name + ` struct { } // ToMail returns the mail notification for ` + name + ` -func (n *` + name + `) ToMail() *notifications.Mail { +func (n *` + name + `) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). Subject(""). Greeting("Hi "). diff --git a/pkg/models/main_test.go b/pkg/models/main_test.go index 6ff126080..a4d4cb30c 100644 --- a/pkg/models/main_test.go +++ b/pkg/models/main_test.go @@ -25,6 +25,7 @@ import ( "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/events" "code.vikunja.io/api/pkg/files" + "code.vikunja.io/api/pkg/i18n" "code.vikunja.io/api/pkg/user" ) @@ -58,6 +59,8 @@ func TestMain(m *testing.M) { // We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH")) + i18n.Init() + // Some tests use the file engine, so we'll need to initialize that files.InitTests() diff --git a/pkg/models/notifications.go b/pkg/models/notifications.go index 7049b9812..e2399592a 100644 --- a/pkg/models/notifications.go +++ b/pkg/models/notifications.go @@ -36,15 +36,15 @@ type ReminderDueNotification struct { } // ToMail returns the mail notification for ReminderDueNotification -func (n *ReminderDueNotification) ToMail() *notifications.Mail { +func (n *ReminderDueNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). IncludeLinkToSettings(). To(n.User.Email). - Subject(i18n.TWithParams(n.User.Language, "notifications.task.reminder.subject", n.Task.Title, n.Project.Title)). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.TWithParams(n.User.Language, "notifications.task.reminder.message", n.Task.Title, n.Project.Title)). + Subject(i18n.T(lang, "notifications.task.reminder.subject", n.Task.Title, n.Project.Title)). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.task.reminder.message", n.Task.Title, n.Project.Title)). Action("Open Task", config.ServicePublicURL.GetString()+"tasks/"+strconv.FormatInt(n.Task.ID, 10)). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the ReminderDueNotification notification in a format which can be saved in the db @@ -66,7 +66,6 @@ type TaskCommentNotification struct { Task *Task `json:"task"` Comment *TaskComment `json:"comment"` Mentioned bool `json:"mentioned"` - User *user.User `json:"-"` // Target user } func (n *TaskCommentNotification) SubjectID() int64 { @@ -74,16 +73,16 @@ func (n *TaskCommentNotification) SubjectID() int64 { } // ToMail returns the mail notification for TaskCommentNotification -func (n *TaskCommentNotification) ToMail() *notifications.Mail { +func (n *TaskCommentNotification) ToMail(lang string) *notifications.Mail { mail := notifications.NewMail(). From(n.Doer.GetNameAndFromEmail()). - Subject(i18n.TWithParams(n.User.Language, "notifications.task.comment.subject", n.Task.Title)) + Subject(i18n.T(lang, "notifications.task.comment.subject", n.Task.Title)) if n.Mentioned { mail. - Line(i18n.TWithParams(n.User.Language, "notifications.task.comment.mentioned_message", n.Doer.GetName())). - Subject(i18n.TWithParams(n.User.Language, "notifications.task.comment.mentioned_subject", n.Doer.GetName(), n.Task.Title)) + Line(i18n.T(lang, "notifications.task.comment.mentioned_message", n.Doer.GetName())). + Subject(i18n.T(lang, "notifications.task.comment.mentioned_subject", n.Doer.GetName(), n.Task.Title)) } mail.HTML(n.Comment.Comment) @@ -111,17 +110,17 @@ type TaskAssignedNotification struct { } // ToMail returns the mail notification for TaskAssignedNotification -func (n *TaskAssignedNotification) ToMail() *notifications.Mail { +func (n *TaskAssignedNotification) ToMail(lang string) *notifications.Mail { if n.Target.ID == n.Assignee.ID { return notifications.NewMail(). - Subject(i18n.TWithParams(n.Target.Language, "notifications.task.assigned.subject_to_assignee", n.Task.Title, n.Task.GetFullIdentifier())). - Line(i18n.TWithParams(n.Target.Language, "notifications.task.assigned.message_to_assignee", n.Doer.GetName(), n.Task.Title)). + Subject(i18n.T(lang, "notifications.task.assigned.subject_to_assignee", n.Task.Title, n.Task.GetFullIdentifier())). + Line(i18n.T(lang, "notifications.task.assigned.message_to_assignee", n.Doer.GetName(), n.Task.Title)). Action("View Task", n.Task.GetFrontendURL()) } return notifications.NewMail(). - Subject(i18n.TWithParams(n.Target.Language, "notifications.task.assigned.subject_to_others", n.Task.Title, n.Task.GetFullIdentifier(), n.Assignee.GetName())). - Line(i18n.TWithParams(n.Target.Language, "notifications.task.assigned.message_to_others", n.Doer.GetName(), n.Assignee.GetName())). + Subject(i18n.T(lang, "notifications.task.assigned.subject_to_others", n.Task.Title, n.Task.GetFullIdentifier(), n.Assignee.GetName())). + Line(i18n.T(lang, "notifications.task.assigned.message_to_others", n.Doer.GetName(), n.Assignee.GetName())). Action("View Task", n.Task.GetFrontendURL()) } @@ -139,14 +138,13 @@ func (n *TaskAssignedNotification) Name() string { type TaskDeletedNotification struct { Doer *user.User `json:"doer"` Task *Task `json:"task"` - User *user.User `json:"-"` // Target user } // ToMail returns the mail notification for TaskDeletedNotification -func (n *TaskDeletedNotification) ToMail() *notifications.Mail { +func (n *TaskDeletedNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.TWithParams(n.User.Language, "notifications.task.deleted.subject", n.Task.Title, n.Task.GetFullIdentifier())). - Line(i18n.TWithParams(n.User.Language, "notifications.task.deleted.message", n.Doer.GetName(), n.Task.Title, n.Task.GetFullIdentifier())) + Subject(i18n.T(lang, "notifications.task.deleted.subject", n.Task.Title, n.Task.GetFullIdentifier())). + Line(i18n.T(lang, "notifications.task.deleted.message", n.Doer.GetName(), n.Task.Title, n.Task.GetFullIdentifier())) } // ToDB returns the TaskDeletedNotification notification in a format which can be saved in the db @@ -163,14 +161,13 @@ func (n *TaskDeletedNotification) Name() string { type ProjectCreatedNotification struct { Doer *user.User `json:"doer"` Project *Project `json:"project"` - User *user.User `json:"-"` // Target user } // ToMail returns the mail notification for ProjectCreatedNotification -func (n *ProjectCreatedNotification) ToMail() *notifications.Mail { +func (n *ProjectCreatedNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.TWithParams(n.User.Language, "notifications.project.created.subject", n.Doer.GetName(), n.Project.Title)). - Line(i18n.TWithParams(n.User.Language, "notifications.project.created.message", n.Doer.GetName(), n.Project.Title)). + Subject(i18n.T(lang, "notifications.project.created.subject", n.Doer.GetName(), n.Project.Title)). + Line(i18n.T(lang, "notifications.project.created.message", n.Doer.GetName(), n.Project.Title)). Action("View Project", config.ServicePublicURL.GetString()+"projects/") } @@ -192,12 +189,12 @@ type TeamMemberAddedNotification struct { } // ToMail returns the mail notification for TeamMemberAddedNotification -func (n *TeamMemberAddedNotification) ToMail() *notifications.Mail { +func (n *TeamMemberAddedNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.TWithParams(n.Member.Language, "notifications.team.member_added.subject", n.Doer.GetName(), n.Team.Name)). + Subject(i18n.T(lang, "notifications.team.member_added.subject", n.Doer.GetName(), n.Team.Name)). From(n.Doer.GetNameAndFromEmail()). - Greeting(i18n.TWithParams(n.Member.Language, "notifications.greeting", n.Member.GetName())). - Line(i18n.TWithParams(n.Member.Language, "notifications.team.member_added.message", n.Doer.GetName(), n.Team.Name)). + Greeting(i18n.T(lang, "notifications.greeting", n.Member.GetName())). + Line(i18n.T(lang, "notifications.team.member_added.message", n.Doer.GetName(), n.Team.Name)). Action("View Team", config.ServicePublicURL.GetString()+"teams/"+strconv.FormatInt(n.Team.ID, 10)+"/edit") } @@ -212,7 +209,7 @@ func (n *TeamMemberAddedNotification) Name() string { } func getOverdueSinceString(until time.Duration, language string) (overdueSince string) { - overdueSince = i18n.TWithParams(language, "notifications.task.overdue.overdue_since", utils.HumanizeDuration(until)) + overdueSince = i18n.T(language, "notifications.task.overdue.overdue_since", utils.HumanizeDuration(until)) if until == 0 { overdueSince = i18n.T(language, "notifications.task.overdue.overdue_now") } @@ -228,15 +225,15 @@ type UndoneTaskOverdueNotification struct { } // ToMail returns the mail notification for UndoneTaskOverdueNotification -func (n *UndoneTaskOverdueNotification) ToMail() *notifications.Mail { +func (n *UndoneTaskOverdueNotification) ToMail(lang string) *notifications.Mail { until := time.Until(n.Task.DueDate).Round(1*time.Hour) * -1 return notifications.NewMail(). IncludeLinkToSettings(). - Subject(i18n.TWithParams(n.User.Language, "notifications.task.overdue.subject", n.Task.Title, n.Project.Title)). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.TWithParams(n.User.Language, "notifications.task.overdue.message", n.Task.Title, n.Project.Title, getOverdueSinceString(until, n.User.Language))). + Subject(i18n.T(lang, "notifications.task.overdue.subject", n.Task.Title, n.Project.Title)). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.task.overdue.message", n.Task.Title, n.Project.Title, getOverdueSinceString(until, n.User.Language))). Action("Open Task", config.ServicePublicURL.GetString()+"tasks/"+strconv.FormatInt(n.Task.ID, 10)). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the UndoneTaskOverdueNotification notification in a format which can be saved in the db @@ -257,7 +254,7 @@ type UndoneTasksOverdueNotification struct { } // ToMail returns the mail notification for UndoneTasksOverdueNotification -func (n *UndoneTasksOverdueNotification) ToMail() *notifications.Mail { +func (n *UndoneTasksOverdueNotification) ToMail(lang string) *notifications.Mail { sortedTasks := make([]*Task, 0, len(n.Tasks)) for _, task := range n.Tasks { @@ -276,12 +273,12 @@ func (n *UndoneTasksOverdueNotification) ToMail() *notifications.Mail { return notifications.NewMail(). IncludeLinkToSettings(). - Subject(i18n.T(n.User.Language, "notifications.task.overdue.multiple_subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.task.overdue.multiple_message")). + Subject(i18n.T(lang, "notifications.task.overdue.multiple_subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.task.overdue.multiple_message")). Line(overdueLine). Action("Open Vikunja", config.ServicePublicURL.GetString()). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the UndoneTasksOverdueNotification notification in a format which can be saved in the db @@ -299,7 +296,6 @@ type UserMentionedInTaskNotification struct { Doer *user.User `json:"doer"` Task *Task `json:"task"` IsNew bool `json:"is_new"` - User *user.User `json:"-"` // Target user } func (n *UserMentionedInTaskNotification) SubjectID() int64 { @@ -307,18 +303,18 @@ func (n *UserMentionedInTaskNotification) SubjectID() int64 { } // ToMail returns the mail notification for UserMentionedInTaskNotification -func (n *UserMentionedInTaskNotification) ToMail() *notifications.Mail { +func (n *UserMentionedInTaskNotification) ToMail(lang string) *notifications.Mail { var subject string if n.IsNew { - subject = i18n.TWithParams(n.User.Language, "notifications.task.mentioned.subject_new", n.Doer.GetName(), n.Task.Title) + subject = i18n.T(lang, "notifications.task.mentioned.subject_new", n.Doer.GetName(), n.Task.Title) } else { - subject = i18n.TWithParams(n.User.Language, "notifications.task.mentioned.subject", n.Doer.GetName(), n.Task.Title) + subject = i18n.T(lang, "notifications.task.mentioned.subject", n.Doer.GetName(), n.Task.Title) } mail := notifications.NewMail(). From(n.Doer.GetNameAndFromEmail()). Subject(subject). - Line(i18n.TWithParams(n.User.Language, "notifications.task.mentioned.message", n.Doer.GetName())). + Line(i18n.T(lang, "notifications.task.mentioned.message", n.Doer.GetName())). HTML(n.Task.Description) return mail. @@ -341,14 +337,14 @@ type DataExportReadyNotification struct { } // ToMail returns the mail notification for DataExportReadyNotification -func (n *DataExportReadyNotification) ToMail() *notifications.Mail { +func (n *DataExportReadyNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.data_export.ready.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.data_export.ready.message")). + Subject(i18n.T(lang, "notifications.data_export.ready.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.data_export.ready.message")). Action("Download", config.ServicePublicURL.GetString()+"user/export/download"). - Line(i18n.T(n.User.Language, "notifications.data_export.ready.availability")). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.data_export.ready.availability")). + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the DataExportReadyNotification notification in a format which can be saved in the db diff --git a/pkg/modules/migration/handler/notifications.go b/pkg/modules/migration/handler/notifications.go index 327d3774c..bc399d834 100644 --- a/pkg/modules/migration/handler/notifications.go +++ b/pkg/modules/migration/handler/notifications.go @@ -30,7 +30,7 @@ type MigrationDoneNotification struct { } // ToMail returns the mail notification for MigrationDoneNotification -func (n *MigrationDoneNotification) ToMail() *notifications.Mail { +func (n *MigrationDoneNotification) ToMail(lang string) *notifications.Mail { kind := cases.Title(language.English).String(n.MigratorName) return notifications.NewMail(). @@ -56,7 +56,7 @@ type MigrationFailedReportedNotification struct { } // ToMail returns the mail notification for MigrationFailedReportedNotification -func (n *MigrationFailedReportedNotification) ToMail() *notifications.Mail { +func (n *MigrationFailedReportedNotification) ToMail(lang string) *notifications.Mail { kind := cases.Title(language.English).String(n.MigratorName) return notifications.NewMail(). @@ -83,7 +83,7 @@ type MigrationFailedNotification struct { } // ToMail returns the mail notification for MigrationFailedNotification -func (n *MigrationFailedNotification) ToMail() *notifications.Mail { +func (n *MigrationFailedNotification) ToMail(lang string) *notifications.Mail { kind := cases.Title(language.English).String(n.MigratorName) return notifications.NewMail(). diff --git a/pkg/notifications/main_test.go b/pkg/notifications/main_test.go index 323608a5c..2ab5d015f 100644 --- a/pkg/notifications/main_test.go +++ b/pkg/notifications/main_test.go @@ -17,12 +17,12 @@ package notifications import ( - "code.vikunja.io/api/pkg/i18n" "os" "testing" "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/db" + "code.vikunja.io/api/pkg/i18n" "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/mail" ) diff --git a/pkg/notifications/notification.go b/pkg/notifications/notification.go index 4b91ea565..b77bfd4f0 100644 --- a/pkg/notifications/notification.go +++ b/pkg/notifications/notification.go @@ -25,7 +25,7 @@ import ( // Notification is a notification which can be sent via mail or db. type Notification interface { - ToMail() *Mail + ToMail(lang string) *Mail ToDB() interface{} Name() string } @@ -74,7 +74,7 @@ func Notify(notifiable Notifiable, notification Notification) (err error) { } func notifyMail(notifiable Notifiable, notification Notification) error { - mail := notification.ToMail() + mail := notification.ToMail(notifiable.Lang()) if mail == nil { return nil } diff --git a/pkg/notifications/notification_test.go b/pkg/notifications/notification_test.go index aff7670c6..6ac8b8722 100644 --- a/pkg/notifications/notification_test.go +++ b/pkg/notifications/notification_test.go @@ -31,7 +31,7 @@ type testNotification struct { } // ToMail returns the mail notification for testNotification -func (n *testNotification) ToMail() *Mail { +func (n *testNotification) ToMail(_ string) *Mail { return NewMail(). Subject("Test Notification"). Line(n.Test) diff --git a/pkg/user/notifications.go b/pkg/user/notifications.go index 48f9dea86..82db479e2 100644 --- a/pkg/user/notifications.go +++ b/pkg/user/notifications.go @@ -32,25 +32,25 @@ type EmailConfirmNotification struct { } // ToMail returns the mail notification for EmailConfirmNotification -func (n *EmailConfirmNotification) ToMail() *notifications.Mail { +func (n *EmailConfirmNotification) ToMail(lang string) *notifications.Mail { - subject := i18n.TWithParams(n.User.Language, "notifications.email_confirm.subject", n.User.GetName()) + subject := i18n.T(lang, "notifications.email_confirm.subject", n.User.GetName()) if n.IsNew { - subject = i18n.TWithParams(n.User.Language, "notifications.email_confirm.subject_new", n.User.GetName()) + subject = i18n.T(lang, "notifications.email_confirm.subject_new", n.User.GetName()) } nn := notifications.NewMail(). Subject(subject). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())) + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())) if n.IsNew { - nn.Line(i18n.T(n.User.Language, "notifications.email_confirm.welcome")) + nn.Line(i18n.T(lang, "notifications.email_confirm.welcome")) } return nn. - Line(i18n.T(n.User.Language, "notifications.email_confirm.confirm")). + Line(i18n.T(lang, "notifications.email_confirm.confirm")). Action("Confirm your email address", config.ServicePublicURL.GetString()+"?userEmailConfirm="+n.ConfirmToken). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the EmailConfirmNotification notification in a format which can be saved in the db @@ -69,12 +69,12 @@ type PasswordChangedNotification struct { } // ToMail returns the mail notification for PasswordChangedNotification -func (n *PasswordChangedNotification) ToMail() *notifications.Mail { +func (n *PasswordChangedNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.password.changed.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.password.changed.success")). - Line(i18n.T(n.User.Language, "notifications.password.changed.warning")) + Subject(i18n.T(lang, "notifications.password.changed.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.password.changed.success")). + Line(i18n.T(lang, "notifications.password.changed.warning")) } // ToDB returns the PasswordChangedNotification notification in a format which can be saved in the db @@ -94,14 +94,14 @@ type ResetPasswordNotification struct { } // ToMail returns the mail notification for ResetPasswordNotification -func (n *ResetPasswordNotification) ToMail() *notifications.Mail { +func (n *ResetPasswordNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.password.reset.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.password.reset.instructions")). + Subject(i18n.T(lang, "notifications.password.reset.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.password.reset.instructions")). Action("Reset your password", config.ServicePublicURL.GetString()+"?userPasswordReset="+n.Token.Token). - Line(i18n.T(n.User.Language, "notifications.password.reset.valid_duration")). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.password.reset.valid_duration")). + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the ResetPasswordNotification notification in a format which can be saved in the db @@ -120,12 +120,12 @@ type InvalidTOTPNotification struct { } // ToMail returns the mail notification for InvalidTOTPNotification -func (n *InvalidTOTPNotification) ToMail() *notifications.Mail { +func (n *InvalidTOTPNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.totp.invalid.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.totp.invalid.message")). - Line(i18n.T(n.User.Language, "notifications.totp.invalid.warning")). + Subject(i18n.T(lang, "notifications.totp.invalid.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.totp.invalid.message")). + Line(i18n.T(lang, "notifications.totp.invalid.warning")). Action("Reset your password", config.ServicePublicURL.GetString()+"get-password-reset") } @@ -145,14 +145,14 @@ type PasswordAccountLockedAfterInvalidTOTOPNotification struct { } // ToMail returns the mail notification for PasswordAccountLockedAfterInvalidTOTOPNotification -func (n *PasswordAccountLockedAfterInvalidTOTOPNotification) ToMail() *notifications.Mail { +func (n *PasswordAccountLockedAfterInvalidTOTOPNotification) ToMail(lang string) *notifications.Mail { resetURL := config.ServicePublicURL.GetString() + "get-password-reset" return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.totp.account_locked.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.totp.account_locked.message")). - Line(i18n.T(n.User.Language, "notifications.totp.account_locked.disabled")). - Line(i18n.TWithParams(n.User.Language, "notifications.totp.account_locked.reset_instructions", resetURL, resetURL)) + Subject(i18n.T(lang, "notifications.totp.account_locked.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.totp.account_locked.message")). + Line(i18n.T(lang, "notifications.totp.account_locked.disabled")). + Line(i18n.T(lang, "notifications.totp.account_locked.reset_instructions", resetURL, resetURL)) } // ToDB returns the PasswordAccountLockedAfterInvalidTOTOPNotification notification in a format which can be saved in the db @@ -171,13 +171,13 @@ type FailedLoginAttemptNotification struct { } // ToMail returns the mail notification for FailedLoginAttemptNotification -func (n *FailedLoginAttemptNotification) ToMail() *notifications.Mail { +func (n *FailedLoginAttemptNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.login.failed.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.login.failed.message")). - Line(i18n.T(n.User.Language, "notifications.login.failed.warning")). - Line(i18n.T(n.User.Language, "notifications.login.failed.enhance_security")). + Subject(i18n.T(lang, "notifications.login.failed.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.login.failed.message")). + Line(i18n.T(lang, "notifications.login.failed.warning")). + Line(i18n.T(lang, "notifications.login.failed.enhance_security")). Action("Go to settings", config.ServicePublicURL.GetString()+"user/settings") } @@ -198,17 +198,17 @@ type AccountDeletionConfirmNotification struct { } // ToMail returns the mail notification for AccountDeletionConfirmNotification -func (n *AccountDeletionConfirmNotification) ToMail() *notifications.Mail { +func (n *AccountDeletionConfirmNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.account.deletion.confirm.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.account.deletion.confirm.request")). + Subject(i18n.T(lang, "notifications.account.deletion.confirm.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.account.deletion.confirm.request")). Action("Confirm the deletion of my account", config.ServicePublicURL.GetString()+"?accountDeletionConfirm="+n.ConfirmToken). - Line(i18n.T(n.User.Language, "notifications.account.deletion.confirm.valid_duration")). - Line(i18n.T(n.User.Language, "notifications.account.deletion.confirm.schedule_info")). - Line(i18n.T(n.User.Language, "notifications.account.deletion.confirm.consequences")). - Line(i18n.T(n.User.Language, "notifications.account.deletion.confirm.changed_mind")). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.account.deletion.confirm.valid_duration")). + Line(i18n.T(lang, "notifications.account.deletion.confirm.schedule_info")). + Line(i18n.T(lang, "notifications.account.deletion.confirm.consequences")). + Line(i18n.T(lang, "notifications.account.deletion.confirm.changed_mind")). + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the AccountDeletionConfirmNotification notification in a format which can be saved in the db @@ -228,27 +228,27 @@ type AccountDeletionNotification struct { } // ToMail returns the mail notification for AccountDeletionNotification -func (n *AccountDeletionNotification) ToMail() *notifications.Mail { +func (n *AccountDeletionNotification) ToMail(lang string) *notifications.Mail { var subject string var deletionTimeLine string if n.NotificationNumber == 1 { - subject = i18n.T(n.User.Language, "notifications.account.deletion.scheduled.subject_tomorrow") - deletionTimeLine = i18n.T(n.User.Language, "notifications.account.deletion.scheduled.deletion_time_tomorrow") + subject = i18n.T(lang, "notifications.account.deletion.scheduled.subject_tomorrow") + deletionTimeLine = i18n.T(lang, "notifications.account.deletion.scheduled.deletion_time_tomorrow") } else { days := strconv.Itoa(n.NotificationNumber) - subject = i18n.TWithParams(n.User.Language, "notifications.account.deletion.scheduled.subject_days", days) - deletionTimeLine = i18n.TWithParams(n.User.Language, "notifications.account.deletion.scheduled.deletion_time_days", days) + subject = i18n.T(lang, "notifications.account.deletion.scheduled.subject_days", days) + deletionTimeLine = i18n.T(lang, "notifications.account.deletion.scheduled.deletion_time_days", days) } return notifications.NewMail(). Subject(subject). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.account.deletion.scheduled.request_reminder")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.account.deletion.scheduled.request_reminder")). Line(deletionTimeLine). - Line(i18n.T(n.User.Language, "notifications.account.deletion.scheduled.changed_mind")). + Line(i18n.T(lang, "notifications.account.deletion.scheduled.changed_mind")). Action("Abort the deletion", config.ServicePublicURL.GetString()). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the AccountDeletionNotification notification in a format which can be saved in the db @@ -267,13 +267,13 @@ type AccountDeletedNotification struct { } // ToMail returns the mail notification for AccountDeletedNotification -func (n *AccountDeletedNotification) ToMail() *notifications.Mail { +func (n *AccountDeletedNotification) ToMail(lang string) *notifications.Mail { return notifications.NewMail(). - Subject(i18n.T(n.User.Language, "notifications.account.deletion.completed.subject")). - Greeting(i18n.TWithParams(n.User.Language, "notifications.greeting", n.User.GetName())). - Line(i18n.T(n.User.Language, "notifications.account.deletion.completed.confirmation")). - Line(i18n.T(n.User.Language, "notifications.account.deletion.completed.permanent")). - Line(i18n.T(n.User.Language, "notifications.common.have_nice_day")) + Subject(i18n.T(lang, "notifications.account.deletion.completed.subject")). + Greeting(i18n.T(lang, "notifications.greeting", n.User.GetName())). + Line(i18n.T(lang, "notifications.account.deletion.completed.confirmation")). + Line(i18n.T(lang, "notifications.account.deletion.completed.permanent")). + Line(i18n.T(lang, "notifications.common.have_nice_day")) } // ToDB returns the AccountDeletedNotification notification in a format which can be saved in the db