Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localize the Controller names and actions in an ASP.NET MVC application?

I'd like to fully localize my ASP.NET MVC application, and while there are many articles that deal with the various pitfalls of ASP.NET MVC localization, none of them deals with an aspect that I want to deal with, and that is the localization of URLs, including the controller names and actions.

I would like a way to specify the strings that should appear instead of the controller name and action name in the URL, for example in a resource file.

How is this doable in a sane way? Thanks in advance for your help!

EDIT:
I'm still looking for a way to do this. Any help would be welcome.
Is there any framework or lib implementing this already?

like image 872
Venemo Avatar asked Nov 24 '10 21:11

Venemo


People also ask

How will you localize URL in MVC application?

To offer a website in multiple languages using ASP.Net we simply need to add some resource. resx files to our project and voilà. Based on the language of the browser, IIS will match the localization resource.

How ASP Net applications are localized?

To opt-in to localization, we need to modify our Startup file. We'll be registering a few services, configuring options, and registering middleware. All steps that are common-place for additions in an ASP.NET application. Starting in our ConfigureServices method, we need to make a call to AddLocalization .

What are controllers and actions in MVC?

In ASP.NET MVC, a Controller is used to define and group a set of actions. An action (or action method ) is a method on a controller that handles incoming requests.


1 Answers

I've never done this before, but couldn't you add an entry to the routes table for every language you want to support? All of the localized routes could redirect to the route in the language of your choice. Check out these related questions:

Multi-lingual websites with ASP.NET MVC

How should I implement localization with ASP.NET MVC routes?

like image 179
Andrew Whitaker Avatar answered Nov 13 '22 02:11

Andrew Whitaker