diff --git a/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties b/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties index bb2782d3e6..6d547f7627 100644 --- a/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties +++ b/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties @@ -831,6 +831,7 @@ additional-grants=Additional Grants revoke=Revoke new-password=New Password password-confirmation=Password Confirmation +reset-password=Reset Password credentials.temporary.tooltip=If enabled user is required to change password on next login remove-totp=Remove TOTP credentials.remove-totp.tooltip=Remove one time password generator for user. diff --git a/themes/src/main/resources/theme/base/admin/resources/js/app.js b/themes/src/main/resources/theme/base/admin/resources/js/app.js index 69df83e863..ca78baccbb 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/app.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/app.js @@ -6,6 +6,8 @@ consoleBaseUrl = consoleBaseUrl + "/console"; var configUrl = consoleBaseUrl + "/config"; var auth = {}; +var resourceBundle; +var locale = 'en'; var module = angular.module('keycloak', [ 'keycloak.services', 'keycloak.loaders', 'ui.bootstrap', 'ui.select2', 'angularFileUpload', 'angularTreeview', 'pascalprecht.translate', 'ngCookies', 'ngSanitize']); var resourceRequests = 0; @@ -34,6 +36,25 @@ angular.element(document).ready(function () { req.send(); } + function loadResourceBundle(success, error) { + var req = new XMLHttpRequest(); + req.open('GET', consoleBaseUrl + '/messages.json?lang=' + locale, true); + req.setRequestHeader('Accept', 'application/json'); + + req.onreadystatechange = function () { + if (req.readyState == 4) { + if (req.status == 200) { + var data = JSON.parse(req.responseText); + success && success(data); + } else { + error && error(); + } + } + } + + req.send(); + } + function hasAnyAccess(user) { return user && user['realm_access']; } @@ -45,6 +66,10 @@ angular.element(document).ready(function () { keycloakAuth.init({ onLoad: 'login-required' }).success(function () { auth.authz = keycloakAuth; + if (auth.authz.idTokenParsed.locale) { + locale = auth.authz.idTokenParsed.locale; + } + auth.refreshPermissions = function(success, error) { whoAmI(function(data) { auth.user = data; @@ -57,17 +82,19 @@ angular.element(document).ready(function () { }); }; - auth.refreshPermissions(function() { - module.factory('Auth', function() { - return auth; - }); - var injector = angular.bootstrap(document, ["keycloak"]); + loadResourceBundle(function(data) { + resourceBundle = data; - injector.get('$translate')('consoleTitle').then(function(consoleTitle) { - document.title=consoleTitle; + auth.refreshPermissions(function () { + module.factory('Auth', function () { + return auth; + }); + var injector = angular.bootstrap(document, ["keycloak"]); + + injector.get('$translate')('consoleTitle').then(function (consoleTitle) { + document.title = consoleTitle; + }); }); - }, function() { - window.location.reload(); }); }).error(function () { window.location.reload(); @@ -99,15 +126,8 @@ module.factory('authInterceptor', function($q, Auth) { module.config(['$translateProvider', function($translateProvider) { $translateProvider.useSanitizeValueStrategy('sanitizeParameters'); - - var locale = auth.authz.idTokenParsed.locale; - if (locale !== undefined) { - $translateProvider.preferredLanguage(locale); - } else { - $translateProvider.preferredLanguage('en'); - } - - $translateProvider.useUrlLoader('messages.json'); + $translateProvider.preferredLanguage(locale); + $translateProvider.translations(locale, resourceBundle); }]); module.config([ '$routeProvider', function($routeProvider) {