KEYCLOAK-2430 Load resource bundle before bootstrapping Angular
This commit is contained in:
parent
fb07559980
commit
fd0d30fd1a
2 changed files with 39 additions and 18 deletions
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue