mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding changes from Dunross and also hooking up Cache to ListCultures for perf
This commit is contained in:
@@ -39,37 +39,53 @@ namespace Orchard.Localization.Controllers {
|
||||
public ActionResult Translate(int id, string to) {
|
||||
var contentItem = _contentManager.Get(id, VersionOptions.Latest);
|
||||
|
||||
// only support translations from the site culture, at the moment at least
|
||||
if (contentItem == null)
|
||||
return HttpNotFound();
|
||||
|
||||
if (!contentItem.Is<LocalizationPart>() || contentItem.As<LocalizationPart>().MasterContentItem != null) {
|
||||
var metadata = _contentManager.GetItemMetadata(contentItem);
|
||||
return RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues);
|
||||
}
|
||||
var lp = contentItem.As<LocalizationPart>();
|
||||
|
||||
if (lp == null)
|
||||
return HttpNotFound();
|
||||
|
||||
string contentItemCulture = _localizationService.GetContentCulture(contentItem);
|
||||
var localizations = _localizationService.GetLocalizations(lp, VersionOptions.Latest);
|
||||
|
||||
var siteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
|
||||
var selectedCulture = siteCultures.SingleOrDefault(s => string.Equals(s, to, StringComparison.OrdinalIgnoreCase))
|
||||
?? _cultureManager.GetCurrentCulture(HttpContext); // could be null but the person doing the translating might be translating into their current culture
|
||||
var siteCultures = _cultureManager.ListCultures();
|
||||
|
||||
//todo: need a better solution for modifying some parts when translating - or go with a completely different experience
|
||||
/*
|
||||
if (contentItem.Has<RoutePart>()) {
|
||||
RoutePart routePart = contentItem.As<RoutePart>();
|
||||
routePart.Slug = string.Format("{0}{2}{1}", routePart.Slug, siteCultures.Any(s => string.Equals(s, selectedCulture, StringComparison.OrdinalIgnoreCase)) ? selectedCulture : "", !string.IsNullOrWhiteSpace(routePart.Slug) ? "-" : "");
|
||||
routePart.Path = null;
|
||||
}*/
|
||||
var missingCultures = siteCultures.Where(s =>
|
||||
s != contentItemCulture
|
||||
&& !localizations.Any(l => s == l.Culture.Culture))
|
||||
.ToList();
|
||||
|
||||
if (contentItem.As<LocalizationPart>().Culture != null)
|
||||
contentItem.As<LocalizationPart>().Culture.Culture = null;
|
||||
string selectedCulture = null;
|
||||
|
||||
if (!String.IsNullOrEmpty(to)) {
|
||||
|
||||
if (!siteCultures.Any(c => String.Equals(c, to, StringComparison.OrdinalIgnoreCase)))
|
||||
return HttpNotFound();
|
||||
|
||||
var existingLocalization = String.Equals(contentItemCulture, to, StringComparison.OrdinalIgnoreCase)
|
||||
? lp
|
||||
: localizations.FirstOrDefault(l => string.Equals(l.Culture.Culture, to, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (existingLocalization != null) {
|
||||
var metadata = _contentManager.GetItemMetadata(existingLocalization);
|
||||
return RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues);
|
||||
}
|
||||
|
||||
selectedCulture = missingCultures.SingleOrDefault(s => string.Equals(s, to, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
if (lp.Culture != null)
|
||||
lp.Culture.Culture = null;
|
||||
var model = new AddLocalizationViewModel {
|
||||
Id = id,
|
||||
SelectedCulture = selectedCulture,
|
||||
SiteCultures = siteCultures,
|
||||
MissingCultures = missingCultures,
|
||||
Content = _contentManager.BuildEditor(contentItem)
|
||||
};
|
||||
|
||||
// Cancel transaction so that the routepart is not modified.
|
||||
// Cancel transaction so that the LocalizationPart is not modified.
|
||||
Services.TransactionManager.Cancel();
|
||||
|
||||
return View(model);
|
||||
@@ -92,6 +108,7 @@ namespace Orchard.Localization.Controllers {
|
||||
|
||||
public ActionResult TranslatePOST(int id, Action<ContentItem> conditionallyPublish) {
|
||||
var contentItem = _contentManager.Get(id, VersionOptions.Latest);
|
||||
var originalLp = contentItem.As<LocalizationPart>();
|
||||
|
||||
if (contentItem == null)
|
||||
return HttpNotFound();
|
||||
@@ -107,9 +124,17 @@ namespace Orchard.Localization.Controllers {
|
||||
} else {
|
||||
// create
|
||||
contentItemTranslation = _contentManager.New(contentItem.ContentType);
|
||||
if (contentItemTranslation.Has<ICommonPart>() && contentItem.Has<ICommonPart>()) {
|
||||
contentItemTranslation.As<ICommonPart>().Container = contentItem.As<ICommonPart>().Container;
|
||||
}
|
||||
|
||||
LocalizationPart translationLp = contentItemTranslation.As<LocalizationPart>();
|
||||
|
||||
translationLp.MasterContentItem = originalLp.MasterContentItem != null
|
||||
? originalLp.MasterContentItem
|
||||
: contentItem;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(model.SelectedCulture))
|
||||
{
|
||||
translationLp.Culture = _cultureManager.GetCultureByName(model.SelectedCulture);
|
||||
}
|
||||
|
||||
_contentManager.Create(contentItemTranslation, VersionOptions.Draft);
|
||||
}
|
||||
@@ -118,8 +143,10 @@ namespace Orchard.Localization.Controllers {
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
model.SiteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
|
||||
var culture = contentItem.As<LocalizationPart>().Culture;
|
||||
model.MissingCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
|
||||
|
||||
var culture = originalLp.Culture;
|
||||
|
||||
if (culture != null) {
|
||||
culture.Culture = null;
|
||||
}
|
||||
@@ -131,12 +158,6 @@ namespace Orchard.Localization.Controllers {
|
||||
Services.Notifier.Information(T("Edited content item translation."));
|
||||
}
|
||||
else {
|
||||
LocalizationPart localized = contentItemTranslation.As<LocalizationPart>();
|
||||
localized.MasterContentItem = contentItem;
|
||||
if (!string.IsNullOrWhiteSpace(model.SelectedCulture)) {
|
||||
localized.Culture = _cultureManager.GetCultureByName(model.SelectedCulture);
|
||||
}
|
||||
|
||||
conditionallyPublish(contentItemTranslation);
|
||||
|
||||
Services.Notifier.Information(T("Created content item translation."));
|
||||
|
@@ -22,30 +22,27 @@ namespace Orchard.Localization.Drivers {
|
||||
}
|
||||
|
||||
protected override DriverResult Display(LocalizationPart part, string displayType, dynamic shapeHelper) {
|
||||
if (!IsActivatable())
|
||||
return null;
|
||||
|
||||
var masterId = part.MasterContentItem != null
|
||||
? part.MasterContentItem.Id
|
||||
: part.Id;
|
||||
|
||||
var siteCultures = _cultureManager.ListCultures();
|
||||
|
||||
return Combined(
|
||||
ContentShape("Parts_Localization_ContentTranslations",
|
||||
() => shapeHelper.Parts_Localization_ContentTranslations(MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
|
||||
() => shapeHelper.Parts_Localization_ContentTranslations(Id: part.ContentItem.Id, MasterId: masterId, Culture: GetCulture(part), Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
|
||||
ContentShape("Parts_Localization_ContentTranslations_Summary",
|
||||
() => shapeHelper.Parts_Localization_ContentTranslations_Summary(MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
|
||||
() => shapeHelper.Parts_Localization_ContentTranslations_Summary(Id: part.ContentItem.Id, MasterId: masterId, Culture: GetCulture(part), Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
|
||||
ContentShape("Parts_Localization_ContentTranslations_SummaryAdmin",
|
||||
() => shapeHelper.Parts_Localization_ContentTranslations_SummaryAdmin(MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Latest)))
|
||||
() => shapeHelper.Parts_Localization_ContentTranslations_SummaryAdmin(Id: part.ContentItem.Id, MasterId: masterId, Culture: GetCulture(part), Localizations: GetDisplayLocalizations(part, VersionOptions.Latest), SiteCultures: siteCultures))
|
||||
);
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(LocalizationPart part, dynamic shapeHelper) {
|
||||
if (!IsActivatable())
|
||||
return null;
|
||||
|
||||
var localizations = GetEditorLocalizations(part).ToList();
|
||||
var model = new EditLocalizationViewModel {
|
||||
SelectedCulture = part.Culture != null ? part.Culture.Culture : null,
|
||||
SiteCultures = _cultureManager.ListCultures().Where(s => s != _cultureManager.GetSiteCulture() && !localizations.Select(l => l.Culture.Culture).Contains(s)),
|
||||
SelectedCulture = GetCulture(part),
|
||||
SiteCultures = _cultureManager.ListCultures().Where(s => !localizations.Any(l => l.Culture.Culture == s)).ToList(),
|
||||
ContentItem = part,
|
||||
MasterContentItem = part.MasterContentItem,
|
||||
ContentLocalizations = new ContentLocalizationsViewModel(part) { Localizations = localizations }
|
||||
@@ -56,9 +53,6 @@ namespace Orchard.Localization.Drivers {
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(LocalizationPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
if (!IsActivatable())
|
||||
return null;
|
||||
|
||||
var model = new EditLocalizationViewModel();
|
||||
if (updater != null && updater.TryUpdateModel(model, TemplatePrefix, null, null)) {
|
||||
_localizationService.SetContentCulture(part, model.SelectedCulture);
|
||||
@@ -67,8 +61,8 @@ namespace Orchard.Localization.Drivers {
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
|
||||
private bool IsActivatable() {
|
||||
return _cultureManager.ListCultures().Count() > 1;
|
||||
private static string GetCulture(LocalizationPart part) {
|
||||
return part.Culture != null ? part.Culture.Culture : null;
|
||||
}
|
||||
|
||||
private IEnumerable<LocalizationPart> GetDisplayLocalizations(LocalizationPart part, VersionOptions versionOptions) {
|
||||
|
@@ -48,7 +48,7 @@ namespace Orchard.Localization.Handlers {
|
||||
_cultureManager.GetCultureById(localizationPart.Record.CultureId));
|
||||
|
||||
localizationPart.MasterContentItemField.Loader(ctx =>
|
||||
_contentManager.Get(localizationPart.Record.MasterContentItemId, localizationPart.IsPublished() ? VersionOptions.Published : VersionOptions.Latest));
|
||||
_contentManager.Get(localizationPart.Record.MasterContentItemId, VersionOptions.AllVersions));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,9 +4,11 @@ using Orchard.Localization.Models;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
public interface ILocalizationService : IDependency {
|
||||
LocalizationPart GetLocalizedContentItem(IContent masterContentItem, string culture);
|
||||
string GetContentCulture(IContent contentItem);
|
||||
void SetContentCulture(IContent contentItem, string culture);
|
||||
IEnumerable<LocalizationPart> GetLocalizations(IContent contentItem, VersionOptions versionOptions);
|
||||
LocalizationPart GetLocalizedContentItem(IContent content, string culture);
|
||||
LocalizationPart GetLocalizedContentItem(IContent content, string culture, VersionOptions versionOptions);
|
||||
string GetContentCulture(IContent content);
|
||||
void SetContentCulture(IContent content, string culture);
|
||||
IEnumerable<LocalizationPart> GetLocalizations(IContent content);
|
||||
IEnumerable<LocalizationPart> GetLocalizations(IContent content, VersionOptions versionOptions);
|
||||
}
|
||||
}
|
||||
|
@@ -14,49 +14,82 @@ namespace Orchard.Localization.Services {
|
||||
}
|
||||
|
||||
LocalizationPart ILocalizationService.GetLocalizedContentItem(IContent content, string culture) {
|
||||
// Warning: Returns only the first of same culture localizations.
|
||||
return ((ILocalizationService) this).GetLocalizedContentItem(content, culture, null);
|
||||
}
|
||||
|
||||
LocalizationPart ILocalizationService.GetLocalizedContentItem(IContent content, string culture, VersionOptions versionOptions) {
|
||||
var cultureRecord = _cultureManager.GetCultureByName(culture);
|
||||
|
||||
if (cultureRecord == null)
|
||||
return null;
|
||||
|
||||
return _contentManager.Query(content.ContentItem.ContentType)
|
||||
.Where<LocalizationPartRecord>(l => l.MasterContentItemId == content.ContentItem.Id && l.CultureId == cultureRecord.Id)
|
||||
var localized = content.As<LocalizationPart>();
|
||||
|
||||
if (localized == null)
|
||||
return null;
|
||||
|
||||
var query = versionOptions == null
|
||||
? _contentManager.Query(content.ContentItem.ContentType)
|
||||
: _contentManager.Query(versionOptions, content.ContentItem.ContentType);
|
||||
|
||||
// Warning: Returns only the first of same culture localizations.
|
||||
return query.Where<LocalizationPartRecord>(l =>
|
||||
(l.Id == content.ContentItem.Id || l.MasterContentItemId == content.ContentItem.Id)
|
||||
&& l.CultureId == cultureRecord.Id)
|
||||
.List()
|
||||
.Select(i => i.As<LocalizationPart>())
|
||||
.SingleOrDefault();
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
string ILocalizationService.GetContentCulture(IContent content) {
|
||||
var localized = content.As<LocalizationPart>();
|
||||
return localized != null && localized.Culture != null
|
||||
? localized.Culture.Culture
|
||||
: _cultureManager.GetSiteCulture();
|
||||
? localized.Culture.Culture
|
||||
: _cultureManager.GetSiteCulture();
|
||||
}
|
||||
|
||||
void ILocalizationService.SetContentCulture(IContent content, string culture) {
|
||||
var localized = content.As<LocalizationPart>();
|
||||
if (localized == null || localized.MasterContentItem == null)
|
||||
if (localized == null)
|
||||
return;
|
||||
|
||||
localized.Culture = _cultureManager.GetCultureByName(culture);
|
||||
var cultureRecord = _cultureManager.GetCultureByName(culture);
|
||||
|
||||
localized.Culture = cultureRecord;
|
||||
}
|
||||
|
||||
IEnumerable<LocalizationPart> ILocalizationService.GetLocalizations(IContent content) {
|
||||
// Warning: May contain more than one localization of the same culture.
|
||||
return ((ILocalizationService) this).GetLocalizations(content, null);
|
||||
}
|
||||
|
||||
IEnumerable<LocalizationPart> ILocalizationService.GetLocalizations(IContent content, VersionOptions versionOptions) {
|
||||
if (content.ContentItem.Id == 0)
|
||||
return Enumerable.Empty<LocalizationPart>();
|
||||
|
||||
var localized = content.As<LocalizationPart>();
|
||||
|
||||
if (localized.MasterContentItem != null)
|
||||
return _contentManager.Query(versionOptions, localized.ContentItem.ContentType)
|
||||
.Where<LocalizationPartRecord>(l =>
|
||||
l.Id != localized.ContentItem.Id
|
||||
&& (l.Id == localized.MasterContentItem.ContentItem.Id
|
||||
|| l.MasterContentItemId == localized.MasterContentItem.ContentItem.Id))
|
||||
.List()
|
||||
.Select(i => i.As<LocalizationPart>());
|
||||
var query = versionOptions == null
|
||||
? _contentManager.Query(localized.ContentItem.ContentType)
|
||||
: _contentManager.Query(versionOptions, localized.ContentItem.ContentType);
|
||||
|
||||
return _contentManager.Query(versionOptions, localized.ContentItem.ContentType)
|
||||
.Where<LocalizationPartRecord>(l => l.MasterContentItemId == localized.ContentItem.Id)
|
||||
.List()
|
||||
.Select(i => i.As<LocalizationPart>());
|
||||
int contentItemId = localized.ContentItem.Id;
|
||||
|
||||
if (localized.MasterContentItem != null) {
|
||||
int masterContentItemId = localized.MasterContentItem.ContentItem.Id;
|
||||
|
||||
query = query.Where<LocalizationPartRecord>(l =>
|
||||
l.Id != contentItemId // Exclude the content
|
||||
&& (l.Id == masterContentItemId || l.MasterContentItemId == masterContentItemId));
|
||||
}
|
||||
else {
|
||||
query = query.Where<LocalizationPartRecord>(l =>
|
||||
l.MasterContentItemId == contentItemId);
|
||||
}
|
||||
|
||||
// Warning: May contain more than one localization of the same culture.
|
||||
return query.List().Select(i => i.As<LocalizationPart>());
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@ namespace Orchard.Localization.ViewModels {
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string SelectedCulture { get; set; }
|
||||
public IEnumerable<string> SiteCultures { get; set; }
|
||||
public IEnumerable<string> MissingCultures { get; set; }
|
||||
public IContent Content { get; set; }
|
||||
}
|
||||
}
|
@@ -4,13 +4,9 @@
|
||||
}
|
||||
<fieldset class="localization culture-selection">
|
||||
<label for="SelectedCulture">@T("Content Localization")</label>
|
||||
@{
|
||||
var siteCultures = Model.SiteCultures.ToList();
|
||||
siteCultures.Insert(0, "");
|
||||
}
|
||||
<div>
|
||||
@T("This is the <em>{0}</em> variation of {1}",
|
||||
Html.DropDownList("SelectedCulture", new SelectList(siteCultures, Model.SelectedCulture)),
|
||||
Html.DropDownList("SelectedCulture", new SelectList(Model.MissingCultures, Model.SelectedCulture)),
|
||||
Html.ItemEditLink(Model.Content))
|
||||
</div>
|
||||
</fieldset>
|
@@ -1,22 +1,36 @@
|
||||
@model Orchard.Localization.ViewModels.EditLocalizationViewModel
|
||||
<fieldset class="localization culture-selection">
|
||||
@if (Model.ContentItem.ContentItem.Id > 0 && Model.SelectedCulture != null && Model.ContentLocalizations.Localizations.Count() > 0) {
|
||||
@using System.Linq;
|
||||
@{
|
||||
Style.Require("LocalizationAdmin");
|
||||
<fieldset class="culture-selected">
|
||||
<label for="SelectedCulture">@T("Content Localization")</label>
|
||||
<div>@T("This is the <em>{0}</em> variation of {1}.",
|
||||
Html.Encode(Model.SelectedCulture),
|
||||
Html.ItemEditLink(Model.MasterContentItem ?? Model.ContentItem))</div>
|
||||
@Html.Hidden("SelectedCulture", Model.SelectedCulture)
|
||||
</fieldset>
|
||||
if (Model.ContentLocalizations.Localizations.Count() > 0) {
|
||||
<dl class="content-localization">
|
||||
<dt>@T("Other translations:")</dt>
|
||||
<dd class="content-localizations">
|
||||
@Html.UnorderedList(Model.ContentLocalizations.Localizations, (c, i) => Html.ItemEditLink(c.Culture.Culture, c), "localizations")
|
||||
</dd>
|
||||
</dl>
|
||||
var siteCultures = Model.SiteCultures.ToList();
|
||||
}
|
||||
<fieldset class="localization culture-selection">
|
||||
@if (Model.ContentItem.ContentItem.Id == 0 || Model.ContentLocalizations.Localizations.Count() == 0) {
|
||||
<fieldset class="localization culture-selection">
|
||||
<label for="SelectedCulture">@T("Content Localization")</label>
|
||||
<div>
|
||||
@T("This is the <em>{0}</em> variation of the content",
|
||||
Html.DropDownList("SelectedCulture", new SelectList(siteCultures, Model.SelectedCulture)))
|
||||
</div>
|
||||
</fieldset>
|
||||
} else {
|
||||
<fieldset class="culture-selected">
|
||||
<label for="SelectedCulture">@T("Content Localization")</label>
|
||||
<div>
|
||||
@T("This is the <em>{0}</em> variation of the content.",
|
||||
Html.Encode(Model.SelectedCulture))
|
||||
</div>
|
||||
@Html.Hidden("SelectedCulture", Model.SelectedCulture)
|
||||
</fieldset>
|
||||
<dl class="content-localization">
|
||||
<dt>@T("Other translations:")</dt>
|
||||
<dd class="content-localizations">
|
||||
@Html.UnorderedList(Model.ContentLocalizations.Localizations, (c, i) => Html.ItemEditLink(c.Culture.Culture, c), "localizations")
|
||||
</dd>
|
||||
</dl>
|
||||
}
|
||||
|
||||
@if (Model.SelectedCulture != null && !siteCultures.All(c => c == Model.SelectedCulture || Model.ContentLocalizations.Localizations.Any(l => c == l.Culture.Culture))) {
|
||||
<div class="add-localization">@Html.ActionLink(T("+ New translation").Text, "Translate", "Admin", new { area = "Orchard.Localization", id = Model.ContentItem.Id }, null)</div>
|
||||
}
|
||||
}
|
||||
<div class="add-localization">@Html.ActionLink(T("+ New translation").Text, "Translate", "Admin", new { area = "Orchard.Localization", id = Model.ContentItem.Id }, null)</div>
|
||||
</fieldset>
|
||||
|
@@ -5,9 +5,18 @@ Style.Require("LocalizationAdmin");
|
||||
IEnumerable<LocalizationPart> localizations = Model.Localizations;
|
||||
var localizationLinks = Html.UnorderedList(localizations, (c, i) => Html.ItemEditLink(c.Culture.Culture, c), "localizations");
|
||||
<div class="content-localization">
|
||||
@if (localizations.Count() > 0) {
|
||||
@if (Model.Culture != null) {
|
||||
<div class="content-culture">@T("Culture: {0}", Model.Culture)</div>
|
||||
} else {
|
||||
<div class="content-culture">@T("Culture: {0}", T("Undefined"))</div>
|
||||
}
|
||||
@if (localizations.Count() > 0)
|
||||
{
|
||||
<div class="content-localizations"><h4>@T("Translations:")</h4>@localizationLinks</div>
|
||||
}
|
||||
<div class="add-localization">@Html.ActionLink(T("+ New translation").Text, "Translate", "Admin", new { area = "Orchard.Localization", id = Model.MasterId }, null)</div>
|
||||
@if (Model.Culture != null && !((IEnumerable<string>)Model.SiteCultures).All(c => c == Model.Culture || localizations.Any(l => c == l.Culture.Culture)))
|
||||
{
|
||||
<div class="add-localization">@Html.ActionLink(T("+ New translation").Text, "Translate", "Admin", new { area = "Orchard.Localization", id = Model.Id }, null)</div>
|
||||
}
|
||||
</div>
|
||||
}
|
@@ -12,30 +12,34 @@ namespace Orchard.Localization.Services {
|
||||
private readonly IEnumerable<ICultureSelector> _cultureSelectors;
|
||||
private readonly ISignals _signals;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly ICacheManager _cacheManager;
|
||||
|
||||
public DefaultCultureManager(IRepository<CultureRecord> cultureRepository,
|
||||
IEnumerable<ICultureSelector> cultureSelectors,
|
||||
ISignals signals,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
ICacheManager cacheManager) {
|
||||
_cultureRepository = cultureRepository;
|
||||
_cultureSelectors = cultureSelectors;
|
||||
_signals = signals;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListCultures() {
|
||||
var query = from culture in _cultureRepository.Table select culture.Culture;
|
||||
return query.ToList();
|
||||
return _cacheManager.Get("Cultures", context => {
|
||||
context.Monitor(_signals.When("culturesChanged"));
|
||||
|
||||
return _cultureRepository.Table.Select(o => o.Culture).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
public void AddCulture(string cultureName) {
|
||||
if (!IsValidCulture(cultureName)) {
|
||||
throw new ArgumentException("cultureName");
|
||||
}
|
||||
|
||||
var culture = _cultureRepository.Get(cr => cr.Culture == cultureName);
|
||||
|
||||
if (culture != null) {
|
||||
if (ListCultures().Any(culture => culture == cultureName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,8 +52,8 @@ namespace Orchard.Localization.Services {
|
||||
throw new ArgumentException("cultureName");
|
||||
}
|
||||
|
||||
var culture = _cultureRepository.Get(cr => cr.Culture == cultureName);
|
||||
if (culture != null) {
|
||||
if (ListCultures().Any(culture => culture == cultureName)) {
|
||||
var culture = _cultureRepository.Get(cr => cr.Culture == cultureName);
|
||||
_cultureRepository.Delete(culture);
|
||||
_signals.Trigger("culturesChanged");
|
||||
}
|
||||
|
Reference in New Issue
Block a user