I need multi-language URL route of existing controller. Let me explain more:
I have a controller with name "Product" and View with name "Software"; therefore, by default if the user enters "http://example.com/en/Product/Software", get right content (that really exists in http://example.com/Product/Software),
However, if another user -- a French user -- types "http://example.com/fr/Produits/logiciels", must get above controller and show with right content (same http://example.com/Product/Software but with French text).
Note: I set the route table with "{language}/{controller}/{action}/{id}"
Any other invalid URL must show the 404 page.
Is it possible?
Building upon Dan's post, I'm using the beneath for translating my controller and action names.
I created a table to store the values, this could and probably should be held in the resource files to keep everything together; however I used a database table as it works better with my companies processes.
The RouteConfig.cs file was then changed to:
By default this will always use the English controller and action names, but allows you to provide an override by entering the values into the table.
(My internationalization code is largely based from this great blog post. http://afana.me/post/aspnet-mvc-internationalization-part-2.aspx)
As has been suggested before, this does depart from convention where the website urls (and routes) use English.
Nevertheless, it is possible, but in order to do it, you'll probably have to look at generating one route per action for every foreign language. So for a website with 20 actions and three languages (English, French, and German), you'll need 41 routes (20 French, 20 German and 1 English). Not the most efficient system, I admit, but it works as you want it to.
In your actions, for example Product/Software...
I would LOVE it if somebody came along and said that there's a better way of doing this, because I agree that having the url in a foreign language isn't good, and given that the Internet itself is moving towards allowing non-Roman characters in urls, the sooner we look at solutions to this, the better.
Not only that, but I know proud French people don't like to see their website urls contain English. :)
You should have url something like "http://mysite.com/en/Product/Software" for English and "http://mysite.com/fr/Product/Software" for French, which would make much sense.
Use the same view for both.
Happy coding.
I strongly recommend the following approach to implement the multi-language in a MVC 5 (and <) web application, because I find it to be the most versatile one among those I've tried in the latest years.
You basically need to implement three things:
Html.ActionLink
and/orUrl.Action
extension methods).See this answer for further details and code samples.
For additional info and further samples on this topic you can also read you can also read this blog post that I wrote on this topic.