mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
- More work on the citem localization, still early stages (updates to services and models).
--HG-- branch : dev
This commit is contained in:
@@ -5,5 +5,16 @@ namespace Orchard.Core.Localization.Models {
|
||||
public sealed class Localized : ContentPart<LocalizedRecord> {
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id { get { return ContentItem.Id; } }
|
||||
|
||||
public int CultureId {
|
||||
get { return Record.CultureId; }
|
||||
set { Record.CultureId = value; }
|
||||
}
|
||||
|
||||
public int MasterContentItemId {
|
||||
get { return Record.MasterContentItemId; }
|
||||
set { Record.MasterContentItemId = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,7 @@
|
||||
|
||||
namespace Orchard.Core.Localization.Models {
|
||||
public class LocalizedRecord : ContentPartRecord {
|
||||
public virtual int CultureId { get; set; }
|
||||
public virtual int MasterContentItemId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Localization.Models;
|
||||
using Orchard.Localization.Services;
|
||||
using Localized = Orchard.Core.Localization.Models.Localized;
|
||||
|
||||
namespace Orchard.Core.Localization.Services {
|
||||
[UsedImplicitly]
|
||||
public class ContentItemLocalizationService : IContentItemLocalizationService {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly ICultureManager _cultureManager;
|
||||
|
||||
public ContentItemLocalizationService(IContentManager contentManager, ICultureManager cultureManager) {
|
||||
_contentManager = contentManager;
|
||||
_cultureManager = cultureManager;
|
||||
}
|
||||
|
||||
public IEnumerable<Localized> Get() {
|
||||
return _contentManager.Query<Localized, LocalizedRecord>().List();
|
||||
}
|
||||
|
||||
public Localized Get(int localizedId) {
|
||||
return _contentManager.Get<Localized>(localizedId);
|
||||
}
|
||||
|
||||
public Localized GetLocalizationForCulture(int masterId, string cultureName) {
|
||||
var cultures = _cultureManager.ListCultures();
|
||||
if (cultures.Contains(cultureName)) {
|
||||
int cultureId = _cultureManager.GetCultureIdByName(cultureName);
|
||||
if (cultureId != 0) {
|
||||
return _contentManager.Query<Localized, LocalizedRecord>()
|
||||
.Where(x => x.MasterContentItemId == masterId && x.CultureId == cultureId).List().FirstOrDefault();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
namespace Orchard.Core.Localization.Services {
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Core.Localization.Models;
|
||||
|
||||
namespace Orchard.Core.Localization.Services {
|
||||
public interface IContentItemLocalizationService : IDependency {
|
||||
IEnumerable<Localized> Get();
|
||||
Localized Get(int localizedId);
|
||||
Localized GetLocalizationForCulture(int masterId, string cultureName);
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,7 @@
|
||||
<Compile Include="Indexing\Services\IndexingTaskManager.cs" />
|
||||
<Compile Include="Localization\Models\Localized.cs" />
|
||||
<Compile Include="Localization\Models\LocalizedRecord.cs" />
|
||||
<Compile Include="Localization\Services\ContentItemLocalizationService.cs" />
|
||||
<Compile Include="Localization\Services\IContentItemLocalizationService.cs" />
|
||||
<Compile Include="Navigation\AdminMenu.cs" />
|
||||
<Compile Include="Navigation\Controllers\AdminController.cs" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
@@ -46,6 +47,13 @@ namespace Orchard.Localization.Services {
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public int GetCultureIdByName(string cultureName) {
|
||||
if (!IsValidCulture(cultureName)) {
|
||||
throw new ArgumentException("cultureName");
|
||||
}
|
||||
return _cultureRepository.Get(x => x.Culture == cultureName).Id;
|
||||
}
|
||||
|
||||
// "<languagecode2>" or
|
||||
// "<languagecode2>-<country/regioncode2>" or
|
||||
// "<languagecode2>-<scripttag>-<country/regioncode2>"
|
||||
|
||||
@@ -6,5 +6,6 @@ namespace Orchard.Localization.Services {
|
||||
IEnumerable<string> ListCultures();
|
||||
void AddCulture(string cultureName);
|
||||
string GetCurrentCulture(HttpContext requestContext);
|
||||
int GetCultureIdByName(string cultureName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user