﻿"use strict";

// Locale Interceptor service "intercepts" all requests to server and changes the default header, we could try putting in in main, but the problem
// is that once the app initializes we won't be able to reset the header
app.factory("localeInterceptorService", ["$injector", function ($injector) {

    var localeInterceptorServiceFactory = {};
    var $http;

    var _request = function (config) {
    	$http = $http || $injector.get('$http');

		// Determine current locale		
    	var urlPath = window.location;
    	var locale = urlPath.pathname.replace("/", "");

		// Change the default Accept-Language header so that the localizer will pick up the current locale from angular
    	$http.defaults.headers.common["Accept-Language"] = locale;

        return config;
    }

    localeInterceptorServiceFactory.request = _request;
    return localeInterceptorServiceFactory;
}]);
