2010-07-14 11:34:19 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2010-07-12 03:03:18 -07:00
|
|
|
|
using System.Web;
|
|
|
|
|
using JetBrains.Annotations;
|
2010-07-14 11:34:19 -07:00
|
|
|
|
using Orchard.ContentManagement;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
using Orchard.ContentManagement.Drivers;
|
|
|
|
|
using Orchard.Core.Common;
|
|
|
|
|
using Orchard.Core.Localization.Models;
|
2010-07-12 03:03:18 -07:00
|
|
|
|
using Orchard.Core.Localization.Services;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
using Orchard.Core.Localization.ViewModels;
|
2010-07-12 03:03:18 -07:00
|
|
|
|
using Orchard.Localization.Services;
|
2010-07-14 11:34:19 -07:00
|
|
|
|
using Orchard.Settings;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Localization.Drivers {
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class LocalizationDriver : ContentPartDriver<Localized> {
|
2010-07-12 03:03:18 -07:00
|
|
|
|
private readonly ICultureManager _cultureManager;
|
|
|
|
|
private readonly ILocalizationService _localizationService;
|
|
|
|
|
|
|
|
|
|
public LocalizationDriver(IOrchardServices services, ICultureManager cultureManager, ILocalizationService localizationService) {
|
|
|
|
|
_cultureManager = cultureManager;
|
|
|
|
|
_localizationService = localizationService;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
Services = services;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 11:34:19 -07:00
|
|
|
|
protected virtual ISite CurrentSite { get; private set; }
|
2010-07-09 14:14:17 -07:00
|
|
|
|
public IOrchardServices Services { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Display(Localized part, string displayType) {
|
2010-07-12 03:03:18 -07:00
|
|
|
|
var model = new ContentLocalizationsViewModel(part) {
|
|
|
|
|
Localizations = _localizationService.GetLocalizations(part.ContentItem)
|
2010-07-14 11:34:19 -07:00
|
|
|
|
.Select(c => {
|
|
|
|
|
var localized = c.ContentItem.As<Localized>();
|
|
|
|
|
if (localized.Culture == null)
|
|
|
|
|
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current)));
|
|
|
|
|
return c;
|
|
|
|
|
}).ToList()
|
2010-07-12 03:03:18 -07:00
|
|
|
|
};
|
2010-07-14 11:34:19 -07:00
|
|
|
|
|
2010-07-09 14:14:17 -07:00
|
|
|
|
return ContentPartTemplate(model, "Parts/Localization.ContentTranslations").LongestMatch(displayType, "Summary", "SummaryAdmin").Location("primary", "5");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|