How to create a multilingual website

I am going to start a project that should support a number of European languages. All static materials on this site must be translatable between these languages. I heard about satellite assemblies and heard that they are used for multilingual sites in .NET, but that was a long time ago. Is this current practice in .NET? I am using ASP.NET MVC.

+4
source share
2 answers

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

ASP.NET MVC Localization: Creating Resource Files and Localized Views Using Custom Templates

+4
source

Without the satellite part, you can add the App_GlobalResources folder to the project and add *.resx files for each language. You can have one resource file for the entire project or one for the ASP.NET MVC Area or, as you see fit, but you do not need more than 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 views and PartialViews (e.g. MyView.cshtml).

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

Additionally:

Resources can be added as a reference and use custom namespaces.

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

mToolNamespace: MyNamespaceHere

Then they will be available through.

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

This is a common way to use (regular / related) resources in ASP.NET MVC. If you use Add As Link, you can have one physical copy in a separate project.

Satellite

Some information about satellite meetings:

MSDN: Building Satellite Assemblies

MSDN Blog: Introduction to Satellite Assemblies

+4
source

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


All Articles