Localization and bit of SEO

Internet is widely available worldwide no matter what language they may speak.

 

Then, why not make your website in multi languages?

 

ASP.Net come with great feature called resource files where you can store key and value per languages and locale (culture) you specify.

The use of resource file is straight forward and easy to implement.  But working with routing feature and making it SEO friendly takes few extra steps

 

and here is how.

Making it “globalization” ready.

In order to serve different languages, first, your  web application has to have a way to detect which language and locale to use.  Once it is detected, then your web application can call corresponding resource files and this is handled within web.Config file like below;

Resource File

The resource file is a table that consist of keys and values, and end with file extension .resx.  A resource file can be local or global.  Global is accessible from anywhere in the application, and local is accessible within specific controls / view folder.

Unless you have to, I recommend using local resource files as much as possible.

To add local resource file, you right click on View folder then click on Add ASP.Net folder, then click on App_Local_Resources, then you ll see new folder created under Views folder.

Local resource file naming rule is; if you have index.cshtml then to add local resource file for this specific View, add index.cshtml.resx for default locale and Index.cshtml.ja.resx for Japanese.

Calling Resource File Content

Once you create resource file, from your View, you can call  locale value like below;

And my resource files look like;

スクリーンショット_030716_102231_PM

and View;

スクリーンショット_030716_102439_PM

Good, it seems to be working.

Programmatically changing locale

My default locale is set to Japanese, and it is set to detect browser’s default locale, so this is working OK.

Let’s see if I can set the active locale to English. I am setting simple link button to switch culture settings like below;

And View code like;

that looks like

スクリーンショット_030716_105226_PM

By default if locale is not set (id is not set), it is set to English, so this is working OK.

Now I click on “Set to Japanese”, which basically reload page with id parameter value “japanese”. Which triggers to set culture to “ja”.

スクリーンショット_030716_105445_PM

Great, this works too.

Working on Route

Now, let’s see if we can set more friendly urls, having prefix local settings in URL like /ja-JP/ being Japanese for Japan, /en-US/ being English for the US, /es-US/ being Spanish for the US.

RouteConfig.cs in App_Start is where routing configuration is stored, and I want to add new MapRoute that handles locale settings.  I have added new variable like below;

This way, if user specify nothing then locale is set to en-US by default.

SEO: sub-domain or folder?

When you are making multi language web application, I recommend go with folder base url rather than sub domain.   Unless if your web application needs to have different set of business logic, template etc.  Assuming that all changes based on local can be handled with resource files, you can likely build better internal links, which scores high.

But of course if the web application need to evolve and have different business logic, then the resource file is not going to cut it, and better off setting sub-domain and treat as completely different site.

Sometimes, some people say, some domain seem to score better as local content like, co.jp, or .jp in Japan or .ru in Russia and so on.  I am not 100% certain if this is true.  Google doesn’t seem to care about it.  But if your site has millions of content to index for search engine.  Then I may recommend having different sub-domain and treat as different site.  Search engine crawler can visit you and may be able to index you better if go with sub-domain model.

I will refine and continue to cover more about setting locale and being SEO friendly for multi language web application more. (to be continued)

 

 

Leave a Reply