Localization is big thing for international websites. And I needed use it when I was building MottoJoy.com.
There is very good explanation/example for that in ASPNET repo on GitHub. It in a solution named as Entropy and here is the link: https://github.com/aspnet/Entropy/tree/dev/samples/Mvc.LocalizationSample.Web
But there are some missed points.
There are 4 types of types of localization methods comes with standard library. You may also implement your own.
- By url query strings
- By request header
- By cookie
CookieRequestCultureProvider(This one is used in Entropy repository)
- And by routing data
I tried all of them and they work very well except 'localization by routing data'.
I care too much about SEO. And I think when building website it is all about SEO. Driving traffic/visitor/customer to website for free. So that is most important thing in this matter: 'SEO point of view'.
When we say SEO, of course Google is our king. There is an article about 'Multi-regional and multilingual sites' by Google. One of the most important thing we see in this article is in these lines:
Thus, 'localization by cookie' and 'localization by request header' is out of question.
Also in this article there is table for 'URL structures' and at it's last row it says URL parameters is not recommended for localization. And that leaves 'localization by query strings' out of question, too.
Actually some developers wouldn't call it a bug maybe. It is not crashing but it is not working either. So it is pretty good bug for me.
When you use
RouteDataRequestCultureProvider class as
RequestCultureProviders it fails without crashing or raising error. After spending two hours to find what causes that problem, I come across with this post on Stack Overflow. And i got an idea to solve it.
When localization classes are called ASP MVC wouldn't be generated routing data for
HttpContext class. So
RouteDataRequestCultureProvider trying to decide which culture to use with
null routing data and of course every time it try to resolve routing data, it can't find anything to resolve and returns default culture.
You can find how I solve this problem in this post.
I hope this post has helped you.