Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am having some problems in changing the language in SharePoint programmatically. I have two language packs installed on my server (Norwegian and English). If I change the language manually through the GUI then its changing but when I do it programmatically it is setting the Lcid of the language in the background as default language but not translating the content. I am checking lcid on the page load. It is the selected one. I have also updated the site after changing locale ID.

Here is the code. Please tell me where I am missing something or something else.

ImageButton btn = sender as ImageButton;
            SPWeb spweb = SPContext.Current.Web;
            spweb.AllowUnsafeUpdates = true;
            int LCID = Convert.ToInt32(btn.ID);
            CultureInfo culture = new CultureInfo(LCID);
            spweb.Locale = culture;
            spweb.Update();
            string url = btn.ImageUrl;
            string btnId = btn.ID;
            imgBtnDefault.ImageUrl = url;
            imgBtnDefault.Height = 18;
            imgBtnDefault.Width = 25;
            spweb.AllowUnsafeUpdates = false;
share|improve this question

2 Answers 2

Language in SharePoint that is Displayed to the user is based on a the HTTP Request Header ["Accepted Languages"] or the SharePoint language cookie if the user selects a specific language in the SharePoint language selection menu. This menu is only shown when activating one or more alternative languages on a site collection.

If you want to change language in the background for a specific part of the code then you will need to set the current running threads to the language you want to use.

System.Threading.Thread.CurrentThread.CurrentUICulture.Name="no" 
System.Threading.Thread.CurrentThread.CurrentCulture.Name="no"

By default Ajax requests for example, will fall back to the site collections default language, the language you selected as default when creating the site collection. On normal page requests it will use the users selected language(cookie or Accepted Languages)

And as mentioned before SPWeb.Local only has a public Get not a Set.

share|improve this answer
spweb.Locale = culture;

This property is read only, you can't modify site's culture using object model.

As far as I know Site's languages are set-up on web application level not site collection level, You can change them by making changes to Web Application's web.config (culture) attribute.

Here's a tutorial on how you can change web application's culture using DB but you can do it by modifying web.onfig as well.

Hope it helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.