Mike Cole
Mike Cole

Reputation: 14703

ASP.NET Localization Not Working for me

I know I'm doing something fundamentally wrong, but I can't quite figure it out...

I have 2 resource files in my App_GlobalResources folder: Global.resx and Global.fr-CA.resx.

I have the following label on my webform:

<asp:Label ID="Label1" runat="server" Text="<%$ Resources:Global, Test %>" />

When I run the form, it displays the value correctly from Global.resx. Now, in code-behind, I want to manually change the culture to pull from my fr-CA resx file:

Page.UICulture = "fr";
Page.Culture = "fr-CA";

However, when I re-run the app it doesn't pull the value from Global.fr-CA.resx - it still pulls from Global.resx. What am I doing wrong?

Thanks!!

Upvotes: 1

Views: 2280

Answers (1)

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262919

You should override the InitializeCulture() method of your page class and set both Page.Culture and Page.UICulture to the specific culture fr-CA:

protected override void InitializeCulture()
{
    base.InitializeCulture();
    Page.Culture = Page.UICulture = "fr-CA";
}

Upvotes: 3

Related Questions