Move SupplemenataryLocalizedTextSources to Backoffice and use File provider.

This commit is contained in:
Kevin Jump
2022-03-31 22:36:34 +01:00
parent db12594332
commit a7ed20918b
3 changed files with 97 additions and 20 deletions

View File

@@ -116,31 +116,13 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
private static LocalizedTextServiceFileSources SourcesFactory(IServiceProvider container)
{
var hostingEnvironment = container.GetRequiredService<IHostingEnvironment>();
var globalSettings = container.GetRequiredService<IOptions<GlobalSettings>>().Value;
var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Umbraco, "config", "lang")));
var appPlugins = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins));
var configLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Config, "lang")));
var pluginLangFolders = appPlugins.Exists == false
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
: appPlugins.GetDirectories()
// Check for both Lang & lang to support case sensitive file systems.
.SelectMany(x => x.GetDirectories("?ang", SearchOption.AllDirectories).Where(x => x.Name.InvariantEquals("lang")))
.SelectMany(x => x.GetFiles("*.xml", SearchOption.TopDirectoryOnly))
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, false));
// user defined langs that overwrite the default, these should not be used by plugin creators
var userLangFolders = configLangFolder.Exists == false
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
: configLangFolder
.GetFiles("*.user.xml", SearchOption.TopDirectoryOnly)
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, true));
return new LocalizedTextServiceFileSources(
container.GetRequiredService<ILogger<LocalizedTextServiceFileSources>>(),
container.GetRequiredService<AppCaches>(),
mainLangFolder,
pluginLangFolders.Concat(userLangFolders));
container.GetServices<LocalizedTextServiceSupplementaryFileSource>());
}
}
}