开发者

How to use various culture specific resource files on ASP.NET

开发者 https://www.devze.com 2023-01-20 16:49 出处:网络
I have a website which currently uses EN-US and I also have resource fil开发者_C百科e for french. what code should I need to write to make the application use the french version of the resource file.

I have a website which currently uses EN-US and I also have resource fil开发者_C百科e for french. what code should I need to write to make the application use the french version of the resource file.

The site is a commerce server and share point site that uses .NET

Any code examples would be great.


You have a couple of options. Option one is at the application level. You could do this in the system.web section of the web.config:

<globalization culture="fr-FR" uiCulture="fr-FR" />

Another option is on the page:

<%@Page Culture="fr-FR" Language="C#" %>

or by thread:

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");

See http://support.microsoft.com/kb/306162 for more info.


I consider the main resource file's feature as the ability to retrieve localized strings according to the culture specified in the url through code such as:

localresourcestring = (String)GetLocalResourceObject("username")  
//will retrieve the localized string for username from your resx (according to the resx's name)!  

Here's a great place to start, including a Walkthrough and such..


I would set the language at the Application_BeginRequest() global event in the Global.asax file:

protected void Application_BeginRequest()
{
    // Get the CultureInfo object that contains the French language specification
    CultureInfo frenchCulture = CultureInfo.CreateSpecificCulture("fr-FR");

    // Set the language the current thread uses (per-user)
    Thread.CurrentThread.CurrentCulture = frenchCulture;
    Thread.CurrentThread.CurrentUICulture = frenchCulture;
}

Hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消