Merge branch 'main' into v17/dev

# Conflicts:
#	src/Umbraco.Core/Services/AuditService.cs
#	src/Umbraco.Core/Services/IAuditService.cs
This commit is contained in:
Andy Butland
2025-06-09 06:49:12 +02:00
575 changed files with 16402 additions and 8075 deletions

View File

@@ -1576,4 +1576,22 @@ public static class StringExtensions
// this is by far the fastest way to find string needles in a string haystack
public static int CountOccurrences(this string haystack, string needle)
=> haystack.Length - haystack.Replace(needle, string.Empty).Length;
/// <summary>
/// Verifies the provided string is a valid culture code and returns it in a consistent casing.
/// </summary>
/// <param name="culture">Culture code.</param>
/// <returns>Culture code in standard casing.</returns>
public static string? EnsureCultureCode(this string? culture)
{
if (string.IsNullOrEmpty(culture) || culture == "*")
{
return culture;
}
// Create as CultureInfo instance from provided name so we can ensure consistent casing of culture code when persisting.
// This will accept mixed case but once created have a `Name` property that is consistently and correctly cased.
// Will throw in an invalid culture code is provided.
return new CultureInfo(culture).Name;
}
}