9

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

ganesshkumar
  • 1,317
  • 1
  • 16
  • 35
Satinder singh
  • 10,100
  • 16
  • 60
  • 102
  • one way of doing it would be to have fully translated pages with just different names e.g AboutPage.en and AboutPage.fr, then depending on which lauguage is picked you just display the page with the corresponding ending to that language. – RhysW May 10 '12 at 12:02
  • 1
    some good links about the topic: http://stackoverflow.com/questions/160335/how-do-you-localize-a-database-driven-website http://stackoverflow.com/questions/7783112/localization-globalization-should-be-database-driven-or-resource-web-frameworka – Christopher Rathermel May 10 '12 at 12:04
  • 1
    Take a look at this thread: http://stackoverflow.com/questions/470366/multiple-languagesenglish-french-on-asp-net-page – Felipe Oriani May 10 '12 at 12:04
  • 1
    read this: http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx – animaonline May 10 '12 at 12:04
  • @RhysW: thnx but have to translate all the pages some dynamic content too – Satinder singh May 10 '12 at 12:08
  • @ChristopherRathermel: thnx but still not clear which is good? for static can use resource file and for dynamic have to database ? – Satinder singh May 10 '12 at 12:16
  • 1
    @satindersingh Yes that sounds reasonable but it will really depend on the details of your project. For example if you have to do a lot of image changes and thus CSS it might make sense to put it all in the DB even though at first thought it sounds like overkill. I would also take a look at 3rd party tools like ~CodeBlend mentioned. – Christopher Rathermel May 10 '12 at 12:23
  • Whatever you try to do is going to result in all the pages having to be translated anyway, its just a case of finding the one which suits you and the way that you find easiest to understand and implement. There is certainly no one size fits all solution – RhysW May 10 '12 at 12:26
  • @ChristopherRathermel: Thank you sir, as per my requiremnt i just need to change the text content of label,messages,textbox, overvall images were same.Am thing to use localization resource file it seem good choice for my application – Satinder singh May 10 '12 at 12:39

3 Answers3

7

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?

Alex
  • 192
  • 3
  • 13
3

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");
            }
        }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Satinder singh
  • 10,100
  • 16
  • 60
  • 102
-1

For dynamic content a thrid party plugin or a adding something such as Google translate would do it;

http://translate.google.com/translate_tools

FYI; Google Chrome has built in auto-translate and Chrome's popularity is growing fast... wow imagine a web where regardless of language you have access to ALL content this isn't that but I though I would share my thoughts

Paul C
  • 4,687
  • 5
  • 39
  • 55
  • 1
    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 – Satinder singh May 10 '12 at 12:24
  • 2
    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... – Falanwe May 10 '12 at 12:27
  • They are valid points based on more experience than mine but what about getting a general idea of the dynamic content displayed? – Paul C May 10 '12 at 12:29
  • 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](http://translate.google.fr/translate?hl=fr&sl=fr&tl=en&u=http%3A%2F%2Fwww.lemonde.fr%2F) – Falanwe May 10 '12 at 12:34
  • @Falanwe : yes it translated the content, but its looks odd and not sure that translated content is perfect, even effect UI – Satinder singh May 10 '12 at 12:47
  • @satindersingh : it looks odd indeed. And that's precisely my point ;) – Falanwe May 10 '12 at 13:37