Last post Feb 04, 2020 03:33 AM by BeRoots
Feb 03, 2020 07:26 AM|BeRoots|LINK
I would like to set localization like that in my asp.net core 3.1 application:
- QueryStringRequestCultureProvider will be a way to set the header when the server receive the culture get parameter
- It's also possible to pass "culture" parameter with another "forceCookie=true" parameter to QueryStringRequestCultureProvider to force using cookie instead of Header. In this case, header will no longer use and a cookie will be sent
- As long as no query is given, I want to set automaticaly a header with a default "en" culture (default behavior).
- finaly, I want to use 3 type of resource file like Example.en-US.resx or Example.en.resx (when cookie or header is defined) and Example.resx as fallback if no cookie and header was found.
In fact, my application will coded to use @Localizer["Native String"] of the default resource file (Example.resx). But if a header or a cookie is provided with en-US, the application looking for the Example.en-US.resx first and if not exists It look for
Example.en.resx. The default behavior is to have a en-US header by default for each request. Override this default header if an url like
?culture=es-MX is provided. Or disable header default and set a cookie if URL like
?culture=es-MX&forceCookie=true is provided
I have created a
github base project to show you my actual code. If someone could show me how to do this ;)
Thanks in advance for your help.
Feb 03, 2020 07:58 AM|Mikesdotnetting|LINK
The default behavior is to have a en-US header by default for each request.
You can also add, remove and change the order of the RequestCultureProviders as needed.
Feb 03, 2020 09:01 AM|BeRoots|LINK
Hi. Thanks for your anwser.
But are you sure I can't set the accept header ? The documentation
here provide an ApplyCurrentCultureToResponseHeaders option to force header to be sent...
Feb 03, 2020 11:46 AM|BeRoots|LINK
The documentation here provide an ApplyCurrentCultureToResponseHeaders option to force header to be sent...
Sorry. Here I confused Accept-Language and Content-Language. Therefore the default behavior is correct for me
I'm glade to discover your website. In your anwser, the tutorial provided is better as those I finded on the web ;-)
My example on github works but the configuration is better in your own example ;-)
I going to test with your example. I keep this topic unresolved for a time if some other question or problem appears.
Feb 04, 2020 03:33 AM|BeRoots|LINK
Ok. After some tests, the default behavior respect my needs. Thanks Mikesdotnetting