How to use various resource files of a certain culture in ASP.NET

I have a website that currently uses EN-US, and I also have a resource file for French. What code do I need to write so that the application uses the French version of the resource file.

A site is a commerce server and a shared site that uses .NET.

Any code examples would be great.

+3
source share
3 answers

You have several options. Option one is at the application level. You can do this in the system.web section of the web.config file:

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

Another option is on the page:

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

or downstream:

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

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

+2

, URL-, , :

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

, ..

+1

I would set the language in the global event Application_BeginRequest()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 this helps.

+1
source

Source: https://habr.com/ru/post/1770368/


All Articles