V8: Remember editor language between sessions (#4035)

This commit is contained in:
Kenn Jacobsen
2019-01-13 12:42:42 +01:00
committed by Sebastiaan Janssen
parent 1c401b9589
commit 291d58900f

View File

@@ -9,7 +9,7 @@
*
* @param {navigationService} navigationService A reference to the navigationService
*/
function NavigationController($scope, $rootScope, $location, $log, $q, $routeParams, $timeout, treeService, appState, navigationService, keyboardService, historyService, eventsService, angularHelper, languageResource, contentResource) {
function NavigationController($scope, $rootScope, $location, $log, $q, $routeParams, $timeout, $cookies, treeService, appState, navigationService, keyboardService, historyService, eventsService, angularHelper, languageResource, contentResource) {
//this is used to trigger the tree to start loading once everything is ready
var treeInitPromise = $q.defer();
@@ -344,9 +344,6 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
$scope.languages = languages;
if ($scope.languages.length > 1) {
var defaultLang = _.find($scope.languages, function (l) {
return l.isDefault;
});
//if there's already one set, check if it exists
var currCulture = null;
var mainCulture = $location.search().mculture;
@@ -356,7 +353,18 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
});
}
if (!currCulture) {
$location.search("mculture", defaultLang ? defaultLang.culture : null);
// no culture in the request, let's look for one in the cookie that's set when changing language
var defaultCulture = $cookies.get("UMB_MCULTURE");
if (!defaultCulture) {
// no luck either, look for the default language
var defaultLang = _.find($scope.languages, function (l) {
return l.isDefault;
});
if (defaultLang) {
defaultCulture = defaultLang.culture;
}
}
$location.search("mculture", defaultCulture ? defaultCulture : null);
}
}
@@ -391,6 +399,9 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
$scope.selectLanguage = function (language) {
$location.search("mculture", language.culture);
// add the selected culture to a cookie so the user will log back into the same culture later on (cookie max age is one year = 31536000 seconds)
// NOTE: $cookies doesn't support max-age, so we need to go the good ol' JS way about setting the cookie
document.cookie = "UMB_MCULTURE=" +language.culture + ";path=/;max-age=31536000;";
// close the language selector
$scope.page.languageSelectorIsOpen = false;