Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a multi-lingual site

I am about to start on a project which must support a number of European languages. All static content on this site must be translatable between these languages. I have heard of satellite assemblies and have heard that they are used for multi-language sites in .NET but this was a long time ago. Is this still current practice in .NET? I'm using ASP.NET MVC.

like image 848
Sachin Kainth Avatar asked Feb 18 '23 09:02

Sachin Kainth


2 Answers

If you're using ASP.NET MVC, one option would be to use a different resource for each view. I wrote an article about it, maybe it can be of help:

ASP.NET MVC Localization: Generate resource files and localized views using custom templates

like image 97
Rui Jarimba Avatar answered Feb 27 '23 05:02

Rui Jarimba


Without the satellite part, you can add a App_GlobalResources folder to the project and add *.resx files for each language. You can have one resource file for the whole project, or one per ASP.NET MVC Area or however you see fit, but you don't need to have more then 1.

App_GlobalResources

MyResources.resx        (Neutral / Default language translated texts)
MyResources.en-GB.resx
MyResources.de-DE.resx

In MyResources.resx

Name    Value
TextID  Some text which will be localized to the end user.

In Global.asax.cs (Application_PreRequestHandlerExecute)

// Set it according to cookies/Session etc.
System.Threading.Thread.CurrentThread.CurrentUICulture = "de-DE"; 
System.Threading.Thread.CurrentThread.CurrentCulture = "de-DE";

Then in the Views and PartialViews (e.g. MyView.cshtml).

<span>@Resources.MyResources.TextID</span>

Optional:

The Resources can be added as a link, and use custom namespaces.

BuildAction:           Embedded Resource
CopyToOutputDirectory: Copy always
CustomTool:            PublicResXFileCodeGenerator
CustomToolNamespace:   MyNamespaceHere

mToolNamespace: MyNamespaceHere

Then they would be accessible via.

<span>@MyNamespaceHere.MyResources.TextID</span>

This is a general way to use (normal / linked) resources in ASP.NET MVC. If you use "Add as link" you can have one physical copy in a separate project.

Satellite:

Some info on satellite assemblies:

MSDN: Creating Satellite Assemblies

A MSDN Blog: Introduction to Satellite Assemblies

like image 31
lko Avatar answered Feb 27 '23 05:02

lko