-
Notifications
You must be signed in to change notification settings - Fork 65
RequestCultureProvider sets an unsupported culture when the request is not supported and the default is not defined or not supported. #70
Comments
This is related: #38 |
It's a bug :( |
@Bartmax can you try this if (requestCulture == null || Options == null)
{
return null;
}
var result = requestCulture;
if (Options.SupportedCultures?.Contains(result.Culture) == false)
{
if (Options.SupportedCultures.Contains(Options.DefaultRequestCulture.Culture))
{
return new RequestCulture(Options.DefaultRequestCulture.Culture);
}
else
{
return new RequestCulture(Options.SupportedCultures?.Count > 0 ?
Options.SupportedCultures[0] : Options.DefaultRequestCulture.Culture);
}
}
if (Options.SupportedUICultures?.Contains(result.UICulture) == false)
{
if (Options.SupportedUICultures.Contains(Options.DefaultRequestCulture.UICulture))
{
return new RequestCulture(Options.DefaultRequestCulture.UICulture);
}
else
{
return new RequestCulture(Options.SupportedUICultures?.Count > 0 ?
Options.SupportedUICultures[0] : Options.DefaultRequestCulture.UICulture);
}
}
return result; |
Looks good, not sure what will works as expected if we have:
I don't think it will be a common scenario but... because we return earlier on Culture without even checking at UICulture. I guess best way to tell is to have some unit test. |
You are right @Bartmax, let me revise the code snippet and come back to you |
@kirthik can you look into this if you don't mind, seems it's a critical issue |
With this design change - #111, passing in default culture will be required when adding localization. We will scan request's culture through supported culture list and fall back to default if exact match is not found. So scenario where default culture is not defined or supported does not arise. Hence closing this issue. |
Helping someone with an issue on Jabbr about localization, I found this strange (at least for me) behavior.
note the commented line
With this cshtml (in layout or index):
According to the documentation here: https://github.com/aspnet/Localization/blob/dev/src/Microsoft.AspNet.Localization/RequestLocalizationOptions.cs#L38-L54
This is not expected behavior. Those cultures are not supposed to be supported by the application.
Uncommenting the commented line (DefaultRequestCulture) I get the expected output:
Looking at source code, I found that a 'premature' fallback to default culture.
https://github.com/aspnet/Localization/blob/dev/src/Microsoft.AspNet.Localization/RequestCultureProvider.cs#L42-L50 without checking if the Default is supported.
I think the workflow should be more like (not real code)
I'm assuming Empty List = null here.
The text was updated successfully, but these errors were encountered: