messages refactoring

This commit is contained in:
Michael Gerber
2015-03-04 15:47:44 +01:00
parent cd3db1d1ce
commit 715583fa5f
16 changed files with 182 additions and 24 deletions

View File

@@ -6,6 +6,7 @@ import org.keycloak.account.AccountProvider;
import org.keycloak.account.freemarker.model.*;
import org.keycloak.events.Event;
import org.keycloak.freemarker.*;
import org.keycloak.freemarker.beans.TextFormatterBean;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
@@ -87,6 +88,7 @@ public class FreeMarkerAccountProvider implements AccountProvider {
Locale locale = LocaleHelper.getLocale(realm, user, uriInfo, headers);
if(locale != null){
attributes.put("locale", locale);
attributes.put("formatter", new TextFormatterBean(locale));
}
Properties messages;
try {

View File

@@ -0,0 +1,19 @@
package org.keycloak.freemarker.beans;
import java.text.MessageFormat;
import java.util.Locale;
/**
* @author <a href="mailto:gerbermichi@me.com">Michael Gerber</a>
*/
public class TextFormatterBean {
private Locale locale;
public TextFormatterBean(Locale locale) {
this.locale = locale;
}
public String format(String pattern, Object ... parameters){
return new MessageFormat(pattern.replace("'","''"),locale).format(parameters);
}
}

View File

@@ -1 +1 @@
${rb.emailVerificationBody?replace("{0}",link)?replace("{1}",linkExpiration)}
${formatter.format(rb.emailVerificationBody,link, linkExpiration)}

View File

@@ -1 +1 @@
${rb.eventLoginErrorBody?replace("{0}",event.date?datetime)?replace("{1}",event.ipAddress)}
${formatter.format(rb.eventLoginErrorBody,event.date,event.ipAddress)}

View File

@@ -1 +1 @@
${rb.eventRemoveTotpBody?replace("{0}",event.date?datetime)?replace("{1}",event.ipAddress)}
${formatter.format(rb.eventRemoveTotpBody,event.date, event.ipAddress)}

View File

@@ -1 +1 @@
${rb.eventUpdatePasswordBody?replace("{0}",event.date?datetime)?replace("{1}",event.ipAddress)}
${formatter.format(rb.eventUpdatePasswordBody,event.date, event.ipAddress)}

View File

@@ -1 +1 @@
${rb.eventUpdateTotpBody?replace("{0}",event.date?datetime)?replace("{1}",event.ipAddress)}
${formatter.format(rb.eventUpdateTotpBody,event.date, event.ipAddress)}

View File

@@ -2,11 +2,11 @@ emailVerificationSubject=E-Mail verifizieren
passwordResetSubject=Passwort zurückzusetzen
passwordResetBody=Jemand hat angeforder Ihr Keycloak Passwort zurückzusetzen. Falls das Sie waren, dann klicken Sie auf den folgenden Link um das Passwort zurückzusetzen.\n\n{0}\n\nDieser Link wird in {1} Minuten ablaufen.\n\nFalls Sie das Passwort nicht zurücksetzen möchten, dann können Sie diese E-Mail ignorieren.
emailVerificationBody=Jemand hat ein Keycloak Konto mit dieser E-Mail Adresse erstellt. Fall das Sie waren, dann klicken Sie auf den Link um die E-Mail Adresse zu verifizieren.\n\n{0}\n\nDieser Link wird in {1} Minuten ablaufen.\n\nFalls Sie dieses Konto nicht erstellt haben, dann können sie diese Nachricht ignorieren.
eventLoginErrorSubject=Login error
eventLoginErrorBody=A failed login attempt was dettected to your account on {0} from {1}. If this was not you, please contact an admin.
eventRemoveTotpSubject=Remove TOTP
eventRemoveTotpBody=TOTP was removed from your account on {0} from {1}. If this was not you, please contact an admin.
eventUpdatePasswordSubject=Update password
eventUpdatePasswordBody=Your password was changed on {0} from {1}. If this was not you, please contact an admin.
eventUpdateTotpSubject=Update TOTP
eventUpdateTotpBody=TOTP was updated for your account on {0} from {1}. If this was not you, please contact an admin.
eventLoginErrorSubject=Fehlgeschlagene Anmeldung
eventLoginErrorBody=Jemand hat um {0} von {1} versucht sich mit ihrem Konto anzumelden. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.
eventRemoveTotpSubject=TOTP Entfernt
eventRemoveTotpBody=TOTP wurde von ihrem Konto am {0} von {1} entfernt. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.
eventUpdatePasswordSubject=Passwort Aktualisiert
eventUpdatePasswordBody=Ihr Passwort wurde am {0} von {1} geändert. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.
eventUpdateTotpSubject=TOTP Aktualisiert
eventUpdateTotpBody=TOTP wurde am {0} von {1} geändert. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.

View File

@@ -1 +1 @@
${rb.passwordResetBody?replace("{0}",link)?replace("{1}",linkExpiration)}
${formatter.format(rb.passwordResetBody,link, linkExpiration)}

View File

@@ -4,7 +4,7 @@
<#if section = "title">
${rb.oauthGrantTitle}
<#elseif section = "header">
${rb.oauthGrantTitleHtml?replace("{0}", (realm.name!''))?replace("{0}", (client.clientId!''))}
${formatter.format(rb.oauthGrantTitleHtml,(realm.name!''), (client.clientId!''))}
<#elseif section = "form">
<div id="kc-oauth" class="content-area">
<h3>${rb.oauthGrantRequest}</h3>

View File

@@ -1,9 +1,9 @@
<#import "template.ftl" as layout>
<@layout.registrationLayout; section>
<#if section = "title">
${rb.loginTitle?replace("{0}",realm.name)}
${formatter.format(rb.loginTitle,realm.name)}
<#elseif section = "header">
${rb.loginTitle?replace("{0}", "<strong>" + realm.name + "<s/trong>")}
${formatter.format(rb.loginTitleHtml,realm.name)}
<#elseif section = "form">
<form id="kc-totp-login-form" class="${properties.kcFormClass!}" action="${url.loginAction}" method="post">
<input id="username" name="username" value="${login.username!''}" type="hidden" />

View File

@@ -2,15 +2,15 @@
<@layout.registrationLayout displayInfo=social.displayInfo; section>
<#if section = "title">
<#if client.application>
${rb.loginTitle?replace("{0}",(realm.name!''))}
${formatter.format(rb.loginTitle,(realm.name!''))}
<#elseif client.oauthClient>
${rb.loginOauthTitle?replace("{0}",(realm.name!''))}
${formatter.format(rb.loginOauthTitle,(realm.name!''))}
</#if>
<#elseif section = "header">
<#if client.application>
${rb.loginTitle?replace("{0}", (realm.name!''))}
${formatter.format(rb.loginTitleHtml,(realm.name!''))}
<#elseif client.oauthClient>
${rb.loginOauthTitleHtml?replace("{0}", (realm.name!''))?replace("{0}", (client.clientId!''))}
${formatter.format(rb.loginOauthTitleHtml,(realm.name!''), (client.clientId!''))}
</#if>
<#elseif section = "form">
<#if realm.password>

View File

@@ -0,0 +1,134 @@
doLogIn=Log in
doRegister=Register
doCancel=Cancel
doSubmit=Submit
doYes=Yes
doNo=No
doForgotPassword=Forgot Password?
doClickHere=Click here
registerWithTitle=Register with {0}
registerWithTitleHtml=Register with <strong>{0}</strong>
loginTitle=Log in to {0}
loginTitleHtml=Log in to <strong>{0}</strong>
loginOauthTitle=Temporary access for {0}
loginOauthTitleHtml=Temporary access for <strong>{0}<strong> requested by <strong>{1}</strong>.
loginTotpTitle=Mobile Authenticator Setup
loginProfileTitle=Update Account Information
oauthGrantTitle=OAuth Grant
oauthGrantTitleHtml=Temporary access for <strong>{0}</strong> requested by <strong>{1}</strong>.
errorTitle=We're sorry...
errorTitleHtml=We're <strong>sorry</strong> ...
emailVerifyTitle=Email verification
emailForgotTitle=Forgot Your Password?
updatePasswordTitle=Update password
noAccount=New user?
username=Username
usernameOrEmail=Username or email
firstName=First name
fullName=Full name
lastName=Last name
email=Email
password=Password
passwordConfirm=Confirm password
passwordNew=New Password
passwordNewConfirm=New Password confirmation
rememberMe=Remember me
authenticatorCode=One-time code
loginTotpStep1=Install <a href="https://fedorahosted.org/freeotp/" target="_blank">FreeOTP</a> or <a href="http://code.google.com/p/google-authenticator/" target="_blank">Google Authenticator</a> on your mobile
loginTotpStep2=Open the application and scan the barcode or enter the key
loginTotpStep3=Enter the one-time code provided by the application and click Submit to finish the setup
loginTotpOneTime=One-time code
oauthGrantRequest=Do you grant these access privileges?
emailVerifyInstruction1=An email with instructions to verify your email address has been sent to you.
emailVerifyInstruction2=Haven't received a verification code in your email?
emailVerifyInstruction3=to re-send the email.
backToLogin=&laquo; Back to Login
emailInstruction=Enter your username or email address and we will send you instructions on how to create a new password.
invalidUserMessage=Invalid username or password.
invalidEmailMessage=Invalid email address.
accountDisabledMessage=Account is disabled, contact admin.
accountTemporarilyDisabledMessage=Account is temporarily disabled, contact admin or try again later.
expiredCodeMessage=Login timeout. Please login again.
missingFirstNameMessage=Please specify first name.
missingLastNameMessage=Please specify last name.
missingEmailMessage=Please specify email.
missingUsernameMessage=Please specify username.
missingPasswordMessage=Please specify password.
missingTotpMessage=Please specify authenticator code.
notMatchPasswordMessage=Passwords don't match.
invalidPasswordExistingMessage=Invalid existing password.
invalidPasswordConfirmMessage=Password confirmation doesn't match.
invalidTotpMessage=Invalid authenticator code.
usernameExistsMessage=Username already exists.
emailExistsMessage=Email already exists.
federatedIdentityEmailExistsMessage=User with email already exists. Please login to account management to link the account.
federatedIdentityUsernameExistsMessage=User with username already exists. Please login to account management to link the account.
configureTotpMessage=You need to set up Mobile Authenticator to activate your account.
updateProfileMessage=You need to update your user profile to activate your account.
updatePasswordMessage=You need to change your password to activate your account.
verifyEmailMessage=You need to verify your email address to activate your account.
emailSentMessage=You should receive an email shortly with further instructions.
emailSendErrorMessage=Failed to send email, please try again later
accountUpdatedMessage=Your account has been updated
accountPasswordUpdatedMessage=Your password has been updated
noAccessMessage=No access
invalidPasswordMinLengthMessage=Invalid password: minimum length {0}
invalidPasswordMinDigitsMessage=Invalid password: must contain at least {0} numerical digits
invalidPasswordMinLowerCaseCharsMessage=Invalid password: must contain at least {0} lower case characters
invalidPasswordMinUpperCaseCharsMessage=Invalid password: must contain at least {0} upper case characters
invalidPasswordMinSpecialCharsMessage=Invalid password: must contain at least {0} special characters
failedToProcessResponseMessage=Failed to process response
httpsRequiredMessage=HTTPS required
realmNotEnabledMessage=Realm not enabled
invalidRequestMessage=Invalid Request
unknownLoginRequesterMessage=Unknown login requester
loginRequesterNotEnabledMessage=Login requester not enabled
bearerOnlyMessage=Bearer-only applications are not allowed to initiate browser login
directGrantsOnlyMessage=Direct-grants-only clients are not allowed to initiate browser login
invalidRedirectUriMessage=Invalid redirect uri
unsupportedNameIdFormatMessage=Unsupported NameIDFormat
invlidRequesterMessage=Invalid requester
registrationNotAllowedMessage=Registration not allowed
permissionNotApprovedMessage=Permission not approved.
noRelayStateInResponseMessage=No relay state in response from identity provider [{0}].
identityProviderAlreadyLinkedMessage=The identity returned by the identity provider [{0}] is already linked to another user.
insufficientPermissionMessage=Insufficient permissions to link identities.
couldNotProceedWithAuthenticationRequestMessage=Could not proceed with authentication request to identity provider.
couldNotObtainTokenMessage=Could not obtain token from identity provider [{0}].
unexpectedErrorRetrievingTokenMessage=Unexpected error when retrieving token from identity provider [{0}].
unexpectedErrorHandlingResponseMessage=Unexpected error when handling response from identity provider [{0}].
identityProviderAuthenticationFailedMessage=Authentication failed. Could not authenticate with identity provider [{0}].
couldNotSendAuthenticationRequestMessage=Could not send authentication request to identity provider [{0}].
unexpectedErrorHandlingRequestMessage=Unexpected error when handling authentication request to identity provider [{0}].
invalidAccessCodeMessage=Invalid access code.
sessionNotActiveMessage=Session not active.
unknownCodeMessage=Unknown code, please login again through your application.
invalidCodeMessage=Invalid code, please login again through your application.
identityProviderUnexpectedErrorMessage=Unexpected error when authenticating with identity provider
identityProviderNotFoundMessage=Could not find an identity provider with the identifier [{0}].
realmSupportsNoCredentialsMessage=Realm [{0}] does not support any credential type.
identityProviderNotUniqueMessage=Realm [{0}] supports multiple identity providers. Could not determine which identity provider should be used to authenticate with.
locale_de=German
locale_en=English
poweredByKeycloak=Powered by Keycloak

View File

@@ -1,10 +1,9 @@
<#import "template.ftl" as layout>
<@layout.registrationLayout; section>
<#if section = "title">
${rb.registerWithTitle} ${realm.name}
${rb.loginTitle?replace("{0}",(realm.name!''))}
${formatter.format(rb.registerWithTitle,(realm.name!''))}
<#elseif section = "header">
${rb.registerWithTitle?replace("{0}", ((realm.name!''))}
${formatter.format(rb.registerWithTitleHtml,(realm.name!''))}
<#elseif section = "form">
<form id="kc-register-form" class="${properties.kcFormClass!}" action="${url.registrationAction}" method="post">
<div class="${properties.kcFormGroupClass!}">

View File

@@ -10,6 +10,7 @@ import org.keycloak.freemarker.FreeMarkerUtil;
import org.keycloak.freemarker.LocaleHelper;
import org.keycloak.freemarker.Theme;
import org.keycloak.freemarker.ThemeProvider;
import org.keycloak.freemarker.beans.TextFormatterBean;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
@@ -84,6 +85,7 @@ public class FreeMarkerEmailProvider implements EmailProvider {
attributes.put("locale", locale);
Properties rb = theme.getMessages(locale);
attributes.put("rb", rb);
attributes.put("formatter", new TextFormatterBean(locale));
String subject = rb.getProperty(subjectKey);
String body = freeMarker.processTemplate(attributes, template, theme);

View File

@@ -6,6 +6,7 @@ import org.keycloak.OAuth2Constants;
import org.keycloak.email.EmailException;
import org.keycloak.email.EmailProvider;
import org.keycloak.freemarker.*;
import org.keycloak.freemarker.beans.TextFormatterBean;
import org.keycloak.login.LoginFormsPages;
import org.keycloak.login.LoginFormsProvider;
import org.keycloak.login.freemarker.model.ClientBean;
@@ -174,6 +175,7 @@ import java.util.concurrent.TimeUnit;
Locale locale = LocaleHelper.getLocale(realm, user, uriInfo, httpHeaders);
if(locale != null){
attributes.put("locale", locale);
attributes.put("formatter", new TextFormatterBean(locale));
}
try {
messages = theme.getMessages(locale);