-
Notifications
You must be signed in to change notification settings - Fork 65
Get segment from mapped route for CustomRequestCultureProvider #122
Comments
What I did was create a
Then simply register it in the
My route mapping is different from yours, but you can easily modify the code to fit your needs
|
@BenjiZombie thanks for good example. app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{culture?}/{controller}/{action}/{id?}",
defaults: new { culture = "en", controller = "Home", action = "Index" });
}); |
You can have a look to issue #54 #57 as well as https://github.com/aspnet/Localization/blob/dev/test/Microsoft.AspNet.Localization.Tests/CustomRequestCultureProviderTest.cs#L46 |
@hishamco Thanks I implement my code based on your links 👍
|
@Codenator81 you can inject |
@hishamco I do it in HomeController all ready) |
What is the value of |
@hishamco There everything work great. My issue is how get route segment from route template before UseMVC middleware. But I think it is not possible. I will try different approach. |
Why you need it before MVC middleware?!! if that's the case i will try to look in your sample |
@hishamco You are right 👍 |
All the best @Codenator81 , be free to ask if you have an issue again |
@kirthik @DamianEdwards We should look at what our guidance is for using path segments for determining the culture and maybe provide a sample on how to do it. |
@danroth27 i provide a simple unit test in https://github.com/aspnet/Localization/blob/dev/test/Microsoft.AspNet.Localization.Tests/CustomRequestCultureProviderTest.cs#L46, also I already suggest #43, if this will help i will make a PR for that |
Middlewares don`t work after UseMVC middleware |
@Codenator81 if what you are looking for is in culture segment in "{controller=Home}/{culture=en-US}/{action=Index}/{id?}", I will try to look to into your sample or i will write a code snippet to display the culture segment |
@hishamco Yes I looking for that. |
I think this should be an extra default Provider like the others as this is a common use case. What do you think? Greetings Damien |
Ok @Codenator81 I will dig into that |
@Codenator81 for saving time do you have a repo with the latest changes that you did? |
Thanks for your answer, your PR sounds great, I was thinking more of a MVC 6 extension which would allow me to define my culture in the MVC attribute routing. Greetings Damien |
@damienbod IMHO while there's |
@Codenator81 have you look to this sample https://github.com/aspnet/Mvc/tree/9342cb0ab78add8c527edcbc4c0988edc96f01e3/test/WebSites/LocalizationWebSite if you didn't get your answer, I will add a sample demo for that |
@hishamco I see that example long time ago. For now it is outdated? For example app.UseCultureReplacer(); I don`t find (may be removed from code)? As I wrote one comment before I looking for segment in Controller. Same people do simelar approach in filter. But for now it is not possible get segment from middleware. I think it is routing feature or issue. |
I see, but as I mentioned before issue #54 and https://github.com/aspnet/Localization/blob/dev/test/Microsoft.AspNet.Localization.Tests/CustomRequestCultureProviderTest.cs#L57 do such thing without using routes, I used segments instead, probably the idea is same. I'm not sure such sample should be in localization repo or mvc?!! |
@hishamco I see all that examples. All of them great 👍 My issue different. routes.MapRoute(
name: "transRoute",
template: "{controller=Home}/{culture=en-US}/{action=Index}/{id?}"); So I wont detect culture segment if it is at end route or at middle without rewrite code and just get that segment as I do in code there: string cultureFromRoute = RouteData.Values["culture"] as string; but segments can be detected only after routes initilized. So there no way get segment in middleware. Hope I explain my issue? |
Could you please add a repo summarize your scenario without any other stuff (MiniMVC), i already saw WeebDoCMF but I don't wanna miss on any other stuff 😄 |
Ok I will do it. May be today evening. |
It's in the way @Codenator81 😄 |
…nformation. [Fixes #122] Get segment from mapped route for CustomRequestCultureProvider
…nformation. [Fixes #122] Get segment from mapped route for CustomRequestCultureProvider
…nformation. [Fixes #122] Get segment from mapped route for CustomRequestCultureProvider
I tested after
in startup class app.UseRequestLocalization not work.
For example user want culture segment been in:
So how I can get
{culture}
segment to find route match?This is all way not processed:
Thanks Alex
The text was updated successfully, but these errors were encountered: