Translate MVC application into another language

Joe Green 146 Reputation points
2022-08-09T17:44:36.32+00:00

I have a .net MVC c# web application in English. Now I've been asked to see if it is possible to make this application available in French. Feels like it is going to take lot of hard, tedious work. Wondering what are my options?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,270 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,279 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Sreeju Nair 11,616 Reputation points
    2022-08-09T18:04:04.93+00:00

    When you are working in multi lingual applications, you need to consider two aspects. One is the application UI such as labels, text etc that is coming from your application code. Second is the dynamic content that is coming from database. For database generated content, you need to make sure your database structure supports fields for multiple languages. For e.g. if you store title in a table, make sure you have the database schema that supports the title in other languages too.

    For the static content generated, you may use IStringLocalizerthat provides localized strings.

    Refer: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-6.0

    If you are not using ASP.Net Core MVC, refer https://blog.e-zest.com/globalization-and-localization-in-asp.net-mvc-application

    Hope this helps

    0 comments No comments

  2. Michael Taylor 48,581 Reputation points
    2022-08-09T18:11:00.893+00:00

    Tedious, yes. Assuming you want to support multiple languages and not just 1 "other" language then you have to use a localizer. You can read about the basics here. Ultimately you'll need to get all your text translated to the other language. There are plenty of companies that provide this service.

    You then need to modify your app to run through a localization service to translate any text you have to the correct language. That will be based upon the language the browser passes to you. You will need to do this for any text you show to the user including any error messages, back end messages and views. Basically all the localized data goes into resource files and the localizer pulls them out. This will have a perf issue the more strings you have and unfortunately also limits your ability to modify text.

    An alternative approach for the views might be to have the HTML localized and stored in its own file, perhaps as a component or partial view depending upon your tech. Then have your controllers select the correct, localized view. This would be faster than localizing everything on the fly and would also allow you to adjust the layout if it doesn't flow well for a particular language. For example you might be using LTR languages now but if you switch to RTL then your UI may look odd so changing the layout would be better. The downside to this approach (unless you use components heavily) would be that you'd have to potentially update multiple views if you are making changes unrelated to text.

    0 comments No comments

  3. Lan Huang-MSFT 25,716 Reputation points Microsoft Vendor
    2022-08-10T03:14:02.307+00:00

    Hi @Joe Green ,
    You can try the following 3 steps to add multilingual support to your MVC application.

    • Create resource file
    • Modify views to use resource files
    • Set the request thread culture to the user locale

    For details, you can refer to the following documents:
    https://learn.microsoft.com/en-us/previous-versions/aspnet/ms227427(v=vs.100)
    https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-and-localization
    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-6.0
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  4. Joe Green 146 Reputation points
    2022-08-10T17:03:19.937+00:00

    I have both static and content that is coming from database. To test, this is what I wrote but I don't see the name in French. What am I doing wrong?
    CultureInfo ci = new CultureInfo("fr-FR");
    obj.name = obj.name.ToString(ci);