RouteLocalization
RouteLocalization copied to clipboard
Change culture parameter name
Hello,
If I am not wrong the parameter that holds the current culture is "culture", right?
Is it possible to change the name of this parameter?
Thank You, Miguel
Yes you are right.
The culture parameter is just added to the defaults collection of the inner route:
public static LocalizationRoute ToLocalizationRoute(this TIRoute route, string url, string culture)
{
// Add culture to the route defaults so it can be used as action parameter
TRouteValueDictionary defaults = new TRouteValueDictionary(route.Defaults);
defaults["culture"] = culture;
return new LocalizationRoute(url, defaults,
new TRouteValueDictionary(route.Constraints), new TRouteValueDictionary(route.DataTokens), route.RouteHandler(), culture);
}
Depending on what you need you could modify the defaults afterwards... why do you want to change that?
I am asking because sometimes it is needed to have another culture parameter for an API so changing the one used by RL would be useful ...
Maybe a property on setup? Something like:
x.DefaultCulture = "en";
x.ParameterName = "something";
Another useful feature would be to control the position of the culture parameter.
I think at the moment Route Localization create the routes as follows:
/en/api/tags
It would be greate to use also:
api/en/tags
Where API is a RoutePrefix.
The culture parameter has nothing todo with the routeprefix within the url - the culture parameter also exists if you don't use route prefix.
I also wouldn't see it as parameter, it is more a "constant" which is added to the route, so you can use it to query the current culture.
You are right for the RoutePrefix position, what options are there?
- Before
[RouteArea]
,[RoutePrefix]
,[Route]
(as it is now) - After
[RouteArea]
but before[RoutePrefix]
,[Route]
- After
[RouteArea]
,[RoutePrefix]
but before[Route]
- After
[RouteArea]
,[RoutePrefix]
,[Route]
Anything else?
I think the 4 options you suggested are enough.
That would be great because en/api does not sound right ... but api/en does.
Added a separate issue for that.
Back to the culture "parameter" naming. How do you use it at the moment and when do you need to rename it? If I understand your use case, it may be easier to come up with a solution.
Consider you have this:
public async Task<IHttpActionResult> Get(Int32 id, String culture) {
// ...
}
Wouldn't this interfere with the culture parameter?
Another example is a project I received a few weeks ago where Language is used in every place of the project but in RL I must use culture (for example, when changing culture). Having the option to use language as the localization parameter might be useful ...
Again, this is not so important ... I asked because I came up with these situations and if I am not mistaken, in Attribute Routing from Tim McCall, there was an option to define the name of that parameter? Maybe it might be useful because of other reasons ...
I see. I'll consider it for the next update.