Fixes the culturerequest.interceptor so that it works in tests (and so circular deps aren't caused), internalizes ClientCulture and makes it a little less error prone.

This commit is contained in:
Shannon
2019-02-19 01:44:00 +11:00
parent 90cbd69373
commit f2ae41ada2
2 changed files with 12 additions and 6 deletions

View File

@@ -3,23 +3,29 @@
/**
* Used to set the current client culture on all requests API requests
* @param {any} $q
* @param {any} $routeParams
*/
function cultureRequestInterceptor($q, $routeParams) {
function cultureRequestInterceptor($injector) {
return {
//dealing with requests:
'request': function (config) {
if (!Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath) {
// no settings available, we're probably on the login screen
return config;
}
if (!config.url.match(RegExp(Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + "\/backoffice\/", "i"))) {
// it's not an API request, no handling
return config;
}
// it's an API request, add the current client culture as a header value
config.headers["X-UMB-CULTURE"] = $routeParams.cculture ? $routeParams.cculture : $routeParams.mculture;
var $routeParams = $injector.get("$routeParams");
if ($routeParams) {
// it's an API request, add the current client culture as a header value
config.headers["X-UMB-CULTURE"] = $routeParams.cculture ? $routeParams.cculture : $routeParams.mculture;
}
return config;
}
};