Middleware to set language based on a number of conditions