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

Ensure there can't be duplicate culture codes in languages dropdown #11441

Merged
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
13 changes: 6 additions & 7 deletions src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.BackOffice.Extensions;
using Umbraco.Cms.Web.Common.ActionsResults;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Authorization;
using Umbraco.Extensions;
Expand All @@ -23,7 +21,6 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
/// Backoffice controller supporting the dashboard for language administration.
/// </summary>
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
//[PrefixlessBodyModelValidator]
public class LanguageController : UmbracoAuthorizedJsonController
{
private readonly ILocalizationService _localizationService;
Expand Down Expand Up @@ -51,10 +48,12 @@ public IDictionary<string, string> GetAllCultures()
// (see notes in Language class about culture info names)
// TODO: Fix this requirement, see https://github.com/umbraco/Umbraco-CMS/issues/3623
return CultureInfo.GetCultures(CultureTypes.AllCultures)
.Where(x => !x.Name.IsNullOrWhiteSpace())
.Select(x => new CultureInfo(x.Name)) // important!
.OrderBy(x => x.EnglishName)
.ToDictionary(x => x.Name, x => x.EnglishName);
.Select(x=>x.Name)
.Distinct()
.Where(x => !x.IsNullOrWhiteSpace())
.Select(x => new CultureInfo(x)) // important!
.OrderBy(x => x.EnglishName)
.ToDictionary(x => x.Name, x => x.EnglishName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylecop suggests using a method body

public IDictionary<string, string> GetAllCultures() =>
            // get cultures - new-ing instances to get proper display name,
            // in the current culture, and not the cached one
            // (see notes in Language class about culture info names)
            // TODO: Fix this requirement, see https://github.com/umbraco/Umbraco-CMS/issues/3623
            CultureInfo.GetCultures(CultureTypes.AllCultures)
                .Select(x=>x.Name)
                .Distinct()
                .Where(x => !x.IsNullOrWhiteSpace())
                .Select(x => new CultureInfo(x)) // important!
                .OrderBy(x => x.EnglishName)
                .ToDictionary(x => x.Name, x => x.EnglishName);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that, but really didn't like it with the big comment 🙈

}

/// <summary>
Expand Down