From 1ccaf6bae1edab1b1a91613e453499a436961461 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 21 Dec 2023 23:06:00 +0300 Subject: [PATCH 1/3] Use ILocalizationService instead of get all cultures --- .../Controllers/AdminController.cs | 15 +++++++++++---- .../Controllers/AdminController.cs | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index de7e1092e12..89a1e32f9ce 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -51,6 +51,7 @@ public class AdminController : Controller private readonly INotifier _notifier; private readonly ILogger _logger; private readonly IOptions _templateOptions; + private readonly ILocalizationService _localizationService; public AdminController( ISession session, @@ -69,8 +70,8 @@ public AdminController( IOptions elasticSearchOptions, INotifier notifier, ILogger logger, - IOptions templateOptions - ) + IOptions templateOptions, + ILocalizationService localizationService) { _session = session; _siteService = siteService; @@ -89,6 +90,7 @@ IOptions templateOptions _notifier = notifier; _logger = logger; _templateOptions = templateOptions; + _localizationService = localizationService; } public async Task Index(ContentOptions options, PagerParameters pagerParameters) @@ -209,8 +211,13 @@ public async Task EditPost(ElasticIndexSettingsViewModel model, st if (!ModelState.IsValid) { - model.Cultures = CultureInfo.GetCultures(CultureTypes.AllCultures) - .Select(x => new SelectListItem { Text = x.Name + " (" + x.DisplayName + ")", Value = x.Name }); + var supportedCultures = await _localizationService.GetSupportedCulturesAsync(); + + model.Cultures = supportedCultures.Select(c => new SelectListItem + { + Text = $"{c} ({CultureInfo.GetCultureInfo(c).DisplayName})", + Value = c + }); model.Analyzers = _elasticSearchOptions.Analyzers .Select(x => new SelectListItem { Text = x.Key, Value = x.Key }); diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs index 3599900d536..5d5095bbdd9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs @@ -51,6 +51,7 @@ public class AdminController : Controller protected readonly IHtmlLocalizer H; private readonly ILogger _logger; private readonly IOptions _templateOptions; + private readonly ILocalizationService _localizationService; public AdminController( ISession session, @@ -69,7 +70,8 @@ public AdminController( IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, ILogger logger, - IOptions templateOptions) + IOptions templateOptions, + ILocalizationService localizationService) { _session = session; _luceneIndexManager = luceneIndexManager; @@ -83,12 +85,12 @@ public AdminController( _notifier = notifier; _pagerOptions = pagerOptions.Value; _javaScriptEncoder = javaScriptEncoder; - New = shapeFactory; S = stringLocalizer; H = htmlLocalizer; _logger = logger; _templateOptions = templateOptions; + _localizationService = localizationService; } public async Task Index(ContentOptions options, PagerParameters pagerParameters) @@ -208,8 +210,14 @@ public async Task EditPost(LuceneIndexSettingsViewModel model, str if (!ModelState.IsValid) { - model.Cultures = CultureInfo.GetCultures(CultureTypes.AllCultures) - .Select(x => new SelectListItem { Text = x.Name + " (" + x.DisplayName + ")", Value = x.Name }).Prepend(new SelectListItem { Text = S["Any culture"], Value = "any" }); + var supportedCultures = await _localizationService.GetSupportedCulturesAsync(); + + model.Cultures = supportedCultures + .Select(c => new SelectListItem + { + Text = $"{c} ({CultureInfo.GetCultureInfo(c).DisplayName})", + Value = c + }).Prepend(new SelectListItem { Text = S["Any culture"], Value = "any" }); model.Analyzers = _luceneAnalyzerManager.GetAnalyzers() .Select(x => new SelectListItem { Text = x.Name, Value = x.Name }); return View(model); From b55e05605a169a830bc068682bac0a63a637baca Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 22 Dec 2023 00:07:33 +0300 Subject: [PATCH 2/3] Add missing comma --- .../Controllers/AdminController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index a13e9fcdf10..d31464de083 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -69,7 +69,7 @@ public AdminController( ILogger logger, IOptions templateOptions, IShapeFactory shapeFactory, - ILocalizationService localizationService + ILocalizationService localizationService, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer) { From 6c12fc12982c8f26e496fc5202ead03de0b1efd8 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 22 Dec 2023 00:39:42 +0300 Subject: [PATCH 3/3] Fix merge conflict issue --- .../Controllers/AdminController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index d31464de083..d9a562344f1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -21,6 +21,7 @@ using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Notify; using OrchardCore.Liquid; +using OrchardCore.Localization; using OrchardCore.Navigation; using OrchardCore.Routing; using OrchardCore.Search.Elasticsearch.Core.Models; @@ -244,7 +245,7 @@ public async Task EditPost(ElasticIndexSettingsViewModel model, st await _notifier.ErrorAsync(H["An error occurred while creating the index."]); _logger.LogError(e, "An error occurred while creating index: {indexName}.", _elasticIndexManager.GetFullIndexName(model.IndexName)); - PopulateMenuOptions(model); + await PopulateMenuOptionsAsync(model); return View(model); } @@ -272,7 +273,7 @@ public async Task EditPost(ElasticIndexSettingsViewModel model, st await _notifier.ErrorAsync(H["An error occurred while editing the index."]); _logger.LogError(e, "An error occurred while editing index: {indexName}.", _elasticIndexManager.GetFullIndexName(model.IndexName)); - PopulateMenuOptions(model); + await PopulateMenuOptionsAsync(model); return View(model); }