V10: merge release branch 20220620 (#12590)
* Add Umbraco specific global usings * Enable implicit usings * v10: Wait for updated ConnectionStrings during install (#12536) * Do not change/reload configuration * Wait for updated connection string options * recase assigndomain (#12448) * Add depth property to ICoreScope (#12540) * Remove ambient scope stack from httpcontext.items. (#12539) This change makes it easier to use service calls in parallel whilst a httpcontext is available. * v10: Prefer SQLite primitive types to flexible types (#12541) * Prefer SQLite primitive types to flexible types. * SQLite - column mappings use TEXT for decimals Thanks @mattbrailsford for sense check. * Fix issue where languages files are not found in subdir of package dir (#12543) * Make FindContent return type nullable (#12545) * Updated nuget dependencies (07-06-2022) (#12525) * Updated nuget dependencies * Move Nerdbank.GitVersioning update to Directory.Build.props * Updated more dependencies * Improve FlagOutOfDateModels property behaviour. (cherry picked from commit 54077725c373495fce0d3fbc5cdb6469aad3b676) * Fix logic error WRT models builder flag out of date models. (#12548) (cherry picked from commit 6b0149803a879d1c6902a5f61d1f2e9dc8545aac) * Fixed issue with expected null value. (#12550) Fixes https://github.com/umbraco/Umbraco-CMS/issues/12526 * Updated Examine to 3.0.0 * Fixes relation issue, when moving a root item to recycle bin, the "Relate Parent Media Folder On Delete"/"Relate Parent Document On Delete" cannot get the parent node type, because it is a fake root. * Fix possible null error * Bump version to 10.0.0 final * Fix attempting to write lock files to LocalTempPath before it exists (#12563) * Re fix usage statements Co-authored-by: Ronald Barendse <ronald@barend.se> Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Co-authored-by: Paul Johnson <pmj@umbraco.com> Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -1,110 +1,116 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.DependencyInjection;
|
||||
using Umbraco.Cms.Core.Routing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IUmbracoBuilder" /> for the Umbraco back office
|
||||
/// </summary>
|
||||
public static partial class UmbracoBuilderExtensions
|
||||
namespace Umbraco.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the supplementary localized texxt file sources from the various physical and virtual locations supported.
|
||||
/// Extension methods for <see cref="IUmbracoBuilder"/> for the Umbraco back office
|
||||
/// </summary>
|
||||
private static IUmbracoBuilder AddSupplemenataryLocalizedTextFileSources(this IUmbracoBuilder builder)
|
||||
public static partial class UmbracoBuilderExtensions
|
||||
{
|
||||
builder.Services.AddTransient(sp =>
|
||||
|
||||
/// <summary>
|
||||
/// Adds the supplementary localized texxt file sources from the various physical and virtual locations supported.
|
||||
/// </summary>
|
||||
private static IUmbracoBuilder AddSupplemenataryLocalizedTextFileSources(this IUmbracoBuilder builder)
|
||||
{
|
||||
return GetSupplementaryFileSources(
|
||||
sp.GetRequiredService<IWebHostEnvironment>());
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Loads the suplimentary localization files from plugins and user config
|
||||
/// </summary>
|
||||
private static IEnumerable<LocalizedTextServiceSupplementaryFileSource> GetSupplementaryFileSources(
|
||||
IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
IFileProvider webFileProvider = webHostEnvironment.WebRootFileProvider;
|
||||
IFileProvider contentFileProvider = webHostEnvironment.ContentRootFileProvider;
|
||||
|
||||
// gets all langs files in /app_plugins real or virtual locations
|
||||
IEnumerable<LocalizedTextServiceSupplementaryFileSource> pluginLangFileSources =
|
||||
GetPluginLanguageFileSources(webFileProvider, Constants.SystemDirectories.AppPlugins, false);
|
||||
|
||||
// user defined langs that overwrite the default, these should not be used by plugin creators
|
||||
var userConfigLangFolder = Constants.SystemDirectories.Config
|
||||
.TrimStart(Constants.CharArrays.Tilde);
|
||||
|
||||
IEnumerable<LocalizedTextServiceSupplementaryFileSource> userLangFileSources = contentFileProvider
|
||||
.GetDirectoryContents(userConfigLangFolder)
|
||||
.Where(x => x.IsDirectory && x.Name.InvariantEquals("lang"))
|
||||
.Select(x => new DirectoryInfo(x.PhysicalPath))
|
||||
.SelectMany(x => x.GetFiles("*.user.xml", SearchOption.TopDirectoryOnly))
|
||||
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, true));
|
||||
|
||||
return pluginLangFileSources
|
||||
.Concat(userLangFileSources);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Loads the suplimentary localaization files via the file provider.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// locates all *.xml files in the lang folder of any sub folder of the one provided.
|
||||
/// e.g /app_plugins/plugin-name/lang/*.xml
|
||||
/// </remarks>
|
||||
private static IEnumerable<LocalizedTextServiceSupplementaryFileSource> GetPluginLanguageFileSources(
|
||||
IFileProvider fileProvider, string folder, bool overwriteCoreKeys)
|
||||
{
|
||||
// locate all the *.xml files inside Lang folders inside folders of the main folder
|
||||
// e.g. /app_plugins/plugin-name/lang/*.xml
|
||||
var fileSources = new List<LocalizedTextServiceSupplementaryFileSource>();
|
||||
|
||||
var pluginFolders = fileProvider.GetDirectoryContents(folder)
|
||||
.Where(x => x.IsDirectory).ToList();
|
||||
|
||||
foreach (IFileInfo pluginFolder in pluginFolders)
|
||||
{
|
||||
// get the full virtual path for the plugin folder
|
||||
var pluginFolderPath = WebPath.Combine(folder, pluginFolder.Name);
|
||||
|
||||
// get any lang folders in this plugin
|
||||
IEnumerable<IFileInfo> langFolders = fileProvider.GetDirectoryContents(pluginFolderPath)
|
||||
.Where(x => x.IsDirectory && x.Name.InvariantEquals("lang"));
|
||||
|
||||
// loop through the lang folder(s)
|
||||
// - there could be multiple on case sensitive file system
|
||||
foreach (IFileInfo langFolder in langFolders)
|
||||
builder.Services.AddTransient(sp =>
|
||||
{
|
||||
// get the full 'virtual' path of the lang folder
|
||||
var langFolderPath = WebPath.Combine(pluginFolderPath, langFolder.Name);
|
||||
return GetSupplementaryFileSources(
|
||||
sp.GetRequiredService<IWebHostEnvironment>());
|
||||
});
|
||||
|
||||
// request all the files out of the path, these will have physicalPath set.
|
||||
var files = fileProvider.GetDirectoryContents(langFolderPath)
|
||||
.Where(x => x.Name.InvariantEndsWith(".xml") && !string.IsNullOrEmpty(x.PhysicalPath))
|
||||
.Select(x => new FileInfo(x.PhysicalPath))
|
||||
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, overwriteCoreKeys))
|
||||
.ToList();
|
||||
return builder;
|
||||
}
|
||||
|
||||
// add any to our results
|
||||
if (files.Count > 0)
|
||||
|
||||
/// <summary>
|
||||
/// Loads the suplimentary localization files from plugins and user config
|
||||
/// </summary>
|
||||
private static IEnumerable<LocalizedTextServiceSupplementaryFileSource> GetSupplementaryFileSources(
|
||||
IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
IFileProvider webFileProvider = webHostEnvironment.WebRootFileProvider;
|
||||
IFileProvider contentFileProvider = webHostEnvironment.ContentRootFileProvider;
|
||||
|
||||
// gets all langs files in /app_plugins real or virtual locations
|
||||
IEnumerable<LocalizedTextServiceSupplementaryFileSource> pluginLangFileSources = GetPluginLanguageFileSources(webFileProvider, Cms.Core.Constants.SystemDirectories.AppPlugins, false);
|
||||
|
||||
// user defined langs that overwrite the default, these should not be used by plugin creators
|
||||
var userConfigLangFolder = Cms.Core.Constants.SystemDirectories.Config
|
||||
.TrimStart(Cms.Core.Constants.CharArrays.Tilde);
|
||||
|
||||
IEnumerable<LocalizedTextServiceSupplementaryFileSource> userLangFileSources = contentFileProvider.GetDirectoryContents(userConfigLangFolder)
|
||||
.Where(x => x.IsDirectory && x.Name.InvariantEquals("lang"))
|
||||
.Select(x => new DirectoryInfo(x.PhysicalPath))
|
||||
.SelectMany(x => x.GetFiles("*.user.xml", SearchOption.TopDirectoryOnly))
|
||||
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, true));
|
||||
|
||||
return pluginLangFileSources
|
||||
.Concat(userLangFileSources);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Loads the suplimentary localaization files via the file provider.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// locates all *.xml files in the lang folder of any sub folder of the one provided.
|
||||
/// e.g /app_plugins/plugin-name/lang/*.xml
|
||||
/// </remarks>
|
||||
private static IEnumerable<LocalizedTextServiceSupplementaryFileSource> GetPluginLanguageFileSources(
|
||||
IFileProvider fileProvider, string folder, bool overwriteCoreKeys)
|
||||
{
|
||||
IEnumerable<IFileInfo> pluginFolders = fileProvider
|
||||
.GetDirectoryContents(folder)
|
||||
.Where(x => x.IsDirectory);
|
||||
|
||||
foreach (IFileInfo pluginFolder in pluginFolders)
|
||||
{
|
||||
// get the full virtual path for the plugin folder
|
||||
var pluginFolderPath = WebPath.Combine(folder, pluginFolder.Name);
|
||||
|
||||
// loop through the lang folder(s)
|
||||
// - there could be multiple on case sensitive file system
|
||||
foreach (var langFolder in GetLangFolderPaths(fileProvider, pluginFolderPath))
|
||||
{
|
||||
fileSources.AddRange(files);
|
||||
// request all the files out of the path, these will have physicalPath set.
|
||||
IEnumerable<FileInfo> localizationFiles = fileProvider
|
||||
.GetDirectoryContents(langFolder)
|
||||
.Where(x => !string.IsNullOrEmpty(x.PhysicalPath))
|
||||
.Where(x => x.Name.InvariantEndsWith(".xml"))
|
||||
.Select(x => new FileInfo(x.PhysicalPath));
|
||||
|
||||
foreach (FileInfo file in localizationFiles)
|
||||
{
|
||||
yield return new LocalizedTextServiceSupplementaryFileSource(file, overwriteCoreKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fileSources;
|
||||
private static IEnumerable<string> GetLangFolderPaths(IFileProvider fileProvider, string path)
|
||||
{
|
||||
IEnumerable<IFileInfo> directories = fileProvider.GetDirectoryContents(path).Where(x => x.IsDirectory);
|
||||
|
||||
foreach (IFileInfo directory in directories)
|
||||
{
|
||||
var virtualPath = WebPath.Combine(path, directory.Name);
|
||||
|
||||
if (directory.Name.InvariantEquals("lang"))
|
||||
{
|
||||
yield return virtualPath;
|
||||
}
|
||||
|
||||
foreach (var nested in GetLangFolderPaths(fileProvider, virtualPath))
|
||||
{
|
||||
yield return nested;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
<PackageReference Include="Umbraco.Code" Version="2.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Update="Nerdbank.GitVersioning">
|
||||
<Version>3.5.107</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user