Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling CultureInfo.InvariantCulture in RequestLocalizationMiddleware #58844

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,9 @@ private static void SetCurrentThreadCulture(RequestCulture requestCulture)
bool fallbackToParentCultures,
int currentDepth)
{
// If the cultureName is an empty string there
// is no chance we can resolve the culture info.
if (cultureName.Equals(string.Empty))
{
return null;
}

var culture = GetCultureInfo(cultureName, supportedCultures);

if (culture == null && fallbackToParentCultures && currentDepth < MaxCultureFallbackDepth)
if (culture == null && fallbackToParentCultures && currentDepth < MaxCultureFallbackDepth && cultureName != CultureInfo.InvariantCulture.Name)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RequestLocalizationMiddlewareTest
[InlineData("zh-Hans-CN", "zh-Hans")]
[InlineData("zh-Hant-TW", "zh-Hant")]
[InlineData("zh-TW", "zh-Hant")]
[InlineData("zh-Hans-CN", "")]
public async Task RequestLocalizationMiddleware_ShouldFallBackToParentCultures_RegradlessOfHyphenSeparatorCheck(string requestedCulture, string parentCulture)
{
using var host = new HostBuilder()
Expand Down
Loading