So we tried another approach ... Using an HTTP Module which interrupts the request in a very early stage - Reference this Page to see how to create and apply an HTTPModule to SharePoint - .
The trick is the new SharePoint model for changing the display language is by checking the user's language preferences ... Then adding those languages to the request header in the Accept-Language tag i.e. ar-SA,en-US or buy the language preferences the user configures in his SharePoint user profile.
English Preference Only |
Arabic then English Preference |
UPDATE: Thanks to Suleman, many people was facing some issues in this approach, He found using the PreRequestHandlerExecute event handler solves all issues
e.g context.PreRequestHandlerExecute +=context_PreRequestHandlerExecute;
Following is the code we used for achieving the above scenario by setting the language to arabic:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Threading.Tasks;
using System.Threading;
namespace MUISwitcher
{
class HTTPSwitcherModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute +=context_PreRequestHandlerExecute;
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication httpApp = sender as HttpApplication;
HttpContext context = httpApp.Context;
string httpUrl = context.Request.Url.ToString();
//TODO:Get the selected value for the current culture form the cookie i.e. ar-SA and
//set the Header and the CurrentCulture to the aquired value
var lang = context.Request.Headers["Accept-Language"];
if (!lang.Contains("ar-SA"))
context.Request.Headers["Accept-Language"] = "ar-SA," + context.Request.Headers["Accept-Language"];
var culture = new System.Globalization.CultureInfo("ar-SA");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
#endregion
}
}