KEYCLOAK-2237
Offer the possibility to add own locale to login/registration dialogs
This commit is contained in:
1 parent
bdc439b4a4
commit
54abfa4859
33 files changed
+113
-18
No files matched your search
@@ -14,7 +14,7 @@ public class ServerInfoRepresentation {
|
||||
private SystemInfoRepresentation systemInfo;
|
||||
private MemoryInfoRepresentation memoryInfo;
|
||||
|
||||
private Map<String, List<String>> themes;
|
||||
private Map<String, List<ThemeInfoRepresentation>> themes;
|
||||
|
||||
private List<Map<String, String>> socialProviders;
|
||||
private List<Map<String, String>> identityProviders;
|
||||
@@ -43,11 +43,12 @@ public class ServerInfoRepresentation {
|
||||
public void setMemoryInfo(MemoryInfoRepresentation memoryInfo) {
|
||||
this.memoryInfo = memoryInfo;
|
||||
}
|
||||
public Map<String, List<String>> getThemes() {
|
||||
|
||||
public Map<String, List<ThemeInfoRepresentation>> getThemes() {
|
||||
return themes;
|
||||
}
|
||||
|
||||
public void setThemes(Map<String, List<String>> themes) {
|
||||
public void setThemes(Map<String, List<ThemeInfoRepresentation>> themes) {
|
||||
this.themes = themes;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
*/
|
||||
|
||||
package org.keycloak.representations.info;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class ThemeInfoRepresentation {
|
||||
|
||||
private String name;
|
||||
private String[] locales;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String[] getLocales() {
|
||||
return locales;
|
||||
}
|
||||
|
||||
public void setLocales(String[] locales) {
|
||||
this.locales = locales;
|
||||
}
|
||||
}
|
||||
+23
-3
@@ -1,5 +1,6 @@
|
||||
package org.keycloak.services.resources.admin.info;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -10,6 +11,7 @@ import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
||||
import org.keycloak.broker.provider.IdentityProvider;
|
||||
@@ -109,13 +111,31 @@ public class ServerInfoAdminResource {
|
||||
|
||||
private void setThemes(ServerInfoRepresentation info) {
|
||||
ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending");
|
||||
info.setThemes(new HashMap<String, List<String>>());
|
||||
info.setThemes(new HashMap<String, List<ThemeInfoRepresentation>>());
|
||||
|
||||
for (Theme.Type type : Theme.Type.values()) {
|
||||
List<String> themes = new LinkedList<String>(themeProvider.nameSet(type));
|
||||
Collections.sort(themes);
|
||||
List<String> themeNames = new LinkedList<>(themeProvider.nameSet(type));
|
||||
Collections.sort(themeNames);
|
||||
|
||||
List<ThemeInfoRepresentation> themes = new LinkedList<>();
|
||||
info.getThemes().put(type.toString().toLowerCase(), themes);
|
||||
|
||||
for (String name : themeNames) {
|
||||
try {
|
||||
Theme theme = themeProvider.getTheme(name, type);
|
||||
ThemeInfoRepresentation ti = new ThemeInfoRepresentation();
|
||||
ti.setName(name);
|
||||
|
||||
String locales = theme.getProperties().getProperty("locales");
|
||||
if (locales != null) {
|
||||
ti.setLocales(locales.replaceAll(" ", "").split(","));
|
||||
}
|
||||
|
||||
themes.add(ti);
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException("Failed to load themes", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"themes": [{
|
||||
"name" : "base",
|
||||
"types": [ "admin", "account", "login" ]
|
||||
"types": [ "admin", "account", "login", "email" ]
|
||||
}, {
|
||||
"name" : "keycloak",
|
||||
"types": [ "admin", "account", "login", "common", "email", "welcome" ]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
locales=ca,de,en,es,fr,it,pt_BR
|
||||
@@ -338,15 +338,55 @@ module.controller('RealmThemeCtrl', function($scope, Current, Realm, realm, serv
|
||||
|
||||
$scope.supportedLocalesOptions = {
|
||||
'multiple' : true,
|
||||
'simple_tags' : true,
|
||||
'tags' : ['en', 'de', 'pt-BR', 'it', 'es', 'ca']
|
||||
'simple_tags' : true
|
||||
};
|
||||
|
||||
$scope.$watch('realm.supportedLocales', function(oldVal, newVal) {
|
||||
if ($scope.realm.defaultLocale && newVal && newVal.indexOf($scope.realm.defaultLocale) == -1) {
|
||||
$scope.realm.defaultLocale = null;
|
||||
function localeForTheme(type, name) {
|
||||
name = name || 'base';
|
||||
for (var i = 0; i < serverInfo.themes[type].length; i++) {
|
||||
if (serverInfo.themes[type][i].name == name) {
|
||||
return serverInfo.themes[type][i].locales;
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
function updateSupported() {
|
||||
if ($scope.realm.internationalizationEnabled) {
|
||||
var accountLocales = localeForTheme('account', $scope.realm.loginTheme);
|
||||
var adminLocales = localeForTheme('admin', $scope.realm.loginTheme);
|
||||
var loginLocales = localeForTheme('login', $scope.realm.loginTheme);
|
||||
var emailLocales = localeForTheme('email', $scope.realm.loginTheme);
|
||||
|
||||
var supportedLocales = [];
|
||||
for (var i = 0; i < accountLocales.length; i++) {
|
||||
var l = accountLocales[i];
|
||||
if (adminLocales.indexOf(l) >= 0 && loginLocales.indexOf(l) >= 0 && emailLocales.indexOf(l) >= 0) {
|
||||
supportedLocales.push(l);
|
||||
}
|
||||
}
|
||||
|
||||
$scope.supportedLocalesOptions.tags = supportedLocales;
|
||||
|
||||
if (!$scope.realm.supportedLocales) {
|
||||
$scope.realm.supportedLocales = supportedLocales;
|
||||
} else {
|
||||
for (var i = 0; i < $scope.realm.supportedLocales.length; i++) {
|
||||
if ($scope.realm.supportedLocales.indexOf($scope.realm.supportedLocales[i]) == -1) {
|
||||
$scope.realm.supportedLocales = supportedLocales;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$scope.realm.defaultLocale || supportedLocales.indexOf($scope.realm.defaultLocale) == -1) {
|
||||
$scope.realm.defaultLocale = 'en';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$watch('realm.loginTheme', updateSupported);
|
||||
$scope.$watch('realm.accountTheme', updateSupported);
|
||||
$scope.$watch('realm.emailTheme', updateSupported);
|
||||
$scope.$watch('realm.internationalizationEnabled', updateSupported);
|
||||
});
|
||||
|
||||
module.controller('RealmCacheCtrl', function($scope, realm, RealmClearUserCache, RealmClearRealmCache, Notifications) {
|
||||
|
||||
+4
-4
@@ -9,7 +9,7 @@
|
||||
<div>
|
||||
<select class="form-control" id="loginTheme"
|
||||
ng-model="realm.loginTheme"
|
||||
ng-options="o as o for o in serverInfo.themes.login">
|
||||
ng-options="o.name as o.name for o in serverInfo.themes.login">
|
||||
<option value="" disabled selected>{{:: 'select-one' | translate}}</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -22,7 +22,7 @@
|
||||
<div>
|
||||
<select class="form-control" id="accountTheme"
|
||||
ng-model="realm.accountTheme"
|
||||
ng-options="o as o for o in serverInfo.themes.account">
|
||||
ng-options="o.name as o.name for o in serverInfo.themes.account">
|
||||
<option value="" disabled selected>{{:: 'select-one' | translate}}</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -35,7 +35,7 @@
|
||||
<div>
|
||||
<select class="form-control" id="adminTheme"
|
||||
ng-model="realm.adminTheme"
|
||||
ng-options="o as o for o in serverInfo.themes.admin">
|
||||
ng-options="o.name as o.name for o in serverInfo.themes.admin">
|
||||
<option value="" disabled selected>{{:: 'select-one' | translate}}</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -48,7 +48,7 @@
|
||||
<div>
|
||||
<select class="form-control" id="emailTheme"
|
||||
ng-model="realm.emailTheme"
|
||||
ng-options="o as o for o in serverInfo.themes.email">
|
||||
ng-options="o.name as o.name for o in serverInfo.themes.email">
|
||||
<option value="" disabled selected>{{:: 'select-one' | translate}}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
import=common/keycloak
|
||||
import=common/keycloak
|
||||
locales=ca,de,en,es,fr
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1 @@
|
||||
locales=ca,de,en,es,fr,it,pt_BR
|
||||
@@ -0,0 +1 @@
|
||||
locales=ca,de,en,es,fr,it,pt_BR
|
||||
@@ -0,0 +1 @@
|
||||
parent=base
|
||||
Reference in new issue
Block a user