Merge pull request #12206 from KevinJump/v9/localizedtext-via-fileprovider

Get lang files via FileProviders (and support Razor Class Libraries)
This commit is contained in:
Nikolaj Geisle
2022-04-22 08:14:46 +02:00
committed by GitHub
3 changed files with 93 additions and 20 deletions

View File

@@ -76,31 +76,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>());
}
}
}