add i18n for emails

This commit is contained in:
Michael Gerber
2015-02-24 19:31:06 +01:00
parent 1575bea45d
commit b6280e90bf
16 changed files with 51 additions and 4 deletions

View File

@@ -19,6 +19,10 @@ public class LocaleHelper {
private final static Logger LOGGER = Logger.getLogger(LocaleHelper.class);
public static Locale getLocale(RealmModel realm, UserModel user) {
return getLocale(realm, user, null, null);
}
public static Locale getLocale(RealmModel realm, UserModel user, UriInfo uriInfo, HttpHeaders httpHeaders) {
if(!realm.isInternationalizationEnabled()){
return null;

View File

@@ -0,0 +1,5 @@
Someone has created a Keycloak account with this email address. If this was you, click the link below to verify your email address:
${link}
This link will expire within ${linkExpiration} minutes.
If you didn't create this account, just ignore this message.

View File

@@ -0,0 +1,5 @@
Someone has created a Keycloak account with this email address. If this was you, click the link below to verify your email address:
${link}
This link will expire within ${linkExpiration} minutes.
If you didn't create this account, just ignore this message.

View File

@@ -0,0 +1 @@
A failed login attempt was dettected to your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1 @@
A failed login attempt was dettected to your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1 @@
TOTP was removed from your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1 @@
TOTP was removed from your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1 @@
Your password was changed on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1 @@
Your password was changed on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1 @@
TOTP was updated for your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1 @@
TOTP was updated for your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin.

View File

@@ -0,0 +1,2 @@
emailVerificationSubject=Verify email
passwordResetSubject=Passwort zurücksetzen

View File

@@ -0,0 +1,2 @@
emailVerificationSubject=Verify email
passwordResetSubject=Reset password

View File

@@ -0,0 +1,5 @@
Jemand hat angeforder ihr Passwort zurück zu setzen:
${link}
This link will expire within ${linkExpiration} minutes.
If you don't want to reset your password, just ignore this message and nothing will be changed.

View File

@@ -0,0 +1,5 @@
Someone just requested to change your Keycloak account's password. If this was you, click on the link below to set a new password:
${link}
This link will expire within ${linkExpiration} minutes.
If you don't want to reset your password, just ignore this message and nothing will be changed.

View File

@@ -6,6 +6,7 @@ import org.keycloak.email.EmailProvider;
import org.keycloak.email.freemarker.beans.EventBean;
import org.keycloak.events.Event;
import org.keycloak.freemarker.FreeMarkerUtil;
import org.keycloak.freemarker.LocaleHelper;
import org.keycloak.freemarker.Theme;
import org.keycloak.freemarker.ThemeProvider;
import org.keycloak.models.KeycloakSession;
@@ -53,7 +54,7 @@ public class FreeMarkerEmailProvider implements EmailProvider {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("event", new EventBean(event));
send("passwordResetSubject", "event-" + event.getType().toString().toLowerCase() + ".ftl", attributes);
send("passwordResetSubject", getTemplate("event-" + event.getType().toString().toLowerCase()), attributes);
}
@Override
@@ -62,7 +63,7 @@ public class FreeMarkerEmailProvider implements EmailProvider {
attributes.put("link", link);
attributes.put("linkExpiration", expirationInMinutes);
send("passwordResetSubject", "password-reset.ftl", attributes);
send("passwordResetSubject", getTemplate("password-reset"), attributes);
}
@Override
@@ -71,7 +72,7 @@ public class FreeMarkerEmailProvider implements EmailProvider {
attributes.put("link", link);
attributes.put("linkExpiration", expirationInMinutes);
send("emailVerificationSubject", "email-verification.ftl", attributes);
send("emailVerificationSubject", getTemplate("email-verification"), attributes);
}
private void send(String subjectKey, String template, Map<String, Object> attributes) throws EmailException {
@@ -79,7 +80,7 @@ public class FreeMarkerEmailProvider implements EmailProvider {
ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending");
Theme theme = themeProvider.getTheme(realm.getEmailTheme(), Theme.Type.EMAIL);
String subject = theme.getMessages(Locale.GERMAN).getProperty(subjectKey);
String subject = theme.getMessages(LocaleHelper.getLocale(realm,user)).getProperty(subjectKey);
String body = freeMarker.processTemplate(attributes, template, theme);
send(subject, body);
@@ -147,4 +148,14 @@ public class FreeMarkerEmailProvider implements EmailProvider {
public void close() {
}
private String getTemplate(String name){
StringBuilder sb = new StringBuilder(name);
Locale locale = LocaleHelper.getLocale(realm, user);
if(locale!=null){
sb.append("_").append(locale.toString());
}
sb.append(".ftl");
return sb.toString();
}
}