From be1fddb9beab4f508384d38a4c60151e5c1bfa22 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 30 Jun 2022 14:08:13 +0200 Subject: [PATCH] Added configuration to allow RTL cultures to opt-in to reverse the url hierarchy (#12635) * Added configuration to allow RTL cultures to opt-in to reverse the url hierarchy. https://github.com/umbraco/Umbraco-CMS/issues/12621 * Fixed bug.. There is difference between array.Reverse (Linq) and list.Reverse (native) * formatting --- .../Configuration/Models/GlobalSettings.cs | 21 ++++++++++++++++++- .../ContentCache.cs | 15 +++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index 5351da317c..2665c0738f 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -33,6 +33,7 @@ public class GlobalSettings internal const string StaticDistributedLockingWriteLockDefaultTimeout = "00:00:05"; internal const bool StaticSanitizeTinyMce = false; internal const int StaticMainDomReleaseSignalPollingInterval = 2000; + private const bool StaticForceCombineUrlPathLeftToRight = true; /// /// Gets or sets a value for the reserved URLs (must end with a comma). @@ -226,7 +227,25 @@ public class GlobalSettings TimeSpan.Parse(StaticDistributedLockingWriteLockDefaultTimeout); /// - /// Gets or sets a value representing the DistributedLockingMechanism to use. + /// Gets or sets a value representing the DistributedLockingMechanism to use. /// public string DistributedLockingMechanism { get; set; } = string.Empty; + + /// + /// Force url paths to be left to right, even when the culture has right to left text + /// + /// + /// For the following hierarchy + /// - Root (/ar) + /// - 1 (/ar/1) + /// - 2 (/ar/1/2) + /// - 3 (/ar/1/2/3) + /// - 3 (/ar/1/2/3/4) + /// When forced + /// - https://www.umbraco.com/ar/1/2/3/4 + /// when not + /// - https://www.umbraco.com/ar/4/3/2/1 + /// + [DefaultValue(StaticForceCombineUrlPathLeftToRight)] + public bool ForceCombineUrlPathLeftToRight { get; set; } = StaticForceCombineUrlPathLeftToRight; } diff --git a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs index c64bd77b92..7a440ef768 100644 --- a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs +++ b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs @@ -87,6 +87,12 @@ public class ContentCache : PublishedCacheBase, IPublishedContentCache, INavigab IPublishedContent? content; + if ((!_globalSettings.ForceCombineUrlPathLeftToRight + && CultureInfo.GetCultureInfo(culture ?? _globalSettings.DefaultUILanguage).TextInfo.IsRightToLeft)) + { + parts = parts.Reverse().ToArray(); + } + if (startNodeId > 0) { // if in a domain then start with the root node of the domain @@ -190,8 +196,13 @@ public class ContentCache : PublishedCacheBase, IPublishedContentCache, INavigab ApplyHideTopLevelNodeFromPath(node, pathParts, preview); } - // assemble the route - pathParts.Reverse(); + // assemble the route- We only have to reverse for left to right languages + if ((_globalSettings.ForceCombineUrlPathLeftToRight + || !CultureInfo.GetCultureInfo(culture ?? _globalSettings.DefaultUILanguage).TextInfo.IsRightToLeft)) + { + pathParts.Reverse(); + } + var path = "/" + string.Join("/", pathParts); // will be "/" or "/foo" or "/foo/bar" etc // prefix the root node id containing the domain if it exists (this is a standard way of creating route paths)