Skip to content

Commit 1a794fe

Browse files
authored
Merge pull request #11136 from umbraco/v9/bugfix/10977-Region-and-UI-cultures-are-different
Fixed cultures to now both seperately in the backoffice and frontend …
2 parents 981e096 + 3b95936 commit 1a794fe

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Umbraco.Web.Common/Localization/UmbracoBackOfficeIdentityCultureProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpC
3636
lock (_locker)
3737
{
3838
// We need to dynamically change the supported cultures since we won't ever know what languages are used since
39-
// they are dynamic within Umbraco.
39+
// they are dynamic within Umbraco. We have to handle this for both UI and Region cultures, in case people run different region and UI languages
4040
var cultureExists = _localizationOptions.SupportedCultures.Contains(culture);
4141

4242
if (!cultureExists)
4343
{
4444
// add this as a supporting culture
4545
_localizationOptions.SupportedCultures.Add(culture);
46+
}
47+
48+
var uiCultureExists = _localizationOptions.SupportedCultures.Contains(culture);
49+
50+
if (!uiCultureExists)
51+
{
52+
// add this as a supporting culture
4653
_localizationOptions.SupportedUICultures.Add(culture);
4754
}
4855

src/Umbraco.Web.Common/Localization/UmbracoPublishedContentCultureProvider.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpC
3636
lock (_locker)
3737
{
3838
// We need to dynamically change the supported cultures since we won't ever know what languages are used since
39-
// they are dynamic within Umbraco.
39+
// they are dynamic within Umbraco. We have to handle this for both UI and Region cultures, in case people run different region and UI languages
4040
// This code to check existence is borrowed from aspnetcore to avoid creating a CultureInfo
4141
// https://github.com/dotnet/aspnetcore/blob/b795ac3546eb3e2f47a01a64feb3020794ca33bb/src/Middleware/Localization/src/RequestLocalizationMiddleware.cs#L165
4242
CultureInfo existingCulture = _localizationOptions.SupportedCultures.FirstOrDefault(supportedCulture =>
@@ -47,6 +47,15 @@ public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpC
4747
// add this as a supporting culture
4848
var ci = CultureInfo.GetCultureInfo(culture);
4949
_localizationOptions.SupportedCultures.Add(ci);
50+
}
51+
52+
CultureInfo existingUICulture = _localizationOptions.SupportedUICultures.FirstOrDefault(supportedCulture =>
53+
StringSegment.Equals(supportedCulture.Name, culture, StringComparison.OrdinalIgnoreCase));
54+
55+
if (existingUICulture == null)
56+
{
57+
// add this as a supporting culture
58+
var ci = CultureInfo.GetCultureInfo(culture);
5059
_localizationOptions.SupportedUICultures.Add(ci);
5160
}
5261
}

0 commit comments

Comments
 (0)