views:

447

answers:

3

So I have a requirement to change the locale of a site collection at runtime.

I am deploying a .resx file into the web applications App_GlobalResources folder, then I am using:

<asp:Literal runat="server" Text="<%$Resources:MyResource,MyLocalizedStringID%>" />

to insert the right localized string.

This works fine for the default resource file but I want the locale of the site to change when the user changes the locale in Regional Settings. Even when the user changes the locale it still picks up the default resource file.

I know with ASP.Net I need to change the CurrentCulture which I have done before, but how do I do this with SharePoint? and how do I make my site collection load the correct resource file?

I could place a dropdown on the page and allow the user to select the language then change the CurrentCulture and I could also create another Site Settings entry which does the same thing.

But ideally I would like to do this with the out of the box regional settings.

Any ideas?

A: 

You can change the regional setting in the Central Admin - > Application Management - > Web Application General Settings

Kusek
+2  A: 

Yep I know that but this does not change the CurrentUICulture of the running ASP.Net thread therefore the correct .resx files do not get loaded.

I have found a solution, once you have changed the Regional Settings locale you need to add the following code to your page layout so that the correct UI culture gets set when the page loads.

<script runat="server">
    protected override void  InitializeCulture()
    {
        System.Threading.Thread.CurrentThread.CurrentUICulture = Microsoft.SharePoint.SPContext.Current.Web.Locale;
        base.InitializeCulture();
    }
</script>
Lee Dale
A: 

I've just posted a blog post on this solution entitled "Localizing a SharePoint UI using ASP.Net Resource Files"

http://leedale.wordpress.com/2009/08/05/localizing-a-sharepoint-ui-using-asp-net-resource-files/

Lee Dale