Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Change culture parameter name #48

Open
mdmoura opened this issue May 16, 2015 · 7 comments
Open

Change culture parameter name #48

mdmoura opened this issue May 16, 2015 · 7 comments

Comments

@mdmoura
Copy link

mdmoura commented May 16, 2015

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

@Dresel
Copy link
Owner

Dresel commented May 16, 2015

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?

@mdmoura
Copy link
Author

mdmoura commented May 16, 2015

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.

@Dresel
Copy link
Owner

Dresel commented May 17, 2015

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?

@mdmoura
Copy link
Author

mdmoura commented May 17, 2015

I think the 4 options you suggested are enough.

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

@Dresel
Copy link
Owner

Dresel commented May 17, 2015

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.

@mdmoura
Copy link
Author

mdmoura commented May 17, 2015

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

@Dresel
Copy link
Owner

Dresel commented May 17, 2015

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants