Merge branch 'v8-fix-localize-content-apps' of https://github.com/kjac/Umbraco-CMS into kjac-v8-fix-localize-content-apps

This commit is contained in:
Claus
2019-02-14 10:35:52 +01:00
4 changed files with 32 additions and 3 deletions

View File

@@ -1,7 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Core.Services;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Models.ContentEditing;
@@ -12,15 +15,29 @@ namespace Umbraco.Web.Models.Mapping
internal class ContentAppResolver : IValueResolver<IContent, ContentItemDisplay, IEnumerable<ContentApp>>
{
private readonly ContentAppFactoryCollection _contentAppDefinitions;
private readonly ILocalizedTextService _localizedTextService;
public ContentAppResolver(ContentAppFactoryCollection contentAppDefinitions)
public ContentAppResolver(ContentAppFactoryCollection contentAppDefinitions, ILocalizedTextService localizedTextService)
{
_contentAppDefinitions = contentAppDefinitions;
_localizedTextService = localizedTextService;
}
public IEnumerable<ContentApp> Resolve(IContent source, ContentItemDisplay destination, IEnumerable<ContentApp> destMember, ResolutionContext context)
{
return _contentAppDefinitions.GetContentAppsFor(source);
var apps = _contentAppDefinitions.GetContentAppsFor(source).ToArray();
// localize content app names
foreach (var app in apps)
{
var localizedAppName = _localizedTextService.Localize($"apps/{app.Alias}");
if (localizedAppName.Equals($"[{app.Alias}]", StringComparison.OrdinalIgnoreCase) == false)
{
app.Name = localizedAppName;
}
}
return apps;
}
}
}