Best practices for a multilingual site in different subdomains

I want to create a site in ASP.NET. I need it to be in French and English with domain settings like this:

en.mysite.com fr.mysite.com

I do not want to duplicate code or upload files to both domains, if possible.

It would be ideal to have all the files on www.mydomain.com and then use the resource files to sort the translations.

What is the best way to install this in ASP.NET?

+4
source share
3 answers

My solution installed lang in BeginRequest in global.asax

 Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) Dim lang As String = "es" ''//default If Request.Url.ToString.ToLower.StartsWith("http://es.") lang = "es" ElseIf Request.Url.ToString.ToLower.StartsWith("http://en.") Then lang = "en" End If Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang) Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang) Site.Idioma = lang ''//static variable that I use in other parts of the site End Sub 

Remember to set the redirection when the user clicks on www.mysite.com using the user's preferred browser language.

 Imports System.Globalization Partial Class redirect_Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal s As Object, ByVal e As System.EventArgs) _ Handles Me.Load Select Case Mid(Request.UserLanguages(0).ToString(), 1, 2).ToLower Case "en" Response.Redirect("http://en.mysite.com") Case Else Response.Redirect("http://es.mysite.com") End Select End Sub End Class 

As a side item, I recommend using http://www.mysite.com/en because itโ€™s better from an SEO point of view (if your site matters)

+3
source

As I understand correctly, you want to put all the files in the root directory, but use subdomains for different languages.

I think that en.mysite.com and fr.mysite.com should just be aliases and should tell asp.net which language to use. You can change the culture settings using the code. It is well described here .

But, from my point of view, this is the best way to provide language settings in the main domain with some default language and the ability to switch between languages. And if the user advises changing the language, he simply clicks one link. In this case, language settings can be stored anywhere (user profile, cookie, session, database, if a registered user, etc.).

0
source

If I implemented this, I would do the following: en.mysie.com map at www.mysite.com/page?lang=en fr.mysite.com map at www.mysite.com/page?lang=fr

and then on the main page, set the language according to the parameter using globalization, and asp.net pages will be automatically served in that language if they find the correct app_localresource file with the same language code.

Hope this helps

0
source

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


All Articles