fix(login): avoid disallowed languages with custom texts (#9094)

# Which Problems Are Solved

If a browsers default language is not allowed by instance restrictions,
the login still renders it if it finds any custom texts for this
language. In that case, the login tries to render all texts on all
screens in this language using custom texts, even for texts that are not
customized.


![image](https://github.com/user-attachments/assets/1038ecac-90c9-4352-b75d-e7466a639711)

![image](https://github.com/user-attachments/assets/e4cbd0fb-a60e-41c5-a404-23e6d144de6c)

![image](https://github.com/user-attachments/assets/98d8b0b9-e082-48ae-9540-66792341fe1c)

# How the Problems Are Solved

If a custom messages language is not allowed, it is not added to the
i18n library's translations bundle. The library correctly falls back to
the instances default language.


![image](https://github.com/user-attachments/assets/fadac92e-bdea-4f8c-b6c2-2aa6476b89b3)

This library method only receives messages for allowed languages

![image](https://github.com/user-attachments/assets/33081929-d3a5-4b0f-b838-7b69f88c13bc)

# Additional Context

Reported via support request
This commit is contained in:
Elio Bischof 2024-12-20 11:31:03 +01:00 committed by GitHub
parent d9a89d9fcf
commit ab6c4331df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -64,10 +64,22 @@ func (t *Translator) SupportedLanguages() []language.Tag {
return t.allowedLanguages
}
// AddMessages adds messages to the translator for the given language tag.
// If the tag is not in the allowed languages, the messages are not added.
func (t *Translator) AddMessages(tag language.Tag, messages ...Message) error {
if len(messages) == 0 {
return nil
}
var isAllowed bool
for _, allowed := range t.allowedLanguages {
if allowed == tag {
isAllowed = true
break
}
}
if !isAllowed {
return nil
}
i18nMessages := make([]*i18n.Message, len(messages))
for i, message := range messages {
i18nMessages[i] = &i18n.Message{