diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs index 5f70a91b23..5d45f9c7e8 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationContext.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.FileProviders; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { @@ -9,10 +10,13 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling public IServiceProvider ServiceProvider { get; } - public BundleConfigurationContext(IServiceProvider serviceProvider) + public IFileProvider FileProvider { get; } + + public BundleConfigurationContext(IServiceProvider serviceProvider, IFileProvider fileProvider) { Files = new List(); ServiceProvider = serviceProvider; + FileProvider = fileProvider; } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs index 760be2de70..572ea918e9 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs @@ -39,7 +39,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling IServiceProvider serviceProvider, IDynamicFileProvider dynamicFileProvider, IBundleCache bundleCache, - IHybridWebRootFileProvider webRootFileProvider, + IHybridWebRootFileProvider webRootFileProvider, IWebRequestResources requestResources) { HostingEnvironment = hostingEnvironment; @@ -67,7 +67,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling protected virtual IReadOnlyList GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) { - var files = RequestResources.Filter(CreateFileList(bundles, bundleName)); + var contributors = GetContributors(bundles, bundleName); + var files = RequestResources.Filter(CreateFileList(contributors)); if (!IsBundlingEnabled()) { @@ -183,30 +184,33 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling } } - protected virtual List CreateFileList(BundleConfigurationCollection bundles, string bundleName) + protected virtual List CreateFileList(List contributors) { using (var scope = ServiceProvider.CreateScope()) { - var contributors = new List(); - var context = new BundleConfigurationContext(scope.ServiceProvider); - - AddContributorsWithBaseBundles(contributors, bundles, context, bundleName); - + var context = new BundleConfigurationContext(scope.ServiceProvider, scope.ServiceProvider.GetRequiredService()); contributors.ForEach(c => c.PreConfigureBundle(context)); contributors.ForEach(c => c.ConfigureBundle(context)); contributors.ForEach(c => c.PostConfigureBundle(context)); - return context.Files; //TODO: Distinct? + return context.Files; } } - protected virtual void AddContributorsWithBaseBundles(List contributors, BundleConfigurationCollection bundles, BundleConfigurationContext context, string bundleName) + protected virtual List GetContributors(BundleConfigurationCollection bundles, string bundleName) + { + var contributors = new List(); + AddContributorsWithBaseBundles(contributors, bundles, bundleName); + return contributors; + } + + protected virtual void AddContributorsWithBaseBundles(List contributors, BundleConfigurationCollection bundles, string bundleName) { var bundleConfiguration = bundles.Get(bundleName); foreach (var baseBundleName in bundleConfiguration.BaseBundles) { - AddContributorsWithBaseBundles(contributors, bundles, context, baseBundleName); //Recursive call + AddContributorsWithBaseBundles(contributors, bundles, baseBundleName); //Recursive call } var selfContributors = bundleConfiguration.Contributors.GetAll(); diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/JQueryValidation/JQueryValidationScriptContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/JQueryValidation/JQueryValidationScriptContributor.cs index 53f6b077f5..868f65b2e5 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/JQueryValidation/JQueryValidationScriptContributor.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/JQueryValidation/JQueryValidationScriptContributor.cs @@ -11,23 +11,36 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation { public const string DefaultLocalizationFolder = "/libs/jquery-validation/localization/"; - public static Dictionary LocalizationMapping { get; } = new Dictionary - { - //TODO: Add all! - {"ar", DefaultLocalizationFolder + "messages_ar.js"}, - {"tr", DefaultLocalizationFolder + "messages_tr.js"} - }; - public override void ConfigureBundle(BundleConfigurationContext context) { context.Files.AddIfNotContains("/libs/jquery-validation/jquery.validate.js"); - //context.PostDynamicFiles.AddIfNotContains("/libs/jquery-validation/localization/messages_" + CultureInfo.CurrentUICulture.Name + ".js"); } public void ConfigureDynamic(BundleConfigurationContext context) { - //TODO: !!! - context.Files.AddIfNotContains("/libs/jquery-validation/localization/messages_" + CultureInfo.CurrentUICulture.Name + ".js"); + //TODO: Can we optimize this? Also refactor a bit to reduce duplication + + var currentCultureName = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Replace('-', '_'); + var filePath = DefaultLocalizationFolder + "messages_" + currentCultureName + ".js"; + var fileInfo = context.FileProvider.GetFileInfo(filePath); + if (fileInfo != null) + { + context.Files.AddIfNotContains(filePath); + return; + } + + if (!currentCultureName.Contains("_")) + { + return; + } + + currentCultureName = currentCultureName.Substring(0, currentCultureName.IndexOf('_')); + filePath = DefaultLocalizationFolder + "messages_" + currentCultureName + ".js"; + fileInfo = context.FileProvider.GetFileInfo(filePath); + if (fileInfo != null) + { + context.Files.AddIfNotContains(filePath); + } } } }