Best way to make website for multiple languages

34,282

Solution 1

Sample code i have done using resource file add global.asax

 void Application_BeginRequest(Object sender, EventArgs e)
        {
            // Code that runs on application startup
            HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
            if (cookie != null && cookie.Value != null)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
            }
        }

Solution 2

Resx:

http://msdn.microsoft.com/en-us/library/ms227427.aspx

http://dreamdotnet.blogspot.com/2007/01/tutorial-translating-aspnet-web.html

You can use resx files for multiple languages and use the ResXResourceWrite to update them (if you want users to be able to update the files: http://msdn.microsoft.com/en-us/library/system.resources.resxresourcewriter.aspx)

This solution is only good for static content. If you want to be able to translate content from the database (for example if you have products stored in your database, and you want that the description of the product to be multilingual too). In this case you'll need to change you DB Scheme in order to support multilingual content.

PS you can use GetLocalResourceObject("key") in order to retrieve values without using web controls.

If you're using MVC, see the following question: How to localize ASP.NET MVC application?

Share:
34,282
Satinder singh
Author by

Satinder singh

I am a Full Stack Developer have a passion to create, solve, and deploy software applications. I have a great passion to learn new things. ForEach(minute in MyLife) { myExperience ++; } Blog: Codepedia Video: Subscribe Youtube Channel

Updated on July 09, 2022

Comments

  • Satinder singh
    Satinder singh almost 2 years

    I have made a website using(Asp.net, c#) and its content in English. Now i have a requirement to make this website in such a way that is support multiple languages ie (German,French). Lable/Textbox/ string all values will display respective selected languages While searching i came to know there are some ways like

    • Using localization
    • Use resource file.
    • Database(every thing is saved in database for different language).

    frankly speaking I am not agree with 3rd option.

    I want to know which is the best way to go or is there any other better way?

    Note:Current Website was built using .NET framework 4.0/ vs 2010.

    Thanks

  • Satinder singh
    Satinder singh about 12 years
    Using third party control is not a good way. As a am making a product so using google translator is bad choice coz using it will change the whole UI, pop up etc
  • Falanwe
    Falanwe about 12 years
    Have you ever tried this kind of automatic translation? I assure you that a site automatically translated does not support multiple language: the results from English to French are atrocious (an exemple I know well) and I would be surprised if it were different for other languages. Automatic translation helps a user understand the general idea of a site, but the result is pretty painful...
  • Coops
    Coops about 12 years
    They are valid points based on more experience than mine but what about getting a general idea of the dynamic content displayed?
  • Falanwe
    Falanwe about 12 years
    To have an idea of what I'm talking about, have a look at the Google translate result for one of the most prominent French newspaper site
  • Satinder singh
    Satinder singh about 12 years
    @Falanwe : yes it translated the content, but its looks odd and not sure that translated content is perfect, even effect UI
  • Falanwe
    Falanwe about 12 years
    @satindersingh : it looks odd indeed. And that's precisely my point ;)
  • Satinder singh
    Satinder singh almost 12 years
    thanks, i have done by using three .resx file( .En, .De, .Fr ) under App_globalization folder , and its work fine fine
  • Javid
    Javid about 5 years
    Does it have any security concerns?