Extracting i18n functionality to i18n core library (#16914)

* extracting i18n functionality to i18n core library

* Removing utils.T

* Adding documentation and changing one function name for better explanation

* Changing other missing utils.T

* Adding license string

* Renaming corelibs to pkg

* Renaming corelibs to pkg (moving directory)

* Renaming from pkg to shared

* Fixing bodyPage.Html casing

* Fixing merges

* Fixing merge problem

* Fixing tests
Этот коммит содержится в:
Jesús Espino
2021-02-26 08:12:49 +01:00
коммит произвёл GitHub
родитель 85293fcf41
Коммит 5dd2e75c10
90 изменённых файлов: 596 добавлений и 568 удалений

Просмотреть файл

@@ -18,7 +18,7 @@ import (
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/mailservice" "github.com/mattermost/mattermost-server/v5/services/mailservice"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils/testutils" "github.com/mattermost/mattermost-server/v5/utils/testutils"
) )
@@ -2794,7 +2794,7 @@ func TestInviteUsersToTeam(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
require.True(t, okMsg, "should return true") require.True(t, okMsg, "should return true")
nameFormat := *th.App.Config().TeamSettings.TeammateNameDisplay nameFormat := *th.App.Config().TeamSettings.TeammateNameDisplay
expectedSubject := utils.T("api.templates.invite_subject", expectedSubject := i18n.T("api.templates.invite_subject",
map[string]interface{}{"SenderName": th.SystemAdminUser.GetDisplayName(nameFormat), map[string]interface{}{"SenderName": th.SystemAdminUser.GetDisplayName(nameFormat),
"TeamDisplayName": th.BasicTeam.DisplayName, "TeamDisplayName": th.BasicTeam.DisplayName,
"SiteName": th.App.ClientConfig()["SiteName"]}) "SiteName": th.App.ClientConfig()["SiteName"]})
@@ -2805,7 +2805,7 @@ func TestInviteUsersToTeam(t *testing.T) {
okMsg, resp = th.LocalClient.InviteUsersToTeam(th.BasicTeam.Id, emailList) okMsg, resp = th.LocalClient.InviteUsersToTeam(th.BasicTeam.Id, emailList)
CheckNoError(t, resp) CheckNoError(t, resp)
require.True(t, okMsg, "should return true") require.True(t, okMsg, "should return true")
expectedSubject = utils.T("api.templates.invite_subject", expectedSubject = i18n.T("api.templates.invite_subject",
map[string]interface{}{"SenderName": "Administrator", map[string]interface{}{"SenderName": "Administrator",
"TeamDisplayName": th.BasicTeam.DisplayName, "TeamDisplayName": th.BasicTeam.DisplayName,
"SiteName": th.App.ClientConfig()["SiteName"]}) "SiteName": th.App.ClientConfig()["SiteName"]})
@@ -2925,7 +2925,7 @@ func TestInviteGuestsToTeam(t *testing.T) {
require.True(t, okMsg, "should return true") require.True(t, okMsg, "should return true")
nameFormat := *th.App.Config().TeamSettings.TeammateNameDisplay nameFormat := *th.App.Config().TeamSettings.TeammateNameDisplay
expectedSubject := utils.T("api.templates.invite_guest_subject", expectedSubject := i18n.T("api.templates.invite_guest_subject",
map[string]interface{}{"SenderName": th.SystemAdminUser.GetDisplayName(nameFormat), map[string]interface{}{"SenderName": th.SystemAdminUser.GetDisplayName(nameFormat),
"TeamDisplayName": th.BasicTeam.DisplayName, "TeamDisplayName": th.BasicTeam.DisplayName,
"SiteName": th.App.ClientConfig()["SiteName"]}) "SiteName": th.App.ClientConfig()["SiteName"]})

Просмотреть файл

@@ -16,6 +16,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/mailservice" "github.com/mattermost/mattermost-server/v5/services/mailservice"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -205,7 +206,7 @@ func (a *App) TestSiteURL(siteURL string) *model.AppError {
func (a *App) TestEmail(userID string, cfg *model.Config) *model.AppError { func (a *App) TestEmail(userID string, cfg *model.Config) *model.AppError {
if *cfg.EmailSettings.SMTPServer == "" { if *cfg.EmailSettings.SMTPServer == "" {
return model.NewAppError("testEmail", "api.admin.test_email.missing_server", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusBadRequest) return model.NewAppError("testEmail", "api.admin.test_email.missing_server", nil, i18n.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusBadRequest)
} }
// if the user hasn't changed their email settings, fill in the actual SMTP password so that // if the user hasn't changed their email settings, fill in the actual SMTP password so that
@@ -224,7 +225,7 @@ func (a *App) TestEmail(userID string, cfg *model.Config) *model.AppError {
return err return err
} }
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
license := a.Srv().License() license := a.Srv().License()
mailConfig := a.Srv().MailServiceConfig() mailConfig := a.Srv().MailServiceConfig()
if err := mailservice.SendMailUsingConfig(user.Email, T("api.admin.test_email.subject"), T("api.admin.test_email.body"), mailConfig, license != nil && *license.Features.Compliance, ""); err != nil { if err := mailservice.SendMailUsingConfig(user.Email, T("api.admin.test_email.subject"), T("api.admin.test_email.body"), mailConfig, license != nil && *license.Features.Compliance, ""); err != nil {

Просмотреть файл

@@ -12,9 +12,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/mattermost/go-i18n/i18n"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/einterfaces" "github.com/mattermost/mattermost-server/v5/einterfaces"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
@@ -23,6 +20,7 @@ import (
"github.com/mattermost/mattermost-server/v5/services/mailservice" "github.com/mattermost/mattermost-server/v5/services/mailservice"
"github.com/mattermost/mattermost-server/v5/services/searchengine" "github.com/mattermost/mattermost-server/v5/services/searchengine"
"github.com/mattermost/mattermost-server/v5/services/timezones" "github.com/mattermost/mattermost-server/v5/services/timezones"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -34,7 +32,7 @@ type App struct {
// a cyclic dependency as bleve tests themselves import testlib. // a cyclic dependency as bleve tests themselves import testlib.
searchEngine *searchengine.Broker searchEngine *searchengine.Broker
t goi18n.TranslateFunc t i18n.TranslateFunc
session model.Session session model.Session
requestId string requestId string
ipAddress string ipAddress string
@@ -366,7 +364,7 @@ func (a *App) notifyAdminsOfWarnMetricStatus(warnMetricId string, isE0Edition bo
} }
} }
T := utils.GetUserTranslations(sysAdmins[0].Locale) T := i18n.GetUserTranslations(sysAdmins[0].Locale)
warnMetricsBot := &model.Bot{ warnMetricsBot := &model.Bot{
Username: model.BOT_WARN_METRIC_BOT_USERNAME, Username: model.BOT_WARN_METRIC_BOT_USERNAME,
DisplayName: T("app.system.warn_metric.bot_displayname"), DisplayName: T("app.system.warn_metric.bot_displayname"),
@@ -380,7 +378,7 @@ func (a *App) notifyAdminsOfWarnMetricStatus(warnMetricId string, isE0Edition bo
} }
for _, sysAdmin := range sysAdmins { for _, sysAdmin := range sysAdmins {
T := utils.GetUserTranslations(sysAdmin.Locale) T := i18n.GetUserTranslations(sysAdmin.Locale)
bot.DisplayName = T("app.system.warn_metric.bot_displayname") bot.DisplayName = T("app.system.warn_metric.bot_displayname")
bot.Description = T("app.system.warn_metric.bot_description") bot.Description = T("app.system.warn_metric.bot_description")
@@ -466,9 +464,9 @@ func (a *App) NotifyAndSetWarnMetricAck(warnMetricId string, sender *model.User,
if !forceAck { if !forceAck {
if *a.Config().EmailSettings.SMTPServer == "" { if *a.Config().EmailSettings.SMTPServer == "" {
return model.NewAppError("NotifyAndSetWarnMetricAck", "api.email.send_warn_metric_ack.missing_server.app_error", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusInternalServerError) return model.NewAppError("NotifyAndSetWarnMetricAck", "api.email.send_warn_metric_ack.missing_server.app_error", nil, i18n.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusInternalServerError)
} }
T := utils.GetUserTranslations(sender.Locale) T := i18n.GetUserTranslations(sender.Locale)
bodyPage := a.Srv().EmailService.newEmailTemplate("warn_metric_ack", sender.Locale) bodyPage := a.Srv().EmailService.newEmailTemplate("warn_metric_ack", sender.Locale)
bodyPage.Props["ContactNameHeader"] = T("api.templates.warn_metric_ack.body.contact_name_header") bodyPage.Props["ContactNameHeader"] = T("api.templates.warn_metric_ack.body.contact_name_header")
bodyPage.Props["ContactNameValue"] = sender.GetFullName() bodyPage.Props["ContactNameValue"] = sender.GetFullName()
@@ -671,7 +669,7 @@ func (a *App) SetSession(s *model.Session) {
a.session = *s a.session = *s
} }
func (a *App) SetT(t goi18n.TranslateFunc) { func (a *App) SetT(t i18n.TranslateFunc) {
a.t = t a.t = t
} }
func (a *App) SetRequestId(s string) { func (a *App) SetRequestId(s string) {
@@ -695,7 +693,7 @@ func (a *App) SetContext(c context.Context) {
func (a *App) SetServer(srv *Server) { func (a *App) SetServer(srv *Server) {
a.srv = srv a.srv = srv
} }
func (a *App) GetT() goi18n.TranslateFunc { func (a *App) GetT() i18n.TranslateFunc {
return a.t return a.t
} }

Просмотреть файл

@@ -18,8 +18,6 @@ import (
"time" "time"
"github.com/dyatlov/go-opengraph/opengraph" "github.com/dyatlov/go-opengraph/opengraph"
"github.com/mattermost/go-i18n/i18n"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/audit" "github.com/mattermost/mattermost-server/v5/audit"
"github.com/mattermost/mattermost-server/v5/einterfaces" "github.com/mattermost/mattermost-server/v5/einterfaces"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
@@ -30,6 +28,7 @@ import (
"github.com/mattermost/mattermost-server/v5/services/imageproxy" "github.com/mattermost/mattermost-server/v5/services/imageproxy"
"github.com/mattermost/mattermost-server/v5/services/searchengine" "github.com/mattermost/mattermost-server/v5/services/searchengine"
"github.com/mattermost/mattermost-server/v5/services/timezones" "github.com/mattermost/mattermost-server/v5/services/timezones"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
) )
@@ -39,7 +38,7 @@ type AppIface interface {
ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
// @openTracingParams teamID // @openTracingParams teamID
// previous ListCommands now ListAutocompleteCommands // previous ListCommands now ListAutocompleteCommands
ListAutocompleteCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) ListAutocompleteCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError)
// @openTracingParams teamID, skipSlackParsing // @openTracingParams teamID, skipSlackParsing
CreateCommandPost(post *model.Post, teamID string, response *model.CommandResponse, skipSlackParsing bool) (*model.Post, *model.AppError) CreateCommandPost(post *model.Post, teamID string, response *model.CommandResponse, skipSlackParsing bool) (*model.Post, *model.AppError)
// AddCursorIdsForPostList adds NextPostId and PrevPostId as cursor to the PostList. // AddCursorIdsForPostList adds NextPostId and PrevPostId as cursor to the PostList.
@@ -231,7 +230,7 @@ type AppIface interface {
// function is only exposed to sysadmins and the possibility of this edge case is relatively small. // function is only exposed to sysadmins and the possibility of this edge case is relatively small.
MoveChannel(team *model.Team, channel *model.Channel, user *model.User) *model.AppError MoveChannel(team *model.Team, channel *model.Channel, user *model.User) *model.AppError
// NewWebConn returns a new WebConn instance. // NewWebConn returns a new WebConn instance.
NewWebConn(ws net.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn NewWebConn(ws net.Conn, session model.Session, t i18n.TranslateFunc, locale string) *WebConn
// NewWebHub creates a new Hub. // NewWebHub creates a new Hub.
NewWebHub() *Hub NewWebHub() *Hub
// NotifySessionsExpired is called periodically from the job server to notify any mobile sessions that have expired. // NotifySessionsExpired is called periodically from the job server to notify any mobile sessions that have expired.
@@ -683,7 +682,7 @@ type AppIface interface {
GetStatus(userID string) (*model.Status, *model.AppError) GetStatus(userID string) (*model.Status, *model.AppError)
GetStatusFromCache(userID string) *model.Status GetStatusFromCache(userID string) *model.Status
GetStatusesByIds(userIDs []string) (map[string]interface{}, *model.AppError) GetStatusesByIds(userIDs []string) (map[string]interface{}, *model.AppError)
GetT() goi18n.TranslateFunc GetT() i18n.TranslateFunc
GetTeam(teamID string) (*model.Team, *model.AppError) GetTeam(teamID string) (*model.Team, *model.AppError)
GetTeamByInviteId(inviteId string) (*model.Team, *model.AppError) GetTeamByInviteId(inviteId string) (*model.Team, *model.AppError)
GetTeamByName(name string) (*model.Team, *model.AppError) GetTeamByName(name string) (*model.Team, *model.AppError)
@@ -784,7 +783,7 @@ type AppIface interface {
LeaveChannel(channelID string, userID string) *model.AppError LeaveChannel(channelID string, userID string) *model.AppError
LeaveTeam(team *model.Team, user *model.User, requestorId string) *model.AppError LeaveTeam(team *model.Team, user *model.User, requestorId string) *model.AppError
LimitedClientConfig() map[string]string LimitedClientConfig() map[string]string
ListAllCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) ListAllCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError)
ListDirectory(path string) ([]string, *model.AppError) ListDirectory(path string) ([]string, *model.AppError)
ListExports() ([]string, *model.AppError) ListExports() ([]string, *model.AppError)
ListImports() ([]string, *model.AppError) ListImports() ([]string, *model.AppError)
@@ -954,7 +953,7 @@ type AppIface interface {
SetStatusOffline(userID string, manual bool) SetStatusOffline(userID string, manual bool)
SetStatusOnline(userID string, manual bool) SetStatusOnline(userID string, manual bool)
SetStatusOutOfOffice(userID string) SetStatusOutOfOffice(userID string)
SetT(t goi18n.TranslateFunc) SetT(t i18n.TranslateFunc)
SetTeamIcon(teamID string, imageData *multipart.FileHeader) *model.AppError SetTeamIcon(teamID string, imageData *multipart.FileHeader) *model.AppError
SetTeamIconFromFile(team *model.Team, file io.Reader) *model.AppError SetTeamIconFromFile(team *model.Team, file io.Reader) *model.AppError
SetTeamIconFromMultiPartFile(teamID string, file multipart.File) *model.AppError SetTeamIconFromMultiPartFile(teamID string, file multipart.File) *model.AppError

Просмотреть файл

@@ -13,8 +13,8 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
) )
// CreateBot creates the given bot and corresponding user. // CreateBot creates the given bot and corresponding user.
@@ -72,7 +72,7 @@ func (a *App) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
return nil, err return nil, err
} }
T := utils.GetUserTranslations(ownerUser.Locale) T := i18n.GetUserTranslations(ownerUser.Locale)
botAddPost := &model.Post{ botAddPost := &model.Post{
Type: model.POST_ADD_BOT_TEAMS_CHANNELS, Type: model.POST_ADD_BOT_TEAMS_CHANNELS,
UserId: savedBot.UserId, UserId: savedBot.UserId,
@@ -471,7 +471,7 @@ func (a *App) getDisableBotSysadminMessage(user *model.User, userBots model.BotL
botList += fmt.Sprintf("* %v\n", bot.Username) botList += fmt.Sprintf("* %v\n", bot.Username)
} }
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
message = T("app.bot.get_disable_bot_sysadmin_message", message = T("app.bot.get_disable_bot_sysadmin_message",
map[string]interface{}{ map[string]interface{}{
"UserName": user.Username, "UserName": user.Username,

Просмотреть файл

@@ -14,6 +14,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin" "github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -22,13 +23,13 @@ import (
// //
func (a *App) CreateDefaultChannels(teamID string) ([]*model.Channel, *model.AppError) { func (a *App) CreateDefaultChannels(teamID string) ([]*model.Channel, *model.AppError) {
displayNames := map[string]string{ displayNames := map[string]string{
"town-square": utils.T("api.channel.create_default_channels.town_square"), "town-square": i18n.T("api.channel.create_default_channels.town_square"),
"off-topic": utils.T("api.channel.create_default_channels.off_topic"), "off-topic": i18n.T("api.channel.create_default_channels.off_topic"),
} }
channels := []*model.Channel{} channels := []*model.Channel{}
defaultChannelNames := a.DefaultChannelNames() defaultChannelNames := a.DefaultChannelNames()
for _, name := range defaultChannelNames { for _, name := range defaultChannelNames {
displayName := utils.TDefault(displayNames[name], name) displayName := i18n.TDefault(displayNames[name], name)
channel := &model.Channel{DisplayName: displayName, Name: name, Type: model.CHANNEL_OPEN, TeamId: teamID} channel := &model.Channel{DisplayName: displayName, Name: name, Type: model.CHANNEL_OPEN, TeamId: teamID}
if _, err := a.CreateChannel(channel, false); err != nil { if _, err := a.CreateChannel(channel, false); err != nil {
return nil, err return nil, err
@@ -711,8 +712,8 @@ func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User)
func (a *App) postChannelPrivacyMessage(user *model.User, channel *model.Channel) *model.AppError { func (a *App) postChannelPrivacyMessage(user *model.User, channel *model.Channel) *model.AppError {
message := (map[string]string{ message := (map[string]string{
model.CHANNEL_OPEN: utils.T("api.channel.change_channel_privacy.private_to_public"), model.CHANNEL_OPEN: i18n.T("api.channel.change_channel_privacy.private_to_public"),
model.CHANNEL_PRIVATE: utils.T("api.channel.change_channel_privacy.public_to_private"), model.CHANNEL_PRIVATE: i18n.T("api.channel.change_channel_privacy.public_to_private"),
})[channel.Type] })[channel.Type]
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
@@ -758,7 +759,7 @@ func (a *App) RestoreChannel(channel *model.Channel, userID string) (*model.Chan
} }
if user != nil { if user != nil {
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
@@ -1273,7 +1274,7 @@ func (a *App) DeleteChannel(channel *model.Channel, userID string) *model.AppErr
} }
if user != nil { if user != nil {
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
@@ -1500,11 +1501,11 @@ func (a *App) PostUpdateChannelHeaderMessage(userID string, channel *model.Chann
var message string var message string
if oldChannelHeader == "" { if oldChannelHeader == "" {
message = fmt.Sprintf(utils.T("api.channel.post_update_channel_header_message_and_forget.updated_to"), user.Username, newChannelHeader) message = fmt.Sprintf(i18n.T("api.channel.post_update_channel_header_message_and_forget.updated_to"), user.Username, newChannelHeader)
} else if newChannelHeader == "" { } else if newChannelHeader == "" {
message = fmt.Sprintf(utils.T("api.channel.post_update_channel_header_message_and_forget.removed"), user.Username, oldChannelHeader) message = fmt.Sprintf(i18n.T("api.channel.post_update_channel_header_message_and_forget.removed"), user.Username, oldChannelHeader)
} else { } else {
message = fmt.Sprintf(utils.T("api.channel.post_update_channel_header_message_and_forget.updated_from"), user.Username, oldChannelHeader, newChannelHeader) message = fmt.Sprintf(i18n.T("api.channel.post_update_channel_header_message_and_forget.updated_from"), user.Username, oldChannelHeader, newChannelHeader)
} }
post := &model.Post{ post := &model.Post{
@@ -1534,11 +1535,11 @@ func (a *App) PostUpdateChannelPurposeMessage(userID string, channel *model.Chan
var message string var message string
if oldChannelPurpose == "" { if oldChannelPurpose == "" {
message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.updated_to"), user.Username, newChannelPurpose) message = fmt.Sprintf(i18n.T("app.channel.post_update_channel_purpose_message.updated_to"), user.Username, newChannelPurpose)
} else if newChannelPurpose == "" { } else if newChannelPurpose == "" {
message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.removed"), user.Username, oldChannelPurpose) message = fmt.Sprintf(i18n.T("app.channel.post_update_channel_purpose_message.removed"), user.Username, oldChannelPurpose)
} else { } else {
message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.updated_from"), user.Username, oldChannelPurpose, newChannelPurpose) message = fmt.Sprintf(i18n.T("app.channel.post_update_channel_purpose_message.updated_from"), user.Username, oldChannelPurpose, newChannelPurpose)
} }
post := &model.Post{ post := &model.Post{
@@ -1565,7 +1566,7 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userID string, channel *model.
return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest) return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest)
} }
message := fmt.Sprintf(utils.T("api.channel.post_update_channel_displayname_message_and_forget.updated_from"), user.Username, oldChannelDisplayName, newChannelDisplayName) message := fmt.Sprintf(i18n.T("api.channel.post_update_channel_displayname_message_and_forget.updated_from"), user.Username, oldChannelDisplayName, newChannelDisplayName)
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
@@ -1962,11 +1963,11 @@ func (a *App) JoinChannel(channel *model.Channel, userID string) *model.AppError
} }
func (a *App) postJoinChannelMessage(user *model.User, channel *model.Channel) *model.AppError { func (a *App) postJoinChannelMessage(user *model.User, channel *model.Channel) *model.AppError {
message := fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username) message := fmt.Sprintf(i18n.T("api.channel.join_channel.post_and_forget"), user.Username)
postType := model.POST_JOIN_CHANNEL postType := model.POST_JOIN_CHANNEL
if user.IsGuest() { if user.IsGuest() {
message = fmt.Sprintf(utils.T("api.channel.guest_join_channel.post_and_forget"), user.Username) message = fmt.Sprintf(i18n.T("api.channel.guest_join_channel.post_and_forget"), user.Username)
postType = model.POST_GUEST_JOIN_CHANNEL postType = model.POST_GUEST_JOIN_CHANNEL
} }
@@ -1990,7 +1991,7 @@ func (a *App) postJoinChannelMessage(user *model.User, channel *model.Channel) *
func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *model.AppError { func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *model.AppError {
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
Message: fmt.Sprintf(utils.T("api.team.join_team.post_and_forget"), user.Username), Message: fmt.Sprintf(i18n.T("api.team.join_team.post_and_forget"), user.Username),
Type: model.POST_JOIN_TEAM, Type: model.POST_JOIN_TEAM,
UserId: user.Id, UserId: user.Id,
Props: model.StringInterface{ Props: model.StringInterface{
@@ -2087,7 +2088,7 @@ func (a *App) postLeaveChannelMessage(user *model.User, channel *model.Channel)
// Message here embeds `@username`, not just `username`, to ensure that mentions // Message here embeds `@username`, not just `username`, to ensure that mentions
// treat this as a username mention even though the user has now left the channel. // treat this as a username mention even though the user has now left the channel.
// The client renders its own system message, ignoring this value altogether. // The client renders its own system message, ignoring this value altogether.
Message: fmt.Sprintf(utils.T("api.channel.leave.left"), fmt.Sprintf("@%s", user.Username)), Message: fmt.Sprintf(i18n.T("api.channel.leave.left"), fmt.Sprintf("@%s", user.Username)),
Type: model.POST_LEAVE_CHANNEL, Type: model.POST_LEAVE_CHANNEL,
UserId: user.Id, UserId: user.Id,
Props: model.StringInterface{ Props: model.StringInterface{
@@ -2103,11 +2104,11 @@ func (a *App) postLeaveChannelMessage(user *model.User, channel *model.Channel)
} }
func (a *App) PostAddToChannelMessage(user *model.User, addedUser *model.User, channel *model.Channel, postRootId string) *model.AppError { func (a *App) PostAddToChannelMessage(user *model.User, addedUser *model.User, channel *model.Channel, postRootId string) *model.AppError {
message := fmt.Sprintf(utils.T("api.channel.add_member.added"), addedUser.Username, user.Username) message := fmt.Sprintf(i18n.T("api.channel.add_member.added"), addedUser.Username, user.Username)
postType := model.POST_ADD_TO_CHANNEL postType := model.POST_ADD_TO_CHANNEL
if addedUser.IsGuest() { if addedUser.IsGuest() {
message = fmt.Sprintf(utils.T("api.channel.add_guest.added"), addedUser.Username, user.Username) message = fmt.Sprintf(i18n.T("api.channel.add_guest.added"), addedUser.Username, user.Username)
postType = model.POST_ADD_GUEST_TO_CHANNEL postType = model.POST_ADD_GUEST_TO_CHANNEL
} }
@@ -2135,7 +2136,7 @@ func (a *App) PostAddToChannelMessage(user *model.User, addedUser *model.User, c
func (a *App) postAddToTeamMessage(user *model.User, addedUser *model.User, channel *model.Channel, postRootId string) *model.AppError { func (a *App) postAddToTeamMessage(user *model.User, addedUser *model.User, channel *model.Channel, postRootId string) *model.AppError {
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
Message: fmt.Sprintf(utils.T("api.team.add_user_to_team.added"), addedUser.Username, user.Username), Message: fmt.Sprintf(i18n.T("api.team.add_user_to_team.added"), addedUser.Username, user.Username),
Type: model.POST_ADD_TO_TEAM, Type: model.POST_ADD_TO_TEAM,
UserId: user.Id, UserId: user.Id,
RootId: postRootId, RootId: postRootId,
@@ -2160,7 +2161,7 @@ func (a *App) postRemoveFromChannelMessage(removerUserId string, removedUser *mo
// Message here embeds `@username`, not just `username`, to ensure that mentions // Message here embeds `@username`, not just `username`, to ensure that mentions
// treat this as a username mention even though the user has now left the channel. // treat this as a username mention even though the user has now left the channel.
// The client renders its own system message, ignoring this value altogether. // The client renders its own system message, ignoring this value altogether.
Message: fmt.Sprintf(utils.T("api.channel.remove_member.removed"), fmt.Sprintf("@%s", removedUser.Username)), Message: fmt.Sprintf(i18n.T("api.channel.remove_member.removed"), fmt.Sprintf("@%s", removedUser.Username)),
Type: model.POST_REMOVE_FROM_CHANNEL, Type: model.POST_REMOVE_FROM_CHANNEL,
UserId: removerUserId, UserId: removerUserId,
Props: model.StringInterface{ Props: model.StringInterface{
@@ -2753,7 +2754,7 @@ func (a *App) postChannelMoveMessage(user *model.User, channel *model.Channel, p
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
Message: fmt.Sprintf(utils.T("api.team.move_channel.success"), previousTeam.Name), Message: fmt.Sprintf(i18n.T("api.team.move_channel.success"), previousTeam.Name),
Type: model.POST_MOVE_CHANNEL, Type: model.POST_MOVE_CHANNEL,
UserId: user.Id, UserId: user.Id,
Props: model.StringInterface{ Props: model.StringInterface{

Просмотреть файл

@@ -14,12 +14,10 @@ import (
"sync" "sync"
"unicode" "unicode"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
) )
const ( const (
@@ -28,7 +26,7 @@ const (
type CommandProvider interface { type CommandProvider interface {
GetTrigger() string GetTrigger() string
GetCommand(a *App, T goi18n.TranslateFunc) *model.Command GetCommand(a *App, T i18n.TranslateFunc) *model.Command
DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse
} }
@@ -80,7 +78,7 @@ func (a *App) CreateCommandPost(post *model.Post, teamID string, response *model
// @openTracingParams teamID // @openTracingParams teamID
// previous ListCommands now ListAutocompleteCommands // previous ListCommands now ListAutocompleteCommands
func (a *App) ListAutocompleteCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) { func (a *App) ListAutocompleteCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError) {
commands := make([]*model.Command, 0, 32) commands := make([]*model.Command, 0, 32)
seen := make(map[string]bool) seen := make(map[string]bool)
@@ -138,7 +136,7 @@ func (a *App) ListTeamCommands(teamID string) ([]*model.Command, *model.AppError
return teamCmds, nil return teamCmds, nil
} }
func (a *App) ListAllCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) { func (a *App) ListAllCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError) {
commands := make([]*model.Command, 0, 32) commands := make([]*model.Command, 0, 32)
seen := make(map[string]bool) seen := make(map[string]bool)
for _, value := range commandProviders { for _, value := range commandProviders {
@@ -645,7 +643,7 @@ func (a *App) createCommand(cmd *model.Command) (*model.Command, *model.AppError
} }
for _, builtInProvider := range commandProviders { for _, builtInProvider := range commandProviders {
builtInCommand := builtInProvider.GetCommand(a, utils.T) builtInCommand := builtInProvider.GetCommand(a, i18n.T)
if builtInCommand != nil && cmd.Trigger == builtInCommand.Trigger { if builtInCommand != nil && cmd.Trigger == builtInCommand.Trigger {
return nil, model.NewAppError("CreateCommand", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest) return nil, model.NewAppError("CreateCommand", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
} }

Просмотреть файл

@@ -7,10 +7,10 @@ import (
"fmt" "fmt"
"testing" "testing"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func TestParseStaticListArgument(t *testing.T) { func TestParseStaticListArgument(t *testing.T) {
@@ -644,7 +644,7 @@ func (p *testProvider) GetTrigger() string {
return "bogus" return "bogus"
} }
func (p *testProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command { func (p *testProvider) GetCommand(a *App, T i18n.TranslateFunc) *model.Command {
top := model.NewAutocompleteData(p.GetTrigger(), "[command]", "Just a test.") top := model.NewAutocompleteData(p.GetTrigger(), "[command]", "Just a test.")
top.AddNamedDynamicListArgument("dynaArg", "A dynamic list", "builtin:bogus", true) top.AddNamedDynamicListArgument("dynaArg", "A dynamic list", "builtin:bogus", true)

Просмотреть файл

@@ -14,7 +14,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/mattermost/go-i18n/i18n"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/throttled/throttled" "github.com/throttled/throttled"
"github.com/throttled/throttled/store/memstore" "github.com/throttled/throttled/store/memstore"
@@ -22,6 +21,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/mailservice" "github.com/mattermost/mattermost-server/v5/services/mailservice"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -88,7 +88,7 @@ func (es *EmailService) setUpRateLimiters() error {
} }
func (es *EmailService) sendChangeUsernameEmail(newUsername, email, locale, siteURL string) *model.AppError { func (es *EmailService) sendChangeUsernameEmail(newUsername, email, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.username_change_subject", subject := T("api.templates.username_change_subject",
map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName, map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName,
@@ -109,7 +109,7 @@ func (es *EmailService) sendChangeUsernameEmail(newUsername, email, locale, site
} }
func (es *EmailService) sendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *model.AppError { func (es *EmailService) sendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(newUserEmail)) link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(newUserEmail))
@@ -133,7 +133,7 @@ func (es *EmailService) sendEmailChangeVerifyEmail(newUserEmail, locale, siteURL
} }
func (es *EmailService) sendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.AppError { func (es *EmailService) sendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.email_change_subject", subject := T("api.templates.email_change_subject",
map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName, map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName,
@@ -154,7 +154,7 @@ func (es *EmailService) sendEmailChangeEmail(oldEmail, newEmail, locale, siteURL
} }
func (es *EmailService) sendVerifyEmail(userEmail, locale, siteURL, token, redirect string) *model.AppError { func (es *EmailService) sendVerifyEmail(userEmail, locale, siteURL, token, redirect string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(userEmail)) link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(userEmail))
if redirect != "" { if redirect != "" {
@@ -187,7 +187,7 @@ func (es *EmailService) sendVerifyEmail(userEmail, locale, siteURL, token, redir
} }
func (es *EmailService) SendSignInChangeEmail(email, method, locale, siteURL string) *model.AppError { func (es *EmailService) SendSignInChangeEmail(email, method, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.signin_change_email.subject", subject := T("api.templates.signin_change_email.subject",
map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName}) map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName})
@@ -211,7 +211,7 @@ func (es *EmailService) sendWelcomeEmail(userID string, email string, verified b
return model.NewAppError("SendWelcomeEmail", "api.user.send_welcome_email_and_forget.failed.error", nil, "Send Email Notifications and Require Email Verification is disabled in the system console", http.StatusInternalServerError) return model.NewAppError("SendWelcomeEmail", "api.user.send_welcome_email_and_forget.failed.error", nil, "Send Email Notifications and Require Email Verification is disabled in the system console", http.StatusInternalServerError)
} }
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
serverURL := condenseSiteURL(siteURL) serverURL := condenseSiteURL(siteURL)
@@ -257,7 +257,7 @@ func (es *EmailService) sendWelcomeEmail(userID string, email string, verified b
} }
func (es *EmailService) sendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppError { func (es *EmailService) sendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.password_change_subject", subject := T("api.templates.password_change_subject",
map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName, map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName,
@@ -278,7 +278,7 @@ func (es *EmailService) sendPasswordChangeEmail(email, method, locale, siteURL s
} }
func (es *EmailService) sendUserAccessTokenAddedEmail(email, locale, siteURL string) *model.AppError { func (es *EmailService) sendUserAccessTokenAddedEmail(email, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.user_access_token_subject", subject := T("api.templates.user_access_token_subject",
map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName}) map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName})
@@ -298,7 +298,7 @@ func (es *EmailService) sendUserAccessTokenAddedEmail(email, locale, siteURL str
} }
func (es *EmailService) SendPasswordResetEmail(email string, token *model.Token, locale, siteURL string) (bool, *model.AppError) { func (es *EmailService) SendPasswordResetEmail(email string, token *model.Token, locale, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
link := fmt.Sprintf("%s/reset_password_complete?token=%s", siteURL, url.QueryEscape(token.Token)) link := fmt.Sprintf("%s/reset_password_complete?token=%s", siteURL, url.QueryEscape(token.Token))
@@ -308,7 +308,7 @@ func (es *EmailService) SendPasswordResetEmail(email string, token *model.Token,
bodyPage := es.newEmailTemplate("reset_body", locale) bodyPage := es.newEmailTemplate("reset_body", locale)
bodyPage.Props["SiteURL"] = siteURL bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = T("api.templates.reset_body.title") bodyPage.Props["Title"] = T("api.templates.reset_body.title")
bodyPage.Props["Info1"] = utils.TranslateAsHTML(T, "api.templates.reset_body.info1", nil) bodyPage.Props["Info1"] = i18n.TranslateAsHTML(T, "api.templates.reset_body.info1", nil)
bodyPage.Props["Info2"] = T("api.templates.reset_body.info2") bodyPage.Props["Info2"] = T("api.templates.reset_body.info2")
bodyPage.Props["ResetUrl"] = link bodyPage.Props["ResetUrl"] = link
bodyPage.Props["Button"] = T("api.templates.reset_body.button") bodyPage.Props["Button"] = T("api.templates.reset_body.button")
@@ -321,7 +321,7 @@ func (es *EmailService) SendPasswordResetEmail(email string, token *model.Token,
} }
func (es *EmailService) sendMfaChangeEmail(email string, activated bool, locale, siteURL string) *model.AppError { func (es *EmailService) sendMfaChangeEmail(email string, activated bool, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.mfa_change_subject", subject := T("api.templates.mfa_change_subject",
map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName}) map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName})
@@ -364,18 +364,18 @@ func (es *EmailService) SendInviteEmails(team *model.Team, senderName string, se
for _, invite := range invites { for _, invite := range invites {
if invite != "" { if invite != "" {
subject := utils.T("api.templates.invite_subject", subject := i18n.T("api.templates.invite_subject",
map[string]interface{}{"SenderName": senderName, map[string]interface{}{"SenderName": senderName,
"TeamDisplayName": team.DisplayName, "TeamDisplayName": team.DisplayName,
"SiteName": es.srv.Config().TeamSettings.SiteName}) "SiteName": es.srv.Config().TeamSettings.SiteName})
bodyPage := es.newEmailTemplate("invite_body", "") bodyPage := es.newEmailTemplate("invite_body", "")
bodyPage.Props["SiteURL"] = siteURL bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = utils.T("api.templates.invite_body.title") bodyPage.Props["Title"] = i18n.T("api.templates.invite_body.title")
bodyPage.HTML["Info"] = utils.TranslateAsHTML(utils.T, "api.templates.invite_body.info", bodyPage.HTML["Info"] = i18n.TranslateAsHTML(i18n.T, "api.templates.invite_body.info",
map[string]interface{}{"SenderName": senderName, "TeamDisplayName": team.DisplayName}) map[string]interface{}{"SenderName": senderName, "TeamDisplayName": team.DisplayName})
bodyPage.Props["Button"] = utils.T("api.templates.invite_body.button") bodyPage.Props["Button"] = i18n.T("api.templates.invite_body.button")
bodyPage.HTML["ExtraInfo"] = utils.TranslateAsHTML(utils.T, "api.templates.invite_body.extra_info", bodyPage.HTML["ExtraInfo"] = i18n.TranslateAsHTML(i18n.T, "api.templates.invite_body.extra_info",
map[string]interface{}{"TeamDisplayName": team.DisplayName}) map[string]interface{}{"TeamDisplayName": team.DisplayName})
bodyPage.Props["TeamURL"] = siteURL + "/" + team.Name bodyPage.Props["TeamURL"] = siteURL + "/" + team.Name
@@ -423,24 +423,24 @@ func (es *EmailService) sendGuestInviteEmails(team *model.Team, channels []*mode
for _, invite := range invites { for _, invite := range invites {
if invite != "" { if invite != "" {
subject := utils.T("api.templates.invite_guest_subject", subject := i18n.T("api.templates.invite_guest_subject",
map[string]interface{}{"SenderName": senderName, map[string]interface{}{"SenderName": senderName,
"TeamDisplayName": team.DisplayName, "TeamDisplayName": team.DisplayName,
"SiteName": es.srv.Config().TeamSettings.SiteName}) "SiteName": es.srv.Config().TeamSettings.SiteName})
bodyPage := es.newEmailTemplate("invite_body", "") bodyPage := es.newEmailTemplate("invite_body", "")
bodyPage.Props["SiteURL"] = siteURL bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["Title"] = utils.T("api.templates.invite_body.title") bodyPage.Props["Title"] = i18n.T("api.templates.invite_body.title")
bodyPage.HTML["Info"] = utils.TranslateAsHTML(utils.T, "api.templates.invite_body_guest.info", bodyPage.HTML["Info"] = i18n.TranslateAsHTML(i18n.T, "api.templates.invite_body_guest.info",
map[string]interface{}{"SenderName": senderName, "TeamDisplayName": team.DisplayName}) map[string]interface{}{"SenderName": senderName, "TeamDisplayName": team.DisplayName})
bodyPage.Props["Button"] = utils.T("api.templates.invite_body.button") bodyPage.Props["Button"] = i18n.T("api.templates.invite_body.button")
bodyPage.Props["SenderName"] = senderName bodyPage.Props["SenderName"] = senderName
bodyPage.Props["SenderId"] = senderUserId bodyPage.Props["SenderId"] = senderUserId
bodyPage.Props["Message"] = "" bodyPage.Props["Message"] = ""
if message != "" { if message != "" {
bodyPage.Props["Message"] = message bodyPage.Props["Message"] = message
} }
bodyPage.HTML["ExtraInfo"] = utils.TranslateAsHTML(utils.T, "api.templates.invite_body.extra_info", bodyPage.HTML["ExtraInfo"] = i18n.TranslateAsHTML(i18n.T, "api.templates.invite_body.extra_info",
map[string]interface{}{"TeamDisplayName": team.DisplayName}) map[string]interface{}{"TeamDisplayName": team.DisplayName})
bodyPage.Props["TeamURL"] = siteURL + "/" + team.Name bodyPage.Props["TeamURL"] = siteURL + "/" + team.Name
@@ -497,9 +497,9 @@ func (es *EmailService) newEmailTemplate(name, locale string) *utils.HTMLTemplat
var localT i18n.TranslateFunc var localT i18n.TranslateFunc
if locale != "" { if locale != "" {
localT = utils.GetUserTranslations(locale) localT = i18n.GetUserTranslations(locale)
} else { } else {
localT = utils.T localT = i18n.T
} }
t.Props["Footer"] = localT("api.templates.email_footer") t.Props["Footer"] = localT("api.templates.email_footer")
@@ -521,7 +521,7 @@ func (es *EmailService) newEmailTemplate(name, locale string) *utils.HTMLTemplat
} }
func (es *EmailService) SendDeactivateAccountEmail(email string, locale, siteURL string) *model.AppError { func (es *EmailService) SendDeactivateAccountEmail(email string, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
serverURL := condenseSiteURL(siteURL) serverURL := condenseSiteURL(siteURL)
@@ -551,7 +551,7 @@ func (es *EmailService) SendRemoveExpiredLicenseEmail(email string, locale, site
return err return err
} }
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.remove_expired_license.subject", subject := T("api.templates.remove_expired_license.subject",
map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName}) map[string]interface{}{"SiteName": es.srv.Config().TeamSettings.SiteName})
@@ -623,7 +623,7 @@ func (es *EmailService) CreateVerifyEmailToken(userID string, newEmail string) (
} }
func (es *EmailService) SendAtUserLimitWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) { func (es *EmailService) SendAtUserLimitWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.at_limit_subject") subject := T("api.templates.at_limit_subject")
@@ -646,7 +646,7 @@ func (es *EmailService) SendAtUserLimitWarningEmail(email string, locale string,
// SendUpgradeEmail formats an email template and sends an email to an admin specified in the email arg // SendUpgradeEmail formats an email template and sends an email to an admin specified in the email arg
func (es *EmailService) SendUpgradeEmail(user, email, locale, siteURL, action string) (bool, *model.AppError) { func (es *EmailService) SendUpgradeEmail(user, email, locale, siteURL, action string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
bodyPage := es.newEmailTemplate("cloud_upgrade_request_email", locale) bodyPage := es.newEmailTemplate("cloud_upgrade_request_email", locale)
@@ -674,7 +674,7 @@ func (es *EmailService) SendUpgradeEmail(user, email, locale, siteURL, action st
} }
func (es *EmailService) SendOverUserLimitWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) { func (es *EmailService) SendOverUserLimitWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.over_limit_subject") subject := T("api.templates.over_limit_subject")
@@ -696,7 +696,7 @@ func (es *EmailService) SendOverUserLimitWarningEmail(email string, locale strin
} }
func (es *EmailService) SendOverUserLimitThirtyDayWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) { func (es *EmailService) SendOverUserLimitThirtyDayWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.over_limit_30_days_subject") subject := T("api.templates.over_limit_30_days_subject")
@@ -721,7 +721,7 @@ func (es *EmailService) SendOverUserLimitThirtyDayWarningEmail(email string, loc
} }
func (es *EmailService) SendOverUserLimitNinetyDayWarningEmail(email string, locale string, siteURL string, overLimitDate string) (bool, *model.AppError) { func (es *EmailService) SendOverUserLimitNinetyDayWarningEmail(email string, locale string, siteURL string, overLimitDate string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.over_limit_90_days_subject") subject := T("api.templates.over_limit_90_days_subject")
@@ -745,7 +745,7 @@ func (es *EmailService) SendOverUserLimitNinetyDayWarningEmail(email string, loc
} }
func (es *EmailService) SendOverUserLimitWorkspaceSuspendedWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) { func (es *EmailService) SendOverUserLimitWorkspaceSuspendedWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.over_limit_suspended_subject") subject := T("api.templates.over_limit_suspended_subject")
@@ -767,7 +767,7 @@ func (es *EmailService) SendOverUserLimitWorkspaceSuspendedWarningEmail(email st
} }
func (es *EmailService) SendOverUserFourteenDayWarningEmail(email string, locale string, siteURL string, overLimitDate string) (bool, *model.AppError) { func (es *EmailService) SendOverUserFourteenDayWarningEmail(email string, locale string, siteURL string, overLimitDate string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.over_limit_14_days_subject") subject := T("api.templates.over_limit_14_days_subject")
@@ -788,7 +788,7 @@ func (es *EmailService) SendOverUserFourteenDayWarningEmail(email string, locale
} }
func (es *EmailService) SendOverUserSevenDayWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) { func (es *EmailService) SendOverUserSevenDayWarningEmail(email string, locale string, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.over_limit_7_days_subject") subject := T("api.templates.over_limit_7_days_subject")
@@ -828,7 +828,7 @@ func (es *EmailService) SendSuspensionEmailToSupport(email string, installationI
} }
func (es *EmailService) SendPaymentFailedEmail(email string, locale string, failedPayment *model.FailedPayment, siteURL string) (bool, *model.AppError) { func (es *EmailService) SendPaymentFailedEmail(email string, locale string, failedPayment *model.FailedPayment, siteURL string) (bool, *model.AppError) {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.payment_failed.subject") subject := T("api.templates.payment_failed.subject")
@@ -853,7 +853,7 @@ func (es *EmailService) SendPaymentFailedEmail(email string, locale string, fail
} }
func (es *EmailService) SendNoCardPaymentFailedEmail(email string, locale string, siteURL string) *model.AppError { func (es *EmailService) SendNoCardPaymentFailedEmail(email string, locale string, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
subject := T("api.templates.payment_failed_no_card.subject") subject := T("api.templates.payment_failed_no_card.subject")

Просмотреть файл

@@ -12,10 +12,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -201,7 +200,7 @@ func (es *EmailService) sendBatchedEmailNotification(userID string, notification
return return
} }
translateFunc := utils.GetUserTranslations(user.Locale) translateFunc := i18n.GetUserTranslations(user.Locale)
displayNameFormat := *es.srv.Config().TeamSettings.TeammateNameDisplay displayNameFormat := *es.srv.Config().TeamSettings.TeammateNameDisplay
var contents string var contents string

Просмотреть файл

@@ -8,7 +8,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
const ( const (
@@ -80,7 +80,7 @@ func (a *App) getSessionExpiredPushMessage(session *model.Session) string {
if err == nil { if err == nil {
locale = user.Locale locale = user.Locale
} }
T := utils.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
siteName := *a.Config().TeamSettings.SiteName siteName := *a.Config().TeamSettings.SiteName
props := map[string]interface{}{"siteName": siteName, "daysCount": *a.Config().ServiceSettings.SessionLengthMobileInDays} props := map[string]interface{}{"siteName": siteName, "daysCount": *a.Config().ServiceSettings.SessionLengthMobileInDays}

Просмотреть файл

@@ -34,6 +34,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -456,12 +457,12 @@ func (a *App) doLocalWarnMetricsRequest(rawURL string, upstreamRequest *model.Po
} }
isE0Edition := (model.BuildEnterpriseReady == "true") // license == nil was already validated upstream isE0Edition := (model.BuildEnterpriseReady == "true") // license == nil was already validated upstream
_, warnMetricDisplayTexts := a.getWarnMetricStatusAndDisplayTextsForId(warnMetricId, utils.T, isE0Edition) _, warnMetricDisplayTexts := a.getWarnMetricStatusAndDisplayTextsForId(warnMetricId, i18n.T, isE0Edition)
botPost.Message = ":white_check_mark: " + warnMetricDisplayTexts.BotSuccessMessage botPost.Message = ":white_check_mark: " + warnMetricDisplayTexts.BotSuccessMessage
if isE0Edition { if isE0Edition {
if appErr = a.RequestLicenseAndAckWarnMetric(warnMetricId, true); appErr != nil { if appErr = a.RequestLicenseAndAckWarnMetric(warnMetricId, true); appErr != nil {
botPost.Message = ":warning: " + utils.T("api.server.warn_metric.bot_response.start_trial_failure.message") botPost.Message = ":warning: " + i18n.T("api.server.warn_metric.bot_response.start_trial_failure.message")
} }
} else { } else {
forceAck := upstreamRequest.Context["force_ack"].(bool) forceAck := upstreamRequest.Context["force_ack"].(bool)
@@ -470,12 +471,12 @@ func (a *App) doLocalWarnMetricsRequest(rawURL string, upstreamRequest *model.Po
return appErr return appErr
} }
mailtoLinkText := a.buildWarnMetricMailtoLink(warnMetricId, user) mailtoLinkText := a.buildWarnMetricMailtoLink(warnMetricId, user)
botPost.Message = ":warning: " + utils.T("api.server.warn_metric.bot_response.notification_failure.message") botPost.Message = ":warning: " + i18n.T("api.server.warn_metric.bot_response.notification_failure.message")
actions := []*model.PostAction{} actions := []*model.PostAction{}
actions = append(actions, actions = append(actions,
&model.PostAction{ &model.PostAction{
Id: "emailUs", Id: "emailUs",
Name: utils.T("api.server.warn_metric.email_us"), Name: i18n.T("api.server.warn_metric.email_us"),
Type: model.POST_ACTION_TYPE_BUTTON, Type: model.POST_ACTION_TYPE_BUTTON,
Options: []*model.PostActionOptions{ Options: []*model.PostActionOptions{
{ {
@@ -500,7 +501,7 @@ func (a *App) doLocalWarnMetricsRequest(rawURL string, upstreamRequest *model.Po
AuthorName: "", AuthorName: "",
Title: "", Title: "",
Actions: actions, Actions: actions,
Text: utils.T("api.server.warn_metric.bot_response.notification_failure.body"), Text: i18n.T("api.server.warn_metric.bot_response.notification_failure.body"),
}} }}
model.ParseSlackAttachment(botPost, attachements) model.ParseSlackAttachment(botPost, attachements)
} }
@@ -527,7 +528,7 @@ func (mlc *MailToLinkContent) ToJson() string {
} }
func (a *App) buildWarnMetricMailtoLink(warnMetricId string, user *model.User) string { func (a *App) buildWarnMetricMailtoLink(warnMetricId string, user *model.User) string {
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
_, warnMetricDisplayTexts := a.getWarnMetricStatusAndDisplayTextsForId(warnMetricId, T, false) _, warnMetricDisplayTexts := a.getWarnMetricStatusAndDisplayTextsForId(warnMetricId, T, false)
mailBody := warnMetricDisplayTexts.EmailBody mailBody := warnMetricDisplayTexts.EmailBody
@@ -540,7 +541,7 @@ func (a *App) buildWarnMetricMailtoLink(warnMetricId string, user *model.User) s
if err != nil { if err != nil {
mlog.Warn("Error retrieving the number of registered users", mlog.Err(err)) mlog.Warn("Error retrieving the number of registered users", mlog.Err(err))
} else { } else {
mailBody += utils.T("api.server.warn_metric.bot_response.mailto_registered_users_header", map[string]interface{}{"NoRegisteredUsers": registeredUsersCount}) mailBody += i18n.T("api.server.warn_metric.bot_response.mailto_registered_users_header", map[string]interface{}{"NoRegisteredUsers": registeredUsersCount})
mailBody += "\r\n" mailBody += "\r\n"
} }

Просмотреть файл

@@ -9,7 +9,6 @@ package opentracing
import ( import (
"github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/ext"
spanlog "github.com/opentracing/opentracing-go/log" spanlog "github.com/opentracing/opentracing-go/log"
goi18n "github.com/mattermost/go-i18n/i18n"
) )
type {{.Name}} struct { type {{.Name}} struct {

Просмотреть файл

@@ -10,7 +10,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func (a *App) SyncLdap() { func (a *App) SyncLdap() {
@@ -150,7 +150,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
return "", err return "", err
} }
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
a.Srv().Go(func() { a.Srv().Go(func() {
if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil { if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil {

Просмотреть файл

@@ -16,8 +16,8 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
"github.com/mattermost/mattermost-server/v5/utils/markdown" "github.com/mattermost/mattermost-server/v5/utils/markdown"
) )
@@ -245,7 +245,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
// Check for channel-wide mentions in channels that have too many members for those to work // Check for channel-wide mentions in channels that have too many members for those to work
if int64(len(profileMap)) > *a.Config().TeamSettings.MaxNotificationsPerChannel { if int64(len(profileMap)) > *a.Config().TeamSettings.MaxNotificationsPerChannel {
T := utils.GetUserTranslations(sender.Locale) T := i18n.GetUserTranslations(sender.Locale)
if mentions.HereMentioned { if mentions.HereMentioned {
a.SendEphemeralPost( a.SendEphemeralPost(
@@ -486,7 +486,7 @@ func (a *App) userAllowsEmail(user *model.User, channelMemberNotificationProps m
} }
func (a *App) sendNoUsersNotifiedByGroupInChannel(sender *model.User, post *model.Post, channel *model.Channel, group *model.Group) { func (a *App) sendNoUsersNotifiedByGroupInChannel(sender *model.User, post *model.Post, channel *model.Channel, group *model.Group) {
T := utils.GetUserTranslations(sender.Locale) T := i18n.GetUserTranslations(sender.Locale)
ephemeralPost := &model.Post{ ephemeralPost := &model.Post{
UserId: sender.Id, UserId: sender.Id,
RootId: post.RootId, RootId: post.RootId,
@@ -586,7 +586,7 @@ func makeOutOfChannelMentionPost(sender *model.User, post *model.Post, outOfChan
ogUsers := model.UserSlice(outOfGroupsUsers) ogUsers := model.UserSlice(outOfGroupsUsers)
ogUsernames := ogUsers.Usernames() ogUsernames := ogUsers.Usernames()
T := utils.GetUserTranslations(sender.Locale) T := i18n.GetUserTranslations(sender.Locale)
ephemeralPostId := model.NewId() ephemeralPostId := model.NewId()
var message string var message string
@@ -1003,7 +1003,7 @@ func (n *PostNotification) GetChannelName(userNameFormat, excludeId string) stri
// and whether or not the username has been overridden by an integration. // and whether or not the username has been overridden by an integration.
func (n *PostNotification) GetSenderName(userNameFormat string, overridesAllowed bool) string { func (n *PostNotification) GetSenderName(userNameFormat string, overridesAllowed bool) string {
if n.Post.IsSystemMessage() { if n.Post.IsSystemMessage() {
return utils.T("system.message.name") return i18n.T("system.message.name")
} }
if overridesAllowed && n.Channel.Type != model.CHANNEL_DIRECT { if overridesAllowed && n.Channel.Type != model.CHANNEL_DIRECT {

Просмотреть файл

@@ -13,10 +13,9 @@ import (
"strings" "strings"
"time" "time"
"github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -67,7 +66,7 @@ func (a *App) sendNotificationEmail(notification *PostNotification, user *model.
// fall back to sending a single email if we can't batch it for some reason // fall back to sending a single email if we can't batch it for some reason
} }
translateFunc := utils.GetUserTranslations(user.Locale) translateFunc := i18n.GetUserTranslations(user.Locale)
var useMilitaryTime bool var useMilitaryTime bool
if data, err := a.Srv().Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_USE_MILITARY_TIME); err != nil { if data, err := a.Srv().Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_USE_MILITARY_TIME); err != nil {

Просмотреть файл

@@ -17,8 +17,8 @@ import (
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/timezones" "github.com/mattermost/mattermost-server/v5/services/timezones"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks" "github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/utils"
) )
func TestGetDirectMessageNotificationEmailSubject(t *testing.T) { func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
@@ -27,7 +27,7 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
post := &model.Post{ post := &model.Post{
CreateAt: 1501804801000, CreateAt: 1501804801000,
} }
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
subject := getDirectMessageNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "@sender", true) subject := getDirectMessageNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "@sender", true)
require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject)) require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject))
} }
@@ -38,7 +38,7 @@ func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) {
post := &model.Post{ post := &model.Post{
CreateAt: 1501804801000, CreateAt: 1501804801000,
} }
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
subject := getGroupMessageNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "sender", emailNotificationContentsType, true) subject := getGroupMessageNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "sender", emailNotificationContentsType, true)
require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject)) require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject))
@@ -50,7 +50,7 @@ func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) {
post := &model.Post{ post := &model.Post{
CreateAt: 1501804801000, CreateAt: 1501804801000,
} }
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
subject := getGroupMessageNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "sender", emailNotificationContentsType, true) subject := getGroupMessageNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "sender", emailNotificationContentsType, true)
require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject)) require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject))
@@ -62,7 +62,7 @@ func TestGetNotificationEmailSubject(t *testing.T) {
post := &model.Post{ post := &model.Post{
CreateAt: 1501804801000, CreateAt: 1501804801000,
} }
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
subject := getNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "team", true) subject := getNotificationEmailSubject(user, post, translateFunc, "http://localhost:8065", "team", true)
require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject)) require.Regexp(t, regexp.MustCompile("^"+regexp.QuoteMeta(expectedPrefix)), subject, fmt.Sprintf("Expected subject line prefix '%s', got %s", expectedPrefix, subject))
} }
@@ -84,7 +84,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -116,7 +116,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -148,7 +148,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -180,7 +180,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -215,7 +215,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testi
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -248,7 +248,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -300,7 +300,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T)
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -333,7 +333,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T)
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -363,7 +363,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -394,7 +394,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -425,7 +425,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -456,7 +456,7 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T)
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -489,7 +489,7 @@ func TestGetNotificationEmailEscapingChars(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -528,7 +528,7 @@ func TestGetNotificationEmailBodyPublicChannelMention(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -593,7 +593,7 @@ func TestGetNotificationEmailBodyMultiPublicChannelMention(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -641,7 +641,7 @@ func TestGetNotificationEmailBodyPrivateChannelMention(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/testteam" teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -790,7 +790,7 @@ func TestLandingLink(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/landing#/testteam" teamURL := "http://localhost:8065/landing#/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}
@@ -819,7 +819,7 @@ func TestLandingLinkPermalink(t *testing.T) {
teamName := "testteam" teamName := "testteam"
teamURL := "http://localhost:8065/landing#/testteam" teamURL := "http://localhost:8065/landing#/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en") translateFunc := i18n.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store) storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{} teamStoreMock := mocks.TeamStore{}

Просмотреть файл

@@ -11,12 +11,11 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/mattermost/go-i18n/i18n"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type notificationType string type notificationType string
@@ -533,7 +532,7 @@ func (a *App) BuildPushNotificationMessage(contentsConfig string, post *model.Po
} }
func (a *App) buildIdLoadedPushNotificationMessage(post *model.Post, user *model.User) *model.PushNotification { func (a *App) buildIdLoadedPushNotificationMessage(post *model.Post, user *model.User) *model.PushNotification {
userLocale := utils.GetUserTranslations(user.Locale) userLocale := i18n.GetUserTranslations(user.Locale)
msg := &model.PushNotification{ msg := &model.PushNotification{
PostId: post.Id, PostId: post.Id,
ChannelId: post.ChannelId, ChannelId: post.ChannelId,
@@ -588,7 +587,7 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
} }
} }
userLocale := utils.GetUserTranslations(user.Locale) userLocale := i18n.GetUserTranslations(user.Locale)
hasFiles := post.FileIds != nil && len(post.FileIds) > 0 hasFiles := post.FileIds != nil && len(post.FileIds) > 0
msg.Message = a.getPushNotificationMessage( msg.Message = a.getPushNotificationMessage(

Просмотреть файл

@@ -17,9 +17,9 @@ import (
"github.com/mattermost/mattermost-server/v5/config" "github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks" "github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/testlib" "github.com/mattermost/mattermost-server/v5/testlib"
"github.com/mattermost/mattermost-server/v5/utils"
) )
func TestDoesNotifyPropsAllowPushNotification(t *testing.T) { func TestDoesNotifyPropsAllowPushNotification(t *testing.T) {
@@ -914,7 +914,7 @@ func TestGetPushNotificationMessage(t *testing.T) {
"user", "user",
tc.ChannelType, tc.ChannelType,
tc.replyToThreadType, tc.replyToThreadType,
utils.GetUserTranslations(locale), i18n.GetUserTranslations(locale),
) )
assert.Equal(t, tc.ExpectedMessage, actualMessage) assert.Equal(t, tc.ExpectedMessage, actualMessage)

Просмотреть файл

@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -1821,7 +1822,7 @@ func TestPostNotificationGetSenderName(t *testing.T) {
}, },
"system message": { "system message": {
post: &model.Post{Type: model.POST_SYSTEM_MESSAGE_PREFIX + "custom"}, post: &model.Post{Type: model.POST_SYSTEM_MESSAGE_PREFIX + "custom"},
expected: utils.T("system.message.name"), expected: i18n.T("system.message.name"),
}, },
"overridden username": { "overridden username": {
post: overriddenPost, post: overriddenPost,

Просмотреть файл

@@ -20,6 +20,7 @@ import (
"github.com/mattermost/mattermost-server/v5/einterfaces" "github.com/mattermost/mattermost-server/v5/einterfaces"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -964,7 +965,7 @@ func (a *App) SwitchOAuthToEmail(email, password, requesterId string) (string, *
return "", err return "", err
} }
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
a.Srv().Go(func() { a.Srv().Go(func() {
if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil { if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil {

Просмотреть файл

@@ -18,8 +18,6 @@ import (
"time" "time"
"github.com/dyatlov/go-opengraph/opengraph" "github.com/dyatlov/go-opengraph/opengraph"
"github.com/mattermost/go-i18n/i18n"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/audit" "github.com/mattermost/mattermost-server/v5/audit"
"github.com/mattermost/mattermost-server/v5/einterfaces" "github.com/mattermost/mattermost-server/v5/einterfaces"
@@ -32,6 +30,7 @@ import (
"github.com/mattermost/mattermost-server/v5/services/searchengine" "github.com/mattermost/mattermost-server/v5/services/searchengine"
"github.com/mattermost/mattermost-server/v5/services/timezones" "github.com/mattermost/mattermost-server/v5/services/timezones"
"github.com/mattermost/mattermost-server/v5/services/tracing" "github.com/mattermost/mattermost-server/v5/services/tracing"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/ext"
spanlog "github.com/opentracing/opentracing-go/log" spanlog "github.com/opentracing/opentracing-go/log"
@@ -10377,7 +10376,7 @@ func (a *OpenTracingAppLayer) LimitedClientConfigWithComputed() map[string]strin
return resultVar0 return resultVar0
} }
func (a *OpenTracingAppLayer) ListAllCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) { func (a *OpenTracingAppLayer) ListAllCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError) {
origCtx := a.ctx origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ListAllCommands") span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ListAllCommands")
@@ -10399,7 +10398,7 @@ func (a *OpenTracingAppLayer) ListAllCommands(teamID string, T goi18n.TranslateF
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (a *OpenTracingAppLayer) ListAutocompleteCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) { func (a *OpenTracingAppLayer) ListAutocompleteCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError) {
origCtx := a.ctx origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ListAutocompleteCommands") span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ListAutocompleteCommands")
@@ -10858,7 +10857,7 @@ func (a *OpenTracingAppLayer) NewPluginAPI(manifest *model.Manifest) plugin.API
return resultVar0 return resultVar0
} }
func (a *OpenTracingAppLayer) NewWebConn(ws net.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *app.WebConn { func (a *OpenTracingAppLayer) NewWebConn(ws net.Conn, session model.Session, t i18n.TranslateFunc, locale string) *app.WebConn {
origCtx := a.ctx origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.NewWebConn") span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.NewWebConn")

Просмотреть файл

@@ -16,7 +16,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type PluginAPI struct { type PluginAPI struct {
@@ -76,7 +76,7 @@ func (api *PluginAPI) ExecuteSlashCommand(commandArgs *model.CommandArgs) (*mode
if appErr != nil { if appErr != nil {
return nil, appErr return nil, appErr
} }
commandArgs.T = utils.GetUserTranslations(user.Locale) commandArgs.T = i18n.GetUserTranslations(user.Locale)
commandArgs.SiteURL = api.app.GetSiteURL() commandArgs.SiteURL = api.app.GetSiteURL()
response, appErr := api.app.ExecuteCommand(commandArgs) response, appErr := api.app.ExecuteCommand(commandArgs)
if appErr != nil { if appErr != nil {
@@ -1007,7 +1007,7 @@ func (api *PluginAPI) ListBuiltInCommands() ([]*model.Command, error) {
seen := make(map[string]bool) seen := make(map[string]bool)
for _, value := range commandProviders { for _, value := range commandProviders {
if cmd := value.GetCommand(api.app, utils.T); cmd != nil { if cmd := value.GetCommand(api.app, i18n.T); cmd != nil {
cpy := *cmd cpy := *cmd
if cpy.AutoComplete && !seen[cpy.Trigger] { if cpy.AutoComplete && !seen[cpy.Trigger] {
cpy.Sanitize() cpy.Sanitize()

Просмотреть файл

@@ -25,10 +25,10 @@ import (
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/einterfaces/mocks" "github.com/mattermost/mattermost-server/v5/einterfaces/mocks"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin" "github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
"github.com/mattermost/mattermost-server/v5/utils/fileutils" "github.com/mattermost/mattermost-server/v5/utils/fileutils"
) )
@@ -1689,7 +1689,7 @@ type MockSlashCommandProvider struct {
func (*MockSlashCommandProvider) GetTrigger() string { func (*MockSlashCommandProvider) GetTrigger() string {
return "mock" return "mock"
} }
func (*MockSlashCommandProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command { func (*MockSlashCommandProvider) GetCommand(a *App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: "mock", Trigger: "mock",
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func TestPluginCommand(t *testing.T) { func TestPluginCommand(t *testing.T) {
@@ -99,7 +99,7 @@ func TestPluginCommand(t *testing.T) {
err2 := th.App.DisablePlugin(pluginIDs[0]) err2 := th.App.DisablePlugin(pluginIDs[0])
require.Nil(t, err2) require.Nil(t, err2)
commands, err3 := th.App.ListAutocompleteCommands(args.TeamId, utils.T) commands, err3 := th.App.ListAutocompleteCommands(args.TeamId, i18n.T)
require.Nil(t, err3) require.Nil(t, err3)
for _, commands := range commands { for _, commands := range commands {

Просмотреть файл

@@ -17,8 +17,8 @@ import (
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin" "github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/services/cache" "github.com/mattermost/mattermost-server/v5/services/cache"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
) )
const ( const (
@@ -65,7 +65,7 @@ func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string, setOnl
} }
} }
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
a.SendEphemeralPost( a.SendEphemeralPost(
post.UserId, post.UserId,
&model.Post{ &model.Post{
@@ -218,7 +218,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
if post.Type == "" && !a.HasPermissionToChannel(user.Id, channel.Id, model.PERMISSION_USE_CHANNEL_MENTIONS) { if post.Type == "" && !a.HasPermissionToChannel(user.Id, channel.Id, model.PERMISSION_USE_CHANNEL_MENTIONS) {
mention := post.DisableMentionHighlights() mention := post.DisableMentionHighlights()
if mention != "" { if mention != "" {
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
ephemeralPost = &model.Post{ ephemeralPost = &model.Post{
UserId: user.Id, UserId: user.Id,
RootId: post.RootId, RootId: post.RootId,

Просмотреть файл

@@ -15,6 +15,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -29,7 +30,7 @@ type RateLimiter struct {
func NewRateLimiter(settings *model.RateLimitSettings, trustedProxyIPHeader []string) (*RateLimiter, error) { func NewRateLimiter(settings *model.RateLimitSettings, trustedProxyIPHeader []string) (*RateLimiter, error) {
store, err := memstore.New(*settings.MemoryStoreSize) store, err := memstore.New(*settings.MemoryStoreSize)
if err != nil { if err != nil {
return nil, errors.Wrap(err, utils.T("api.server.start_server.rate_limiting_memory_store")) return nil, errors.Wrap(err, i18n.T("api.server.start_server.rate_limiting_memory_store"))
} }
quota := throttled.RateQuota{ quota := throttled.RateQuota{
@@ -39,7 +40,7 @@ func NewRateLimiter(settings *model.RateLimitSettings, trustedProxyIPHeader []st
throttledRateLimiter, err := throttled.NewGCRARateLimiter(store, quota) throttledRateLimiter, err := throttled.NewGCRARateLimiter(store, quota)
if err != nil { if err != nil {
return nil, errors.Wrap(err, utils.T("api.server.start_server.rate_limiting_rate_limiter")) return nil, errors.Wrap(err, i18n.T("api.server.start_server.rate_limiting_rate_limiter"))
} }
return &RateLimiter{ return &RateLimiter{

Просмотреть файл

@@ -13,7 +13,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/mailservice" "github.com/mattermost/mattermost-server/v5/services/mailservice"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
const ( const (
@@ -116,8 +116,7 @@ func (s *Server) DoSecurityUpdateCheck() {
mlog.Info("Sending security bulletin", mlog.String("bulletin_id", bulletin.Id), mlog.String("user_email", user.Email)) mlog.Info("Sending security bulletin", mlog.String("bulletin_id", bulletin.Id), mlog.String("user_email", user.Email))
license := s.License() license := s.License()
mailConfig := s.MailServiceConfig() mailConfig := s.MailServiceConfig()
mailservice.SendMailUsingConfig(user.Email, i18n.T("mattermost.bulletin.subject"), string(body), mailConfig, license != nil && *license.Features.Compliance, "")
mailservice.SendMailUsingConfig(user.Email, utils.T("mattermost.bulletin.subject"), string(body), mailConfig, license != nil && *license.Features.Compliance, "")
} }
bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id} bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id}

Просмотреть файл

@@ -54,6 +54,7 @@ import (
"github.com/mattermost/mattermost-server/v5/services/timezones" "github.com/mattermost/mattermost-server/v5/services/timezones"
"github.com/mattermost/mattermost-server/v5/services/tracing" "github.com/mattermost/mattermost-server/v5/services/tracing"
"github.com/mattermost/mattermost-server/v5/services/upgrader" "github.com/mattermost/mattermost-server/v5/services/upgrader"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/store/localcachelayer" "github.com/mattermost/mattermost-server/v5/store/localcachelayer"
"github.com/mattermost/mattermost-server/v5/store/retrylayer" "github.com/mattermost/mattermost-server/v5/store/retrylayer"
@@ -288,7 +289,7 @@ func NewServer(options ...Option) (*Server, error) {
if err := utils.TranslationsPreInit(); err != nil { if err := utils.TranslationsPreInit(); err != nil {
return nil, errors.Wrapf(err, "unable to load Mattermost translation files") return nil, errors.Wrapf(err, "unable to load Mattermost translation files")
} }
model.AppErrorInit(utils.T) model.AppErrorInit(i18n.T)
searchEngine := searchengine.NewBroker(s.Config(), s.Jobs) searchEngine := searchengine.NewBroker(s.Config(), s.Jobs)
bleveEngine := bleveengine.NewBleveEngine(s.Config(), s.Jobs) bleveEngine := bleveengine.NewBleveEngine(s.Config(), s.Jobs)
@@ -328,7 +329,7 @@ func NewServer(options ...Option) (*Server, error) {
s.createPushNotificationsHub() s.createPushNotificationsHub()
if err2 := utils.InitTranslations(s.Config().LocalizationSettings); err2 != nil { if err2 := i18n.InitTranslations(*s.Config().LocalizationSettings.DefaultServerLocale, *s.Config().LocalizationSettings.DefaultClientLocale); err2 != nil {
return nil, errors.Wrapf(err2, "unable to load Mattermost translation files") return nil, errors.Wrapf(err2, "unable to load Mattermost translation files")
} }
@@ -1043,7 +1044,7 @@ func (s *Server) Start() error {
listener, err := net.Listen("tcp", addr) listener, err := net.Listen("tcp", addr)
if err != nil { if err != nil {
return errors.Wrapf(err, utils.T("api.server.start_server.starting.critical"), err) return errors.Wrapf(err, i18n.T("api.server.start_server.starting.critical"), err)
} }
s.ListenAddr = listener.Addr().(*net.TCPAddr) s.ListenAddr = listener.Addr().(*net.TCPAddr)
@@ -1059,7 +1060,7 @@ func (s *Server) Start() error {
if host, port, err := net.SplitHostPort(addr); err != nil { if host, port, err := net.SplitHostPort(addr); err != nil {
mlog.Error("Unable to setup forwarding", mlog.Err(err)) mlog.Error("Unable to setup forwarding", mlog.Err(err))
} else if port != "443" { } else if port != "443" {
return fmt.Errorf(utils.T("api.server.start_server.forward80to443.enabled_but_listening_on_wrong_port"), port) return fmt.Errorf(i18n.T("api.server.start_server.forward80to443.enabled_but_listening_on_wrong_port"), port)
} else { } else {
httpListenAddress := net.JoinHostPort(host, "http") httpListenAddress := net.JoinHostPort(host, "http")
@@ -1088,7 +1089,7 @@ func (s *Server) Start() error {
} }
} }
} else if *s.Config().ServiceSettings.UseLetsEncrypt { } else if *s.Config().ServiceSettings.UseLetsEncrypt {
return errors.New(utils.T("api.server.start_server.forward80to443.disabled_while_using_lets_encrypt")) return errors.New(i18n.T("api.server.start_server.forward80to443.disabled_while_using_lets_encrypt"))
} }
s.didFinishListen = make(chan struct{}) s.didFinishListen = make(chan struct{})
@@ -1183,15 +1184,15 @@ func (s *Server) startLocalModeServer() error {
socket := *s.configStore.Get().ServiceSettings.LocalModeSocketLocation socket := *s.configStore.Get().ServiceSettings.LocalModeSocketLocation
if err := os.RemoveAll(socket); err != nil { if err := os.RemoveAll(socket); err != nil {
return errors.Wrapf(err, utils.T("api.server.start_server.starting.critical"), err) return errors.Wrapf(err, i18n.T("api.server.start_server.starting.critical"), err)
} }
unixListener, err := net.Listen("unix", socket) unixListener, err := net.Listen("unix", socket)
if err != nil { if err != nil {
return errors.Wrapf(err, utils.T("api.server.start_server.starting.critical"), err) return errors.Wrapf(err, i18n.T("api.server.start_server.starting.critical"), err)
} }
if err = os.Chmod(socket, 0600); err != nil { if err = os.Chmod(socket, 0600); err != nil {
return errors.Wrapf(err, utils.T("api.server.start_server.starting.critical"), err) return errors.Wrapf(err, i18n.T("api.server.start_server.starting.critical"), err)
} }
go func() { go func() {

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type AwayProvider struct { type AwayProvider struct {
@@ -25,7 +24,7 @@ func (*AwayProvider) GetTrigger() string {
return CmdAway return CmdAway
} }
func (*AwayProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*AwayProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdAway, Trigger: CmdAway,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type HeaderProvider struct { type HeaderProvider struct {
@@ -25,7 +24,7 @@ func (*HeaderProvider) GetTrigger() string {
return CmdHeader return CmdHeader
} }
func (*HeaderProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*HeaderProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdHeader, Trigger: CmdHeader,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type PurposeProvider struct { type PurposeProvider struct {
@@ -25,7 +24,7 @@ func (*PurposeProvider) GetTrigger() string {
return CmdPurpose return CmdPurpose
} }
func (*PurposeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*PurposeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdPurpose, Trigger: CmdPurpose,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type RenameProvider struct { type RenameProvider struct {
@@ -25,7 +24,7 @@ func (*RenameProvider) GetTrigger() string {
return CmdRename return CmdRename
} }
func (*RenameProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*RenameProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
renameAutocompleteData := model.NewAutocompleteData(CmdRename, T("api.command_channel_rename.hint"), T("api.command_channel_rename.desc")) renameAutocompleteData := model.NewAutocompleteData(CmdRename, T("api.command_channel_rename.hint"), T("api.command_channel_rename.desc"))
renameAutocompleteData.AddTextArgument(T("api.command_channel_rename.hint"), "[text]", "") renameAutocompleteData.AddTextArgument(T("api.command_channel_rename.hint"), "[text]", "")
return &model.Command{ return &model.Command{

Просмотреть файл

@@ -6,10 +6,9 @@ package slashcommands
import ( import (
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type CodeProvider struct { type CodeProvider struct {
@@ -27,7 +26,7 @@ func (*CodeProvider) GetTrigger() string {
return CmdCode return CmdCode
} }
func (*CodeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*CodeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdCode, Trigger: CmdCode,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -6,11 +6,10 @@ package slashcommands
import ( import (
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type CustomStatusProvider struct { type CustomStatusProvider struct {
@@ -31,7 +30,7 @@ func (*CustomStatusProvider) GetTrigger() string {
return CmdCustomStatus return CmdCustomStatus
} }
func (*CustomStatusProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*CustomStatusProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdCustomStatus, Trigger: CmdCustomStatus,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type DndProvider struct { type DndProvider struct {
@@ -25,7 +24,7 @@ func (*DndProvider) GetTrigger() string {
return CmdDND return CmdDND
} }
func (*DndProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*DndProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdDND, Trigger: CmdDND,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -8,11 +8,10 @@ import (
"strings" "strings"
"time" "time"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
var echoSem chan bool var echoSem chan bool
@@ -32,7 +31,7 @@ func (*EchoProvider) GetTrigger() string {
return CmdEcho return CmdEcho
} }
func (*EchoProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*EchoProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdEcho, Trigger: CmdEcho,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -6,10 +6,9 @@ package slashcommands
import ( import (
"strconv" "strconv"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type ExpandProvider struct { type ExpandProvider struct {
@@ -36,7 +35,7 @@ func (*CollapseProvider) GetTrigger() string {
return CmdCollapse return CmdCollapse
} }
func (*ExpandProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*ExpandProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdExpand, Trigger: CmdExpand,
AutoComplete: true, AutoComplete: true,
@@ -45,7 +44,7 @@ func (*ExpandProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Com
} }
} }
func (*CollapseProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*CollapseProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdCollapse, Trigger: CmdCollapse,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -7,11 +7,10 @@ import (
"fmt" "fmt"
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type groupmsgProvider struct { type groupmsgProvider struct {
@@ -29,7 +28,7 @@ func (*groupmsgProvider) GetTrigger() string {
return CmdGroupMsg return CmdGroupMsg
} }
func (*groupmsgProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*groupmsgProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdGroupMsg, Trigger: CmdGroupMsg,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -6,10 +6,10 @@ package slashcommands
import ( import (
"testing" "testing"
"github.com/mattermost/go-i18n/i18n"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func TestGroupMsgUsernames(t *testing.T) { func TestGroupMsgUsernames(t *testing.T) {

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type HelpProvider struct { type HelpProvider struct {
@@ -25,7 +24,7 @@ func (h *HelpProvider) GetTrigger() string {
return CmdHelp return CmdHelp
} }
func (h *HelpProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (h *HelpProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdHelp, Trigger: CmdHelp,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -6,11 +6,10 @@ package slashcommands
import ( import (
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type InviteProvider struct { type InviteProvider struct {
@@ -28,7 +27,7 @@ func (*InviteProvider) GetTrigger() string {
return CmdInvite return CmdInvite
} }
func (*InviteProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*InviteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdInvite, Trigger: CmdInvite,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -6,11 +6,10 @@ package slashcommands
import ( import (
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type InvitePeopleProvider struct { type InvitePeopleProvider struct {
@@ -28,7 +27,7 @@ func (*InvitePeopleProvider) GetTrigger() string {
return CmdInvite_PEOPLE return CmdInvite_PEOPLE
} }
func (*InvitePeopleProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*InvitePeopleProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
autoComplete := true autoComplete := true
if !*a.Config().EmailSettings.SendEmailNotifications || !*a.Config().TeamSettings.EnableUserCreation || !*a.Config().ServiceSettings.EnableEmailInvitations { if !*a.Config().EmailSettings.SendEmailNotifications || !*a.Config().TeamSettings.EnableUserCreation || !*a.Config().ServiceSettings.EnableEmailInvitations {
autoComplete = false autoComplete = false

Просмотреть файл

@@ -6,10 +6,9 @@ package slashcommands
import ( import (
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type JoinProvider struct { type JoinProvider struct {
@@ -27,7 +26,7 @@ func (*JoinProvider) GetTrigger() string {
return CmdJoin return CmdJoin
} }
func (*JoinProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*JoinProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdJoin, Trigger: CmdJoin,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -6,10 +6,10 @@ package slashcommands
import ( import (
"testing" "testing"
"github.com/mattermost/go-i18n/i18n"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func TestJoinCommandNoChannel(t *testing.T) { func TestJoinCommandNoChannel(t *testing.T) {

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type LeaveProvider struct { type LeaveProvider struct {
@@ -25,7 +24,7 @@ func (*LeaveProvider) GetTrigger() string {
return CmdLeave return CmdLeave
} }
func (*LeaveProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*LeaveProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdLeave, Trigger: CmdLeave,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -12,12 +12,12 @@ import (
"strconv" "strconv"
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -95,7 +95,7 @@ func (*LoadTestProvider) GetTrigger() string {
return CmdTest return CmdTest
} }
func (*LoadTestProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*LoadTestProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
if !*a.Config().ServiceSettings.EnableTesting { if !*a.Config().ServiceSettings.EnableTesting {
return nil return nil
} }

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type LogoutProvider struct { type LogoutProvider struct {
@@ -25,7 +24,7 @@ func (*LogoutProvider) GetTrigger() string {
return CmdLogout return CmdLogout
} }
func (*LogoutProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*LogoutProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdLogout, Trigger: CmdLogout,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type MeProvider struct { type MeProvider struct {
@@ -25,7 +24,7 @@ func (*MeProvider) GetTrigger() string {
return CmdMe return CmdMe
} }
func (*MeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*MeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdMe, Trigger: CmdMe,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -7,11 +7,10 @@ import (
"errors" "errors"
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
) )
@@ -30,7 +29,7 @@ func (*msgProvider) GetTrigger() string {
return CmdMsg return CmdMsg
} }
func (*msgProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*msgProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdMsg, Trigger: CmdMsg,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -6,10 +6,10 @@ package slashcommands
import ( import (
"testing" "testing"
"github.com/mattermost/go-i18n/i18n"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func TestMsgProvider(t *testing.T) { func TestMsgProvider(t *testing.T) {

Просмотреть файл

@@ -6,10 +6,9 @@ package slashcommands
import ( import (
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type MuteProvider struct { type MuteProvider struct {
@@ -27,7 +26,7 @@ func (*MuteProvider) GetTrigger() string {
return CmdMute return CmdMute
} }
func (*MuteProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*MuteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdMute, Trigger: CmdMute,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -7,10 +7,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/mattermost/go-i18n/i18n"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func TestMuteCommandNoChannel(t *testing.T) { func TestMuteCommandNoChannel(t *testing.T) {

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type OfflineProvider struct { type OfflineProvider struct {
@@ -25,7 +24,7 @@ func (*OfflineProvider) GetTrigger() string {
return CmdOffline return CmdOffline
} }
func (*OfflineProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*OfflineProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdOffline, Trigger: CmdOffline,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type OnlineProvider struct { type OnlineProvider struct {
@@ -25,7 +24,7 @@ func (*OnlineProvider) GetTrigger() string {
return CmdOnline return CmdOnline
} }
func (*OnlineProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*OnlineProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdOnline, Trigger: CmdOnline,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type OpenProvider struct { type OpenProvider struct {
@@ -26,7 +25,7 @@ func (open *OpenProvider) GetTrigger() string {
return CmdOpen return CmdOpen
} }
func (open *OpenProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (open *OpenProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
cmd := open.JoinProvider.GetCommand(a, T) cmd := open.JoinProvider.GetCommand(a, T)
cmd.Trigger = CmdOpen cmd.Trigger = CmdOpen
cmd.DisplayName = T("api.command_open.name") cmd.DisplayName = T("api.command_open.name")

Просмотреть файл

@@ -6,11 +6,10 @@ package slashcommands
import ( import (
"strings" "strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type RemoveProvider struct { type RemoveProvider struct {
@@ -37,7 +36,7 @@ func (*KickProvider) GetTrigger() string {
return CmdKick return CmdKick
} }
func (*RemoveProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*RemoveProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdRemove, Trigger: CmdRemove,
AutoComplete: true, AutoComplete: true,
@@ -47,7 +46,7 @@ func (*RemoveProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Com
} }
} }
func (*KickProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*KickProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdKick, Trigger: CmdKick,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type SearchProvider struct { type SearchProvider struct {
@@ -25,7 +24,7 @@ func (search *SearchProvider) GetTrigger() string {
return CmdSearch return CmdSearch
} }
func (search *SearchProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (search *SearchProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdSearch, Trigger: CmdSearch,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type SettingsProvider struct { type SettingsProvider struct {
@@ -25,7 +24,7 @@ func (settings *SettingsProvider) GetTrigger() string {
return CmdSettings return CmdSettings
} }
func (settings *SettingsProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (settings *SettingsProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdSettings, Trigger: CmdSettings,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type ShortcutsProvider struct { type ShortcutsProvider struct {
@@ -25,7 +24,7 @@ func (*ShortcutsProvider) GetTrigger() string {
return CmdShortcuts return CmdShortcuts
} }
func (*ShortcutsProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*ShortcutsProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdShortcuts, Trigger: CmdShortcuts,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -4,10 +4,9 @@
package slashcommands package slashcommands
import ( import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type ShrugProvider struct { type ShrugProvider struct {
@@ -25,7 +24,7 @@ func (*ShrugProvider) GetTrigger() string {
return CmdShrug return CmdShrug
} }
func (*ShrugProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { func (*ShrugProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
return &model.Command{ return &model.Command{
Trigger: CmdShrug, Trigger: CmdShrug,
AutoComplete: true, AutoComplete: true,

Просмотреть файл

@@ -21,8 +21,8 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin" "github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
) )
func (a *App) CreateTeam(team *model.Team) (*model.Team, *model.AppError) { func (a *App) CreateTeam(team *model.Team) (*model.Team, *model.AppError) {
@@ -1325,7 +1325,7 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User, requestorId string)
func (a *App) postLeaveTeamMessage(user *model.User, channel *model.Channel) *model.AppError { func (a *App) postLeaveTeamMessage(user *model.User, channel *model.Channel) *model.AppError {
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
Message: fmt.Sprintf(utils.T("api.team.leave.left"), user.Username), Message: fmt.Sprintf(i18n.T("api.team.leave.left"), user.Username),
Type: model.POST_LEAVE_TEAM, Type: model.POST_LEAVE_TEAM,
UserId: user.Id, UserId: user.Id,
Props: model.StringInterface{ Props: model.StringInterface{
@@ -1343,7 +1343,7 @@ func (a *App) postLeaveTeamMessage(user *model.User, channel *model.Channel) *mo
func (a *App) postRemoveFromTeamMessage(user *model.User, channel *model.Channel) *model.AppError { func (a *App) postRemoveFromTeamMessage(user *model.User, channel *model.Channel) *model.AppError {
post := &model.Post{ post := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
Message: fmt.Sprintf(utils.T("api.team.remove_user_from_team.removed"), user.Username), Message: fmt.Sprintf(i18n.T("api.team.remove_user_from_team.removed"), user.Username),
Type: model.POST_REMOVE_FROM_TEAM, Type: model.POST_REMOVE_FROM_TEAM,
UserId: user.Id, UserId: user.Id,
Props: model.StringInterface{ Props: model.StringInterface{

Просмотреть файл

@@ -34,8 +34,8 @@ import (
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin" "github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/services/mfa" "github.com/mattermost/mattermost-server/v5/services/mfa"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
"github.com/mattermost/mattermost-server/v5/utils/fileutils" "github.com/mattermost/mattermost-server/v5/utils/fileutils"
) )
@@ -266,7 +266,7 @@ func (a *App) createUserOrGuest(user *model.User, guest bool) (*model.User, *mod
user.Roles = model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID user.Roles = model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID
} }
if _, ok := utils.GetSupportedLocales()[user.Locale]; !ok { if _, ok := i18n.GetSupportedLocales()[user.Locale]; !ok {
user.Locale = *a.Config().LocalizationSettings.DefaultClientLocale user.Locale = *a.Config().LocalizationSettings.DefaultClientLocale
} }
@@ -1046,7 +1046,7 @@ func (a *App) UpdatePasswordAsUser(userID, currentPassword, newPassword string)
return err return err
} }
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
return a.UpdatePasswordSendEmail(user, newPassword, T("api.user.update_password.menu")) return a.UpdatePasswordSendEmail(user, newPassword, T("api.user.update_password.menu"))
} }
@@ -1463,7 +1463,7 @@ func (a *App) ResetPasswordFromToken(userSuppliedTokenString, newPassword string
return model.NewAppError("ResetPasswordFromCode", "api.user.reset_password.sso.app_error", nil, "userId="+user.Id, http.StatusBadRequest) return model.NewAppError("ResetPasswordFromCode", "api.user.reset_password.sso.app_error", nil, "userId="+user.Id, http.StatusBadRequest)
} }
T := utils.GetUserTranslations(user.Locale) T := i18n.GetUserTranslations(user.Locale)
if err := a.UpdatePasswordSendEmail(user, newPassword, T("api.user.reset_password.method")); err != nil { if err := a.UpdatePasswordSendEmail(user, newPassword, T("api.user.reset_password.method")); err != nil {
return err return err

Просмотреть файл

@@ -18,11 +18,11 @@ import (
"github.com/gobwas/ws" "github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil" "github.com/gobwas/ws/wsutil"
"github.com/mailru/easygo/netpoll" "github.com/mailru/easygo/netpoll"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
const ( const (
@@ -43,7 +43,7 @@ type WebConn struct {
sessionExpiresAt int64 // This should stay at the top for 64-bit alignment of 64-bit words accessed atomically sessionExpiresAt int64 // This should stay at the top for 64-bit alignment of 64-bit words accessed atomically
App *App App *App
WebSocket net.Conn WebSocket net.Conn
T goi18n.TranslateFunc T i18n.TranslateFunc
Locale string Locale string
Sequence int64 Sequence int64
UserId string UserId string
@@ -61,7 +61,7 @@ type WebConn struct {
} }
// NewWebConn returns a new WebConn instance. // NewWebConn returns a new WebConn instance.
func (a *App) NewWebConn(ws net.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn { func (a *App) NewWebConn(ws net.Conn, session model.Session, t i18n.TranslateFunc, locale string) *WebConn {
if session.UserId != "" { if session.UserId != "" {
a.Srv().Go(func() { a.Srv().Go(func() {
a.SetStatusOnline(session.UserId, false) a.SetStatusOnline(session.UserId, false)

Просмотреть файл

@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func TestWebConnShouldSendEvent(t *testing.T) { func TestWebConnShouldSendEvent(t *testing.T) {
@@ -28,7 +28,7 @@ func TestWebConnShouldSendEvent(t *testing.T) {
basicUserWc := &WebConn{ basicUserWc := &WebConn{
App: th.App, App: th.App,
UserId: th.BasicUser.Id, UserId: th.BasicUser.Id,
T: utils.T, T: i18n.T,
} }
basicUserWc.SetSession(session) basicUserWc.SetSession(session)
@@ -47,7 +47,7 @@ func TestWebConnShouldSendEvent(t *testing.T) {
basicUser2Wc := &WebConn{ basicUser2Wc := &WebConn{
App: th.App, App: th.App,
UserId: th.BasicUser2.Id, UserId: th.BasicUser2.Id,
T: utils.T, T: i18n.T,
} }
basicUser2Wc.SetSession(session2) basicUser2Wc.SetSession(session2)
@@ -60,7 +60,7 @@ func TestWebConnShouldSendEvent(t *testing.T) {
adminUserWc := &WebConn{ adminUserWc := &WebConn{
App: th.App, App: th.App,
UserId: th.SystemAdminUser.Id, UserId: th.SystemAdminUser.Id,
T: utils.T, T: i18n.T,
} }
adminUserWc.SetSession(session3) adminUserWc.SetSession(session3)

Просмотреть файл

@@ -15,12 +15,12 @@ import (
"github.com/gobwas/ws" "github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil" "github.com/gobwas/ws/wsutil"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks" "github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
) )
@@ -68,7 +68,7 @@ func registerDummyWebConn(t *testing.T, a *App, addr net.Addr, userID string) *W
c, _, _, err := ws.Dial(context.Background(), "ws://"+addr.String()+"/ws") c, _, _, err := ws.Dial(context.Background(), "ws://"+addr.String()+"/ws")
require.NoError(t, err) require.NoError(t, err)
wc := a.NewWebConn(c, *session, goi18n.IdentityTfunc(), "en") wc := a.NewWebConn(c, *session, i18n.IdentityTfunc(), "en")
a.HubRegister(wc) a.HubRegister(wc)
go wc.Pump() go wc.Pump()
return wc return wc

Просмотреть файл

@@ -17,9 +17,9 @@ import (
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/testlib" "github.com/mattermost/mattermost-server/v5/testlib"
) )
@@ -87,7 +87,7 @@ func registerDummyWebConn(a *App, addr net.Addr, userID string) *WebConn {
panic(err) panic(err)
} }
wc := a.NewWebConn(c, *session, goi18n.IdentityTfunc(), "en") wc := a.NewWebConn(c, *session, i18n.IdentityTfunc(), "en")
a.HubRegister(wc) a.HubRegister(wc)
go wc.Pump() go wc.Pump()
return wc return wc

Просмотреть файл

@@ -8,7 +8,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type webSocketHandler interface { type webSocketHandler interface {
@@ -103,7 +103,7 @@ func returnWebSocketError(app *App, conn *WebConn, r *model.WebSocketRequest, er
"websocket routing error.", "websocket routing error.",
mlog.Int64("seq", r.Seq), mlog.Int64("seq", r.Seq),
mlog.String("user_id", conn.UserId), mlog.String("user_id", conn.UserId),
mlog.String("system_message", err.SystemMessage(utils.T)), mlog.String("system_message", err.SystemMessage(i18n.T)),
mlog.Err(err), mlog.Err(err),
) )

Просмотреть файл

@@ -17,6 +17,7 @@ import (
"github.com/mattermost/mattermost-server/v5/config" "github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -106,7 +107,7 @@ func init() {
func configValidateCmdF(command *cobra.Command, args []string) error { func configValidateCmdF(command *cobra.Command, args []string) error {
utils.TranslationsPreInit() utils.TranslationsPreInit()
model.AppErrorInit(utils.T) model.AppErrorInit(i18n.T)
_, err := getConfigStore(command) _, err := getConfigStore(command)
if err != nil { if err != nil {

Просмотреть файл

@@ -9,6 +9,7 @@ import (
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/config" "github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -37,7 +38,7 @@ func initDBCommandContext(configDSN string, readOnlyConfigStore bool) (*app.App,
if err := utils.TranslationsPreInit(); err != nil { if err := utils.TranslationsPreInit(); err != nil {
return nil, err return nil, err
} }
model.AppErrorInit(utils.T) model.AppErrorInit(i18n.T)
s, err := app.NewServer( s, err := app.NewServer(
app.Config(configDSN, false, readOnlyConfigStore, nil), app.Config(configDSN, false, readOnlyConfigStore, nil),

Просмотреть файл

@@ -11,7 +11,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/mattermost/mattermost-server/v5/audit" "github.com/mattermost/mattermost-server/v5/audit"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
var PermissionsCmd = &cobra.Command{ var PermissionsCmd = &cobra.Command{
@@ -102,7 +102,7 @@ func exportPermissionsCmdF(command *cobra.Command, args []string) error {
defer a.Srv().Shutdown() defer a.Srv().Shutdown()
if license := a.Srv().License(); license == nil { if license := a.Srv().License(); license == nil {
return errors.New(utils.T("cli.license.critical")) return errors.New(i18n.T("cli.license.critical"))
} }
if err = a.ExportPermissions(os.Stdout); err != nil { if err = a.ExportPermissions(os.Stdout); err != nil {
@@ -123,7 +123,7 @@ func importPermissionsCmdF(command *cobra.Command, args []string) error {
defer a.Srv().Shutdown() defer a.Srv().Shutdown()
if license := a.Srv().License(); license == nil { if license := a.Srv().License(); license == nil {
return errors.New(utils.T("cli.license.critical")) return errors.New(i18n.T("cli.license.critical"))
} }
file, err := os.Open(args[0]) file, err := os.Open(args[0])

Просмотреть файл

@@ -6,9 +6,8 @@ package commands
import ( import (
"testing" "testing"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v5/utils"
) )
func TestPermissionsExport_rejectsUnlicensed(t *testing.T) { func TestPermissionsExport_rejectsUnlicensed(t *testing.T) {
@@ -16,7 +15,7 @@ func TestPermissionsExport_rejectsUnlicensed(t *testing.T) {
defer th.TearDown() defer th.TearDown()
actual, _ := th.RunCommandWithOutput(t, "permissions", "export") actual, _ := th.RunCommandWithOutput(t, "permissions", "export")
assert.Contains(t, actual, utils.T("cli.license.critical")) assert.Contains(t, actual, i18n.T("cli.license.critical"))
} }
func TestPermissionsImport_rejectsUnlicensed(t *testing.T) { func TestPermissionsImport_rejectsUnlicensed(t *testing.T) {
@@ -25,5 +24,5 @@ func TestPermissionsImport_rejectsUnlicensed(t *testing.T) {
actual, _ := th.RunCommandWithOutput(t, "permissions", "import") actual, _ := th.RunCommandWithOutput(t, "permissions", "import")
assert.Contains(t, actual, utils.T("cli.license.critical")) assert.Contains(t, actual, i18n.T("cli.license.critical"))
} }

Просмотреть файл

@@ -15,7 +15,7 @@ import (
"github.com/mattermost/mattermost-server/v5/api4" "github.com/mattermost/mattermost-server/v5/api4"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/wsapi" "github.com/mattermost/mattermost-server/v5/wsapi"
) )
@@ -52,7 +52,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error {
} }
defer a.Srv().Shutdown() defer a.Srv().Shutdown()
utils.InitTranslations(a.Config().LocalizationSettings) i18n.InitTranslations(*a.Config().LocalizationSettings.DefaultServerLocale, *a.Config().LocalizationSettings.DefaultClientLocale)
serverErr := a.Srv().Start() serverErr := a.Srv().Start()
if serverErr != nil { if serverErr != nil {
return serverErr return serverErr
@@ -73,7 +73,7 @@ func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
} }
defer a.Srv().Shutdown() defer a.Srv().Shutdown()
utils.InitTranslations(a.Config().LocalizationSettings) i18n.InitTranslations(*a.Config().LocalizationSettings.DefaultServerLocale, *a.Config().LocalizationSettings.DefaultClientLocale)
serverErr := a.Srv().Start() serverErr := a.Srv().Start()
if serverErr != nil { if serverErr != nil {
return serverErr return serverErr

Просмотреть файл

@@ -10,6 +10,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -110,7 +111,7 @@ func fixConfig(cfg *model.Config) {
func FixInvalidLocales(cfg *model.Config) bool { func FixInvalidLocales(cfg *model.Config) bool {
var changed bool var changed bool
locales := utils.GetSupportedLocales() locales := i18n.GetSupportedLocales()
if _, ok := locales[*cfg.LocalizationSettings.DefaultServerLocale]; !ok { if _, ok := locales[*cfg.LocalizationSettings.DefaultServerLocale]; !ok {
*cfg.LocalizationSettings.DefaultServerLocale = model.DEFAULT_LOCALE *cfg.LocalizationSettings.DefaultServerLocale = model.DEFAULT_LOCALE
mlog.Warn("DefaultServerLocale must be one of the supported locales. Setting DefaultServerLocale to en as default value.") mlog.Warn("DefaultServerLocale must be one of the supported locales. Setting DefaultServerLocale to en as default value.")

Просмотреть файл

@@ -7,21 +7,21 @@ import (
"encoding/json" "encoding/json"
"io" "io"
goi18n "github.com/mattermost/go-i18n/i18n" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
type CommandArgs struct { type CommandArgs struct {
UserId string `json:"user_id"` UserId string `json:"user_id"`
ChannelId string `json:"channel_id"` ChannelId string `json:"channel_id"`
TeamId string `json:"team_id"` TeamId string `json:"team_id"`
RootId string `json:"root_id"` RootId string `json:"root_id"`
ParentId string `json:"parent_id"` ParentId string `json:"parent_id"`
TriggerId string `json:"trigger_id,omitempty"` TriggerId string `json:"trigger_id,omitempty"`
Command string `json:"command"` Command string `json:"command"`
SiteURL string `json:"-"` SiteURL string `json:"-"`
T goi18n.TranslateFunc `json:"-"` T i18n.TranslateFunc `json:"-"`
UserMentions UserMentionMap `json:"-"` UserMentions UserMentionMap `json:"-"`
ChannelMentions ChannelMentionMap `json:"-"` ChannelMentions ChannelMentionMap `json:"-"`
// DO NOT USE Session field is deprecated. MM-26398 // DO NOT USE Session field is deprecated. MM-26398
Session Session `json:"-"` Session Session `json:"-"`

Просмотреть файл

@@ -22,7 +22,7 @@ import (
"time" "time"
"unicode" "unicode"
goi18n "github.com/mattermost/go-i18n/i18n" "github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/pborman/uuid" "github.com/pborman/uuid"
) )
@@ -73,10 +73,10 @@ func (sa StringArray) Equals(input StringArray) bool {
return true return true
} }
var translateFunc goi18n.TranslateFunc var translateFunc i18n.TranslateFunc
var translateFuncOnce sync.Once var translateFuncOnce sync.Once
func AppErrorInit(t goi18n.TranslateFunc) { func AppErrorInit(t i18n.TranslateFunc) {
translateFuncOnce.Do(func() { translateFuncOnce.Do(func() {
translateFunc = t translateFunc = t
}) })
@@ -97,7 +97,7 @@ func (er *AppError) Error() string {
return er.Where + ": " + er.Message + ", " + er.DetailedError return er.Where + ": " + er.Message + ", " + er.DetailedError
} }
func (er *AppError) Translate(T goi18n.TranslateFunc) { func (er *AppError) Translate(T i18n.TranslateFunc) {
if T == nil { if T == nil {
er.Message = er.Id er.Message = er.Id
return return
@@ -110,7 +110,7 @@ func (er *AppError) Translate(T goi18n.TranslateFunc) {
} }
} }
func (er *AppError) SystemMessage(T goi18n.TranslateFunc) string { func (er *AppError) SystemMessage(T i18n.TranslateFunc) string {
if er.params == nil { if er.params == nil {
return T(er.Id) return T(er.Id)
} }

Просмотреть файл

@@ -7,7 +7,7 @@ import (
"encoding/json" "encoding/json"
"io" "io"
goi18n "github.com/mattermost/go-i18n/i18n" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
// WebSocketRequest represents a request made to the server through a websocket. // WebSocketRequest represents a request made to the server through a websocket.
@@ -18,9 +18,9 @@ type WebSocketRequest struct {
Data map[string]interface{} `json:"data"` // The metadata for an action. Data map[string]interface{} `json:"data"` // The metadata for an action.
// Server-provided fields // Server-provided fields
Session Session `json:"-"` Session Session `json:"-"`
T goi18n.TranslateFunc `json:"-"` T i18n.TranslateFunc `json:"-"`
Locale string `json:"-"` Locale string `json:"-"`
} }
func (o *WebSocketRequest) ToJson() string { func (o *WebSocketRequest) ToJson() string {

Просмотреть файл

@@ -19,6 +19,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -114,11 +115,11 @@ func New(store store.Store, actions Actions, config *model.Config) *SlackImporte
func (si *SlackImporter) SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) { func (si *SlackImporter) SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
// Create log file // Create log file
log := bytes.NewBufferString(utils.T("api.slackimport.slack_import.log")) log := bytes.NewBufferString(i18n.T("api.slackimport.slack_import.log"))
zipreader, err := zip.NewReader(fileData, fileSize) zipreader, err := zip.NewReader(fileData, fileSize)
if err != nil || zipreader.File == nil { if err != nil || zipreader.File == nil {
log.WriteString(utils.T("api.slackimport.slack_import.zip.app_error")) log.WriteString(i18n.T("api.slackimport.slack_import.zip.app_error"))
return model.NewAppError("SlackImport", "api.slackimport.slack_import.zip.app_error", nil, err.Error(), http.StatusBadRequest), log return model.NewAppError("SlackImport", "api.slackimport.slack_import.zip.app_error", nil, err.Error(), http.StatusBadRequest), log
} }
@@ -133,12 +134,12 @@ func (si *SlackImporter) SlackImport(fileData multipart.File, fileSize int64, te
uploads := make(map[string]*zip.File) uploads := make(map[string]*zip.File)
for _, file := range zipreader.File { for _, file := range zipreader.File {
if file.UncompressedSize64 > slackImportMaxFileSize { if file.UncompressedSize64 > slackImportMaxFileSize {
log.WriteString(utils.T("api.slackimport.slack_import.zip.file_too_large", map[string]interface{}{"Filename": file.Name})) log.WriteString(i18n.T("api.slackimport.slack_import.zip.file_too_large", map[string]interface{}{"Filename": file.Name}))
continue continue
} }
reader, err := file.Open() reader, err := file.Open()
if err != nil { if err != nil {
log.WriteString(utils.T("api.slackimport.slack_import.open.app_error", map[string]interface{}{"Filename": file.Name})) log.WriteString(i18n.T("api.slackimport.slack_import.open.app_error", map[string]interface{}{"Filename": file.Name}))
return model.NewAppError("SlackImport", "api.slackimport.slack_import.open.app_error", map[string]interface{}{"Filename": file.Name}, err.Error(), http.StatusInternalServerError), log return model.NewAppError("SlackImport", "api.slackimport.slack_import.open.app_error", map[string]interface{}{"Filename": file.Name}, err.Error(), http.StatusInternalServerError), log
} }
if file.Name == "channels.json" { if file.Name == "channels.json" {
@@ -186,12 +187,12 @@ func (si *SlackImporter) SlackImport(fileData multipart.File, fileSize int64, te
si.actions.InvalidateAllCaches() si.actions.InvalidateAllCaches()
log.WriteString(utils.T("api.slackimport.slack_import.notes")) log.WriteString(i18n.T("api.slackimport.slack_import.notes"))
log.WriteString("=======\r\n\r\n") log.WriteString("=======\r\n\r\n")
log.WriteString(utils.T("api.slackimport.slack_import.note1")) log.WriteString(i18n.T("api.slackimport.slack_import.note1"))
log.WriteString(utils.T("api.slackimport.slack_import.note2")) log.WriteString(i18n.T("api.slackimport.slack_import.note2"))
log.WriteString(utils.T("api.slackimport.slack_import.note3")) log.WriteString(i18n.T("api.slackimport.slack_import.note3"))
return nil, log return nil, log
} }
@@ -206,7 +207,7 @@ func truncateRunes(s string, i int) string {
func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, importerLog *bytes.Buffer) map[string]*model.User { func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, importerLog *bytes.Buffer) map[string]*model.User {
// Log header // Log header
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.created")) importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.created"))
importerLog.WriteString("===============\r\n\r\n") importerLog.WriteString("===============\r\n\r\n")
addedUsers := make(map[string]*model.User) addedUsers := make(map[string]*model.User)
@@ -214,7 +215,7 @@ func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, im
// Need the team // Need the team
team, err := si.store.Team().Get(teamId) team, err := si.store.Team().Get(teamId)
if err != nil { if err != nil {
importerLog.WriteString(utils.T("api.slackimport.slack_import.team_fail")) importerLog.WriteString(i18n.T("api.slackimport.slack_import.team_fail"))
return addedUsers return addedUsers
} }
@@ -224,7 +225,7 @@ func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, im
email := sUser.Profile.Email email := sUser.Profile.Email
if email == "" { if email == "" {
email = sUser.Username + "@example.com" email = sUser.Username + "@example.com"
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.missing_email_address", map[string]interface{}{"Email": email, "Username": sUser.Username})) importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.missing_email_address", map[string]interface{}{"Email": email, "Username": sUser.Username}))
mlog.Warn("Slack Import: User does not have an email address in the Slack export. Used username as a placeholder. The user should update their email address once logged in to the system.", mlog.String("user_email", email), mlog.String("user_name", sUser.Username)) mlog.Warn("Slack Import: User does not have an email address in the Slack export. Used username as a placeholder. The user should update their email address once logged in to the system.", mlog.String("user_email", email), mlog.String("user_name", sUser.Username))
} }
@@ -234,9 +235,9 @@ func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, im
if existingUser, err := si.store.User().GetByEmail(email); err == nil { if existingUser, err := si.store.User().GetByEmail(email); err == nil {
addedUsers[sUser.Id] = existingUser addedUsers[sUser.Id] = existingUser
if err := si.actions.JoinUserToTeam(team, addedUsers[sUser.Id], ""); err != nil { if err := si.actions.JoinUserToTeam(team, addedUsers[sUser.Id], ""); err != nil {
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.merge_existing_failed", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username})) importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.merge_existing_failed", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username}))
} else { } else {
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.merge_existing", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username})) importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.merge_existing", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username}))
} }
continue continue
} }
@@ -252,11 +253,11 @@ func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, im
mUser := si.oldImportUser(team, &newUser) mUser := si.oldImportUser(team, &newUser)
if mUser == nil { if mUser == nil {
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.unable_import", map[string]interface{}{"Username": sUser.Username})) importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.unable_import", map[string]interface{}{"Username": sUser.Username}))
continue continue
} }
addedUsers[sUser.Id] = mUser addedUsers[sUser.Id] = mUser
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.email_pwd", map[string]interface{}{"Email": newUser.Email, "Password": password})) importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.email_pwd", map[string]interface{}{"Email": newUser.Email, "Password": password}))
} }
return addedUsers return addedUsers
@@ -265,7 +266,7 @@ func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, im
func (si *SlackImporter) slackAddBotUser(teamId string, log *bytes.Buffer) *model.User { func (si *SlackImporter) slackAddBotUser(teamId string, log *bytes.Buffer) *model.User {
team, err := si.store.Team().Get(teamId) team, err := si.store.Team().Get(teamId)
if err != nil { if err != nil {
log.WriteString(utils.T("api.slackimport.slack_import.team_fail")) log.WriteString(i18n.T("api.slackimport.slack_import.team_fail"))
return nil return nil
} }
@@ -283,11 +284,11 @@ func (si *SlackImporter) slackAddBotUser(teamId string, log *bytes.Buffer) *mode
mUser := si.oldImportUser(team, &botUser) mUser := si.oldImportUser(team, &botUser)
if mUser == nil { if mUser == nil {
log.WriteString(utils.T("api.slackimport.slack_add_bot_user.unable_import", map[string]interface{}{"Username": username})) log.WriteString(i18n.T("api.slackimport.slack_add_bot_user.unable_import", map[string]interface{}{"Username": username}))
return nil return nil
} }
log.WriteString(utils.T("api.slackimport.slack_add_bot_user.email_pwd", map[string]interface{}{"Email": botUser.Email, "Password": password})) log.WriteString(i18n.T("api.slackimport.slack_add_bot_user.email_pwd", map[string]interface{}{"Email": botUser.Email, "Password": password}))
return mUser return mUser
} }
@@ -531,11 +532,11 @@ func (si *SlackImporter) addSlackUsersToChannel(members []string, users map[stri
for _, member := range members { for _, member := range members {
user, ok := users[member] user, ok := users[member]
if !ok { if !ok {
log.WriteString(utils.T("api.slackimport.slack_add_channels.failed_to_add_user", map[string]interface{}{"Username": "?"})) log.WriteString(i18n.T("api.slackimport.slack_add_channels.failed_to_add_user", map[string]interface{}{"Username": "?"}))
continue continue
} }
if _, err := si.actions.AddUserToChannel(user, channel); err != nil { if _, err := si.actions.AddUserToChannel(user, channel); err != nil {
log.WriteString(utils.T("api.slackimport.slack_add_channels.failed_to_add_user", map[string]interface{}{"Username": user.Username})) log.WriteString(i18n.T("api.slackimport.slack_add_channels.failed_to_add_user", map[string]interface{}{"Username": user.Username}))
} }
} }
} }
@@ -566,7 +567,7 @@ func slackSanitiseChannelProperties(channel model.Channel) model.Channel {
func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackChannel, posts map[string][]slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel { func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackChannel, posts map[string][]slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel {
// Write Header // Write Header
importerLog.WriteString(utils.T("api.slackimport.slack_add_channels.added")) importerLog.WriteString(i18n.T("api.slackimport.slack_add_channels.added"))
importerLog.WriteString("=================\r\n\r\n") importerLog.WriteString("=================\r\n\r\n")
addedChannels := make(map[string]*model.Channel) addedChannels := make(map[string]*model.Channel)
@@ -591,7 +592,7 @@ func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackCh
var err error var err error
if mChannel, err = si.store.Channel().GetByName(teamId, sChannel.Name, true); err == nil { if mChannel, err = si.store.Channel().GetByName(teamId, sChannel.Name, true); err == nil {
// The channel already exists as an active channel. Merge with the existing one. // The channel already exists as an active channel. Merge with the existing one.
importerLog.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName})) importerLog.WriteString(i18n.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
} else if _, nErr := si.store.Channel().GetDeletedByName(teamId, sChannel.Name); nErr == nil { } else if _, nErr := si.store.Channel().GetDeletedByName(teamId, sChannel.Name); nErr == nil {
// The channel already exists but has been deleted. Generate a random string for the handle instead. // The channel already exists but has been deleted. Generate a random string for the handle instead.
newChannel.Name = model.NewId() newChannel.Name = model.NewId()
@@ -603,7 +604,7 @@ func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackCh
mChannel = si.oldImportChannel(&newChannel, sChannel, users) mChannel = si.oldImportChannel(&newChannel, sChannel, users)
if mChannel == nil { if mChannel == nil {
mlog.Warn("Slack Import: Unable to import Slack channel.", mlog.String("channel_display_name", newChannel.DisplayName)) mlog.Warn("Slack Import: Unable to import Slack channel.", mlog.String("channel_display_name", newChannel.DisplayName))
importerLog.WriteString(utils.T("api.slackimport.slack_add_channels.import_failed", map[string]interface{}{"DisplayName": newChannel.DisplayName})) importerLog.WriteString(i18n.T("api.slackimport.slack_add_channels.import_failed", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
continue continue
} }
} }

185
shared/i18n/i18n.go Обычный файл
Просмотреть файл

@@ -0,0 +1,185 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package i18n
import (
"fmt"
"html/template"
"io/ioutil"
"net/http"
"path/filepath"
"reflect"
"strings"
"github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/mlog"
)
const defaultLocale = "en"
// TranslateFunc is the type of the translate functions
type TranslateFunc func(translationID string, args ...interface{}) string
// T is the translate function using the default server language as fallback language
var T TranslateFunc
// TDefault is the translate function using english as fallback language
var TDefault TranslateFunc
var locales map[string]string = make(map[string]string)
var defaultServerLocale string
var defaultClientLocale string
// TranslationsPreInit loads translations from filesystem if they are not
// loaded already and assigns english while loading server config
func TranslationsPreInit(translationsDir string) error {
if T != nil {
return nil
}
// Set T even if we fail to load the translations. Lots of shutdown handling code will
// segfault trying to handle the error, and the untranslated IDs are strictly better.
T = tfuncWithFallback(defaultLocale)
TDefault = tfuncWithFallback(defaultLocale)
return initTranslationsWithDir(translationsDir)
}
// InitTranslations set the defaults configured in the server and initialize
// the T function using the server default as fallback language
func InitTranslations(serverLocale, clientLocale string) error {
defaultServerLocale = serverLocale
defaultClientLocale = clientLocale
var err error
T, err = getTranslationsBySystemLocale()
return err
}
func initTranslationsWithDir(dir string) error {
files, _ := ioutil.ReadDir(dir)
for _, f := range files {
if filepath.Ext(f.Name()) == ".json" {
filename := f.Name()
locales[strings.Split(filename, ".")[0]] = filepath.Join(dir, filename)
if err := i18n.LoadTranslationFile(filepath.Join(dir, filename)); err != nil {
return err
}
}
}
return nil
}
func getTranslationsBySystemLocale() (TranslateFunc, error) {
locale := defaultServerLocale
if _, ok := locales[locale]; !ok {
mlog.Warn("Failed to load system translations for", mlog.String("locale", locale), mlog.String("attempting to fall back to default locale", defaultLocale))
locale = defaultLocale
}
if locales[locale] == "" {
return nil, fmt.Errorf("failed to load system translations for '%v'", defaultLocale)
}
translations := tfuncWithFallback(locale)
if translations == nil {
return nil, fmt.Errorf("failed to load system translations")
}
mlog.Info("Loaded system translations", mlog.String("for locale", locale), mlog.String("from locale", locales[locale]))
return translations, nil
}
// GetUserTranslations get the translation function for an specific locale
func GetUserTranslations(locale string) TranslateFunc {
if _, ok := locales[locale]; !ok {
locale = defaultLocale
}
translations := tfuncWithFallback(locale)
return translations
}
// GetTranslationsAndLocaleFromRequest return the translation function and the
// locale based on a request headers
func GetTranslationsAndLocaleFromRequest(r *http.Request) (TranslateFunc, string) {
// This is for checking against locales like pt_BR or zn_CN
headerLocaleFull := strings.Split(r.Header.Get("Accept-Language"), ",")[0]
// This is for checking against locales like en, es
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
defaultLocale := defaultClientLocale
if locales[headerLocaleFull] != "" {
translations := tfuncWithFallback(headerLocaleFull)
return translations, headerLocaleFull
} else if locales[headerLocale] != "" {
translations := tfuncWithFallback(headerLocale)
return translations, headerLocale
} else if locales[defaultLocale] != "" {
translations := tfuncWithFallback(defaultLocale)
return translations, headerLocale
}
translations := tfuncWithFallback(defaultLocale)
return translations, defaultLocale
}
// GetSupportedLocales return a map of locale code and the file path with the
// translations
func GetSupportedLocales() map[string]string {
return locales
}
func tfuncWithFallback(pref string) TranslateFunc {
t, _ := i18n.Tfunc(pref)
return func(translationID string, args ...interface{}) string {
if translated := t(translationID, args...); translated != translationID {
return translated
}
t, _ := i18n.Tfunc(defaultLocale)
return t(translationID, args...)
}
}
// TranslateAsHTML translates the translationID provided and return a
// template.HTML object
func TranslateAsHTML(t TranslateFunc, translationID string, args map[string]interface{}) template.HTML {
message := t(translationID, escapeForHTML(args))
message = strings.Replace(message, "[[", "<strong>", -1)
message = strings.Replace(message, "]]", "</strong>", -1)
return template.HTML(message)
}
func escapeForHTML(arg interface{}) interface{} {
switch typedArg := arg.(type) {
case string:
return template.HTMLEscapeString(typedArg)
case *string:
return template.HTMLEscapeString(*typedArg)
case map[string]interface{}:
safeArg := make(map[string]interface{}, len(typedArg))
for key, value := range typedArg {
safeArg[key] = escapeForHTML(value)
}
return safeArg
default:
mlog.Warn(
"Unable to escape value for HTML template",
mlog.Any("html_template", arg),
mlog.String("template_type", reflect.ValueOf(arg).Type().String()),
)
return ""
}
}
// IdentityTfunc returns a translation function that don't translate, only
// returns the same id
func IdentityTfunc() TranslateFunc {
return func(translationID string, args ...interface{}) string {
return translationID
}
}

69
shared/i18n/i18n_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,69 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package i18n
import (
"testing"
"github.com/mattermost/go-i18n/i18n/bundle"
"github.com/mattermost/go-i18n/i18n/language"
"github.com/mattermost/go-i18n/i18n/translation"
"github.com/stretchr/testify/assert"
)
var htmlTestTranslationBundle *bundle.Bundle
func init() {
htmlTestTranslationBundle = bundle.New()
fooBold, _ := translation.NewTranslation(map[string]interface{}{
"id": "foo.bold",
"translation": "<p>[[{{ .Foo }}]]</p>",
})
htmlTestTranslationBundle.AddTranslation(&language.Language{Tag: "en"}, fooBold)
}
func TestTranslateAsHTML(t *testing.T) {
assert.EqualValues(t, "<p><strong>&lt;i&gt;foo&lt;/i&gt;</strong></p>", TranslateAsHTML(TranslateFunc(htmlTestTranslationBundle.MustTfunc("en")), "foo.bold", map[string]interface{}{
"Foo": "<i>foo</i>",
}))
}
func TestEscapeForHTML(t *testing.T) {
stringForPointer := "<b>abc</b>"
for name, tc := range map[string]struct {
In interface{}
Expected interface{}
}{
"NoHTML": {
In: "abc",
Expected: "abc",
},
"String": {
In: "<b>abc</b>",
Expected: "&lt;b&gt;abc&lt;/b&gt;",
},
"StringPointer": {
In: &stringForPointer,
Expected: "&lt;b&gt;abc&lt;/b&gt;",
},
"Map": {
In: map[string]interface{}{
"abc": "abc",
"123": "<b>123</b>",
},
Expected: map[string]interface{}{
"abc": "abc",
"123": "&lt;b&gt;123&lt;/b&gt;",
},
},
"Unsupported": {
In: struct{ string }{"<b>abc</b>"},
Expected: "",
},
} {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.Expected, escapeForHTML(tc.In))
})
}
}

Просмотреть файл

@@ -35,8 +35,8 @@ import (
"github.com/mattermost/mattermost-server/v5/einterfaces" "github.com/mattermost/mattermost-server/v5/einterfaces"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
) )
type migrationDirection string type migrationDirection string
@@ -1322,7 +1322,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
binder := func(holder, target interface{}) error { binder := func(holder, target interface{}) error {
s, ok := holder.(*string) s, ok := holder.(*string)
if !ok { if !ok {
return errors.New(utils.T("store.sql.convert_string_map")) return errors.New(i18n.T("store.sql.convert_string_map"))
} }
b := []byte(*s) b := []byte(*s)
return json.Unmarshal(b, target) return json.Unmarshal(b, target)
@@ -1332,7 +1332,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
binder := func(holder, target interface{}) error { binder := func(holder, target interface{}) error {
s, ok := holder.(*string) s, ok := holder.(*string)
if !ok { if !ok {
return errors.New(utils.T("store.sql.convert_string_map")) return errors.New(i18n.T("store.sql.convert_string_map"))
} }
b := []byte(*s) b := []byte(*s)
return json.Unmarshal(b, target) return json.Unmarshal(b, target)
@@ -1342,7 +1342,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
binder := func(holder, target interface{}) error { binder := func(holder, target interface{}) error {
s, ok := holder.(*string) s, ok := holder.(*string)
if !ok { if !ok {
return errors.New(utils.T("store.sql.convert_string_array")) return errors.New(i18n.T("store.sql.convert_string_array"))
} }
b := []byte(*s) b := []byte(*s)
return json.Unmarshal(b, target) return json.Unmarshal(b, target)
@@ -1352,7 +1352,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
binder := func(holder, target interface{}) error { binder := func(holder, target interface{}) error {
s, ok := holder.(*string) s, ok := holder.(*string)
if !ok { if !ok {
return errors.New(utils.T("store.sql.convert_string_interface")) return errors.New(i18n.T("store.sql.convert_string_interface"))
} }
b := []byte(*s) b := []byte(*s)
return json.Unmarshal(b, target) return json.Unmarshal(b, target)
@@ -1362,7 +1362,7 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
binder := func(holder, target interface{}) error { binder := func(holder, target interface{}) error {
s, ok := holder.(*string) s, ok := holder.(*string)
if !ok { if !ok {
return errors.New(utils.T("store.sql.convert_string_interface")) return errors.New(i18n.T("store.sql.convert_string_interface"))
} }
b := []byte(*s) b := []byte(*s)
return json.Unmarshal(b, target) return json.Unmarshal(b, target)

Просмотреть файл

@@ -16,6 +16,7 @@ import (
"unicode/utf8" "unicode/utf8"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func CheckOrigin(r *http.Request, allowedOrigins string) bool { func CheckOrigin(r *http.Request, allowedOrigins string) bool {
@@ -121,9 +122,9 @@ func RenderMobileAuthComplete(w http.ResponseWriter, redirectURL string) {
<div class="icon text-success" style="font-size: 4em"> <div class="icon text-success" style="font-size: 4em">
<i class="fa fa-check-circle" title="Success Icon"></i> <i class="fa fa-check-circle" title="Success Icon"></i>
</div> </div>
<h2> `+T("api.oauth.auth_complete")+` </h2> <h2> `+i18n.T("api.oauth.auth_complete")+` </h2>
<p id="redirecting-message"> `+T("api.oauth.redirecting_back")+` </p> <p id="redirecting-message"> `+i18n.T("api.oauth.redirecting_back")+` </p>
<p id="close-tab-message" style="display: none"> `+T("api.oauth.close_browser")+` </p> <p id="close-tab-message" style="display: none"> `+i18n.T("api.oauth.close_browser")+` </p>
<noscript><meta http-equiv="refresh" content="2; url=`+template.HTMLEscapeString(redirectURL)+`"></noscript> <noscript><meta http-equiv="refresh" content="2; url=`+template.HTMLEscapeString(redirectURL)+`"></noscript>
<script> <script>
window.onload = function() { window.onload = function() {
@@ -142,10 +143,10 @@ func RenderMobileError(config *model.Config, w http.ResponseWriter, err *model.A
<div class="icon" style="color: #ccc; font-size: 4em"> <div class="icon" style="color: #ccc; font-size: 4em">
<span class="fa fa-warning"></span> <span class="fa fa-warning"></span>
</div> </div>
<h2> `+T("error")+` </h2> <h2> `+i18n.T("error")+` </h2>
<p> `+err.Message+` </p> <p> `+err.Message+` </p>
<a href="`+redirectURL+`"> <a href="`+redirectURL+`">
`+T("api.back_to_app", map[string]interface{}{"SiteName": config.TeamSettings.SiteName})+` `+i18n.T("api.back_to_app", map[string]interface{}{"SiteName": config.TeamSettings.SiteName})+`
</a> </a>
`) `)
} }

Просмотреть файл

@@ -9,12 +9,9 @@ import (
"html/template" "html/template"
"io" "io"
"path/filepath" "path/filepath"
"reflect"
"strings"
"sync/atomic" "sync/atomic"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/utils/fileutils" "github.com/mattermost/mattermost-server/v5/utils/fileutils"
@@ -119,32 +116,3 @@ func (t *HTMLTemplate) RenderToWriter(w io.Writer) error {
return nil return nil
} }
func TranslateAsHTML(t i18n.TranslateFunc, translationID string, args map[string]interface{}) template.HTML {
message := t(translationID, escapeForHTML(args))
message = strings.Replace(message, "[[", "<strong>", -1)
message = strings.Replace(message, "]]", "</strong>", -1)
return template.HTML(message)
}
func escapeForHTML(arg interface{}) interface{} {
switch typedArg := arg.(type) {
case string:
return template.HTMLEscapeString(typedArg)
case *string:
return template.HTMLEscapeString(*typedArg)
case map[string]interface{}:
safeArg := make(map[string]interface{}, len(typedArg))
for key, value := range typedArg {
safeArg[key] = escapeForHTML(value)
}
return safeArg
default:
mlog.Warn(
"Unable to escape value for HTML template",
mlog.Any("html_template", arg),
mlog.String("template_type", reflect.ValueOf(arg).Type().String()),
)
return ""
}
}

Просмотреть файл

@@ -12,27 +12,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/go-i18n/i18n/bundle"
"github.com/mattermost/go-i18n/i18n/language"
"github.com/mattermost/go-i18n/i18n/translation"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model"
) )
var htmlTestTranslationBundle *bundle.Bundle
func init() {
htmlTestTranslationBundle = bundle.New()
fooBold, _ := translation.NewTranslation(map[string]interface{}{
"id": "foo.bold",
"translation": "<p>[[{{ .Foo }}]]</p>",
})
htmlTestTranslationBundle.AddTranslation(&language.Language{Tag: "en"}, fooBold)
}
func TestHTMLTemplateWatcher(t *testing.T) { func TestHTMLTemplateWatcher(t *testing.T) {
TranslationsPreInit() TranslationsPreInit()
@@ -101,47 +84,3 @@ func TestHTMLTemplate_RenderError(t *testing.T) {
assert.Error(t, htmlTemplate.RenderToWriter(buf)) assert.Error(t, htmlTemplate.RenderToWriter(buf))
assert.Equal(t, "foo", buf.String()) assert.Equal(t, "foo", buf.String())
} }
func TestTranslateAsHtml(t *testing.T) {
assert.EqualValues(t, "<p><strong>&lt;i&gt;foo&lt;/i&gt;</strong></p>", TranslateAsHTML(i18n.TranslateFunc(htmlTestTranslationBundle.MustTfunc("en")), "foo.bold", map[string]interface{}{
"Foo": "<i>foo</i>",
}))
}
func TestEscapeForHtml(t *testing.T) {
for name, tc := range map[string]struct {
In interface{}
Expected interface{}
}{
"NoHTML": {
In: "abc",
Expected: "abc",
},
"String": {
In: "<b>abc</b>",
Expected: "&lt;b&gt;abc&lt;/b&gt;",
},
"StringPointer": {
In: model.NewString("<b>abc</b>"),
Expected: "&lt;b&gt;abc&lt;/b&gt;",
},
"Map": {
In: map[string]interface{}{
"abc": "abc",
"123": "<b>123</b>",
},
Expected: map[string]interface{}{
"abc": "abc",
"123": "&lt;b&gt;123&lt;/b&gt;",
},
},
"Unsupported": {
In: struct{ string }{"<b>abc</b>"},
Expected: "",
},
} {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.Expected, escapeForHTML(tc.In))
})
}
}

Просмотреть файл

@@ -5,135 +5,25 @@ package utils
import ( import (
"fmt" "fmt"
"io/ioutil"
"net/http"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/mattermost/go-i18n/i18n" "github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils/fileutils" "github.com/mattermost/mattermost-server/v5/utils/fileutils"
) )
var T i18n.TranslateFunc
var TDefault i18n.TranslateFunc
var locales map[string]string = make(map[string]string)
var settings model.LocalizationSettings
// this functions loads translations from filesystem if they are not // this functions loads translations from filesystem if they are not
// loaded already and assigns english while loading server config // loaded already and assigns english while loading server config
func TranslationsPreInit() error { func TranslationsPreInit() error {
if T != nil {
return nil
}
// Set T even if we fail to load the translations. Lots of shutdown handling code will
// segfault trying to handle the error, and the untranslated IDs are strictly better.
T = TfuncWithFallback("en")
TDefault = TfuncWithFallback("en")
translationsDir := "i18n" translationsDir := "i18n"
if mattermostPath := os.Getenv("MM_SERVER_PATH"); mattermostPath != "" { if mattermostPath := os.Getenv("MM_SERVER_PATH"); mattermostPath != "" {
translationsDir = filepath.Join(mattermostPath, "i18n") translationsDir = filepath.Join(mattermostPath, "i18n")
} }
return InitTranslationsWithDir(translationsDir) i18nDirectory, found := fileutils.FindDirRelBinary(translationsDir)
}
func InitTranslations(localizationSettings model.LocalizationSettings) error {
settings = localizationSettings
var err error
T, err = GetTranslationsBySystemLocale()
return err
}
func InitTranslationsWithDir(dir string) error {
i18nDirectory, found := fileutils.FindDirRelBinary(dir)
if !found { if !found {
return fmt.Errorf("unable to find i18n directory at %q", dir) return fmt.Errorf("unable to find i18n directory at %q", translationsDir)
} }
files, _ := ioutil.ReadDir(i18nDirectory) return i18n.TranslationsPreInit(i18nDirectory)
for _, f := range files {
if filepath.Ext(f.Name()) == ".json" {
filename := f.Name()
locales[strings.Split(filename, ".")[0]] = filepath.Join(i18nDirectory, filename)
if err := i18n.LoadTranslationFile(filepath.Join(i18nDirectory, filename)); err != nil {
return err
}
}
}
return nil
}
func GetTranslationsBySystemLocale() (i18n.TranslateFunc, error) {
locale := *settings.DefaultServerLocale
if _, ok := locales[locale]; !ok {
mlog.Warn("Failed to load system translations for", mlog.String("locale", locale), mlog.String("attempting to fall back to default locale", model.DEFAULT_LOCALE))
locale = model.DEFAULT_LOCALE
}
if locales[locale] == "" {
return nil, fmt.Errorf("failed to load system translations for '%v'", model.DEFAULT_LOCALE)
}
translations := TfuncWithFallback(locale)
if translations == nil {
return nil, fmt.Errorf("failed to load system translations")
}
mlog.Info("Loaded system translations", mlog.String("for locale", locale), mlog.String("from locale", locales[locale]))
return translations, nil
}
func GetUserTranslations(locale string) i18n.TranslateFunc {
if _, ok := locales[locale]; !ok {
locale = model.DEFAULT_LOCALE
}
translations := TfuncWithFallback(locale)
return translations
}
func GetTranslationsAndLocale(r *http.Request) (i18n.TranslateFunc, string) {
// This is for checking against locales like pt_BR or zn_CN
headerLocaleFull := strings.Split(r.Header.Get("Accept-Language"), ",")[0]
// This is for checking against locales like en, es
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
defaultLocale := *settings.DefaultClientLocale
if locales[headerLocaleFull] != "" {
translations := TfuncWithFallback(headerLocaleFull)
return translations, headerLocaleFull
} else if locales[headerLocale] != "" {
translations := TfuncWithFallback(headerLocale)
return translations, headerLocale
} else if locales[defaultLocale] != "" {
translations := TfuncWithFallback(defaultLocale)
return translations, headerLocale
}
translations := TfuncWithFallback(model.DEFAULT_LOCALE)
return translations, model.DEFAULT_LOCALE
}
func GetSupportedLocales() map[string]string {
return locales
}
func TfuncWithFallback(pref string) i18n.TranslateFunc {
t, _ := i18n.Tfunc(pref)
return func(translationID string, args ...interface{}) string {
if translated := t(translationID, args...); translated != translationID {
return translated
}
t, _ := i18n.Tfunc(model.DEFAULT_LOCALE)
return t(translationID, args...)
}
} }

Просмотреть файл

@@ -13,6 +13,7 @@ import (
"github.com/mattermost/mattermost-server/v5/audit" "github.com/mattermost/mattermost-server/v5/audit"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -87,7 +88,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
func (c *Context) LogErrorByCode(err *model.AppError) { func (c *Context) LogErrorByCode(err *model.AppError) {
code := err.StatusCode code := err.StatusCode
msg := err.SystemMessage(utils.TDefault) msg := err.SystemMessage(i18n.TDefault)
fields := []mlog.Field{ fields := []mlog.Field{
mlog.String("err_where", err.Where), mlog.String("err_where", err.Where),
mlog.Int("http_code", err.StatusCode), mlog.Int("http_code", err.StatusCode),

Просмотреть файл

@@ -24,6 +24,7 @@ import (
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/tracing" "github.com/mattermost/mattermost-server/v5/services/tracing"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/store/opentracinglayer" "github.com/mattermost/mattermost-server/v5/store/opentracinglayer"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -108,7 +109,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
) )
c.App.InitServer() c.App.InitServer()
t, _ := utils.GetTranslationsAndLocale(r) t, _ := i18n.GetTranslationsAndLocaleFromRequest(r)
c.App.SetT(t) c.App.SetT(t)
c.App.SetRequestId(requestID) c.App.SetRequestId(requestID)
c.App.SetIpAddress(utils.GetIPAddress(r, c.App.Config().ServiceSettings.TrustedProxyIPHeader)) c.App.SetIpAddress(utils.GetIPAddress(r, c.App.Config().ServiceSettings.TrustedProxyIPHeader))

Просмотреть файл

@@ -13,6 +13,7 @@ import (
"github.com/mattermost/mattermost-server/v5/audit" "github.com/mattermost/mattermost-server/v5/audit"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
"github.com/mattermost/mattermost-server/v5/utils/fileutils" "github.com/mattermost/mattermost-server/v5/utils/fileutils"
) )
@@ -147,7 +148,7 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
utils.RenderWebError(c.App.Config(), w, r, err.StatusCode, utils.RenderWebError(c.App.Config(), w, r, err.StatusCode,
url.Values{ url.Values{
"type": []string{"oauth_invalid_redirect_url"}, "type": []string{"oauth_invalid_redirect_url"},
"message": []string{utils.T("api.oauth.allow_oauth.redirect_callback.app_error")}, "message": []string{i18n.T("api.oauth.allow_oauth.redirect_callback.app_error")},
}, c.App.AsymmetricSigningKey()) }, c.App.AsymmetricSigningKey())
return return
} }
@@ -414,7 +415,7 @@ func signupWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
if !*c.App.Config().TeamSettings.EnableUserCreation { if !*c.App.Config().TeamSettings.EnableUserCreation {
utils.RenderWebError(c.App.Config(), w, r, http.StatusBadRequest, url.Values{ utils.RenderWebError(c.App.Config(), w, r, http.StatusBadRequest, url.Values{
"message": []string{utils.T("api.oauth.singup_with_oauth.disabled.app_error")}, "message": []string{i18n.T("api.oauth.singup_with_oauth.disabled.app_error")},
}, c.App.AsymmetricSigningKey()) }, c.App.AsymmetricSigningKey())
return return
} }

Просмотреть файл

@@ -20,6 +20,7 @@ import (
"github.com/mattermost/mattermost-server/v5/einterfaces" "github.com/mattermost/mattermost-server/v5/einterfaces"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/utils"
) )
@@ -534,7 +535,7 @@ func TestOAuthComplete_ErrorMessages(t *testing.T) {
}, },
} }
translationFunc := utils.GetUserTranslations("en") translationFunc := i18n.GetUserTranslations("en")
c.App.SetT(translationFunc) c.App.SetT(translationFunc)
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
c.Logger = mlog.NewTestingLogger(t, buffer) c.Logger = mlog.NewTestingLogger(t, buffer)

Просмотреть файл

@@ -9,7 +9,7 @@ import (
"github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils" "github.com/mattermost/mattermost-server/v5/shared/i18n"
) )
func (api *API) ApiWebSocketHandler(wh func(*model.WebSocketRequest) (map[string]interface{}, *model.AppError)) webSocketHandler { func (api *API) ApiWebSocketHandler(wh func(*model.WebSocketRequest) (map[string]interface{}, *model.AppError)) webSocketHandler {
@@ -37,7 +37,7 @@ func (wh webSocketHandler) ServeWebSocket(conn *app.WebConn, r *model.WebSocketR
mlog.String("action", r.Action), mlog.String("action", r.Action),
mlog.Int64("seq", r.Seq), mlog.Int64("seq", r.Seq),
mlog.String("user_id", conn.UserId), mlog.String("user_id", conn.UserId),
mlog.String("error_message", sessionErr.SystemMessage(utils.T)), mlog.String("error_message", sessionErr.SystemMessage(i18n.T)),
mlog.Err(sessionErr), mlog.Err(sessionErr),
) )
sessionErr.DetailedError = "" sessionErr.DetailedError = ""
@@ -59,7 +59,7 @@ func (wh webSocketHandler) ServeWebSocket(conn *app.WebConn, r *model.WebSocketR
mlog.String("action", r.Action), mlog.String("action", r.Action),
mlog.Int64("seq", r.Seq), mlog.Int64("seq", r.Seq),
mlog.String("user_id", conn.UserId), mlog.String("user_id", conn.UserId),
mlog.String("error_message", err.SystemMessage(utils.T)), mlog.String("error_message", err.SystemMessage(i18n.T)),
mlog.Err(err), mlog.Err(err),
) )
err.DetailedError = "" err.DetailedError = ""