mccalltd/AttributeRouting — Issue #45: Localization Needed
Author: mccalltd
Created: 2012-02-11 05:09:54+00:00
State: open
Labels: TODO

I would love to add localization support. However, I have not yet had a need for localizing routes. So to try and come up with a good solution, I would like to open the floor for comments. Please leave your requests and ideas so that I (or a willing contributor) can build something out.

What would be nice to have, and what would AR do?

1. Support specifying the locale to use during requests via the url with some pattern to match (eg: {culture}.domain.com or domain/{culture}), or with a custom object to provide the logic, or by using the culture of the current thread? Specify via the configuration process or in another attribute somehow?

2. ITranslationProvider that will translate route areas, prefixes, urls, defaults, and constraints? This provider could have a single method that when given a key, would return a string with the translation. Returning null would tell AR to use whatever is specified via the attributes in code. So the attribute would describe the default culture translation.

3. Use a conventional approach to specify keys provided to the translation provider? Add a new property to the attributes called TranslationKey, which could simply override the default convention? Convention and configuration. Any need to be able to specify your own convention?

4. Now, how to make AR use the translation provider to handle inbound requests? Do we need another route for every possible translation? So if you have 100 routes in your app, then having three translations would yield 300 routes? Anyone see this becoming a problem? It would be the easiest to do, and require the least processing after setting up routes.

5. Next, AR and outbound url generation. Have to use the translation provider to generate the correct url for the current culture. So when browsing a default-English site in Spanish, using the MVC UrlHelper will give the visitor properly translated urls. Would have to add a property to AttributeRoute that stores the translations created during route generation. Then AttributeRoute could place the translation over the default generated route. (Imaging a route like

```
/{areaUrl}/{prefix}/{routeUrl}/{param}
```

having a default generated route of

```
/sea/scape/goat/milk
```

and ending up with

```
/easay/apescay/oatgay/milk
```

with milk left alone cause it's a route param, but could have been supplied from translation for route default, and would apply translated route constraints as well.)

Would this be useful? This is just a stab at what could be done. The simplest way to fully support localization is what I'd want to build in. So suggestions are welcome!