RouteLocalization icon indicating copy to clipboard operation
RouteLocalization copied to clipboard

Change culture parameter name

Open mdmoura opened this issue 9 years ago • 7 comments

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

mdmoura avatar May 16 '15 01:05 mdmoura

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?

Dresel avatar May 16 '15 08:05 Dresel

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.

mdmoura avatar May 16 '15 21:05 mdmoura

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?

Dresel avatar May 17 '15 07:05 Dresel

I think the 4 options you suggested are enough.

That would be great because en/api does not sound right ... but api/en does.

mdmoura avatar May 17 '15 10:05 mdmoura

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.

Dresel avatar May 17 '15 10:05 Dresel

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 ...

mdmoura avatar May 17 '15 18:05 mdmoura

I see. I'll consider it for the next update.

Dresel avatar May 17 '15 18:05 Dresel