mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixes to localizationservice to get with of silly select..
This commit is contained in:
@@ -58,6 +58,7 @@ namespace Orchard.Tests.Localization {
|
||||
builder.RegisterType<TestCultureSelector>().As<ICultureSelector>();
|
||||
builder.RegisterType<DefaultCultureManager>().As<ICultureManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
||||
_session = _sessionFactory.OpenSession();
|
||||
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();
|
||||
|
@@ -16,6 +16,8 @@ namespace Orchard.Localization.Selectors {
|
||||
}
|
||||
|
||||
public CultureSelectorResult GetCulture(HttpContextBase context) {
|
||||
if (context == null) return null;
|
||||
|
||||
/* Fall back to Browser */
|
||||
var userLanguages = context.Request.UserLanguages;
|
||||
|
||||
|
@@ -23,8 +23,7 @@ namespace Orchard.Localization.Selectors {
|
||||
}
|
||||
|
||||
public CultureSelectorResult GetCulture(HttpContextBase context) {
|
||||
if (ContextHelpers.IsRequestAdmin(context))
|
||||
return null;
|
||||
if (context == null || ContextHelpers.IsRequestAdmin(context)) return null;
|
||||
|
||||
// Attempt to determine culture by previous route if by POST
|
||||
string path;
|
||||
|
@@ -48,6 +48,8 @@ namespace Orchard.Localization.Selectors {
|
||||
}
|
||||
|
||||
public CultureSelectorResult GetCulture(HttpContextBase context) {
|
||||
if (context == null) return null;
|
||||
|
||||
var cookie = context.Request.Cookies.Get(CookieName);
|
||||
|
||||
if (cookie != null)
|
||||
|
@@ -7,8 +7,7 @@ namespace Orchard.Localization.Selectors {
|
||||
[OrchardFeature("Orchard.Localization.CutlureSelector")]
|
||||
public class RouteCultureSelector : ICultureSelector {
|
||||
public CultureSelectorResult GetCulture(HttpContextBase context) {
|
||||
if (ContextHelpers.IsRequestAdmin(context))
|
||||
return null;
|
||||
if (context == null || ContextHelpers.IsRequestAdmin(context)) return null;
|
||||
|
||||
// Attempt to determine culture by route.
|
||||
// This normally happens when you are using non standard pages that are not content items
|
||||
|
@@ -30,15 +30,14 @@ namespace Orchard.Localization.Services {
|
||||
return null;
|
||||
|
||||
var query = versionOptions == null
|
||||
? _contentManager.Query(content.ContentItem.ContentType)
|
||||
: _contentManager.Query(versionOptions, content.ContentItem.ContentType);
|
||||
? _contentManager.Query<LocalizationPart>(content.ContentItem.ContentType)
|
||||
: _contentManager.Query<LocalizationPart>(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>())
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -54,9 +53,7 @@ namespace Orchard.Localization.Services {
|
||||
if (localized == null)
|
||||
return;
|
||||
|
||||
var cultureRecord = _cultureManager.GetCultureByName(culture);
|
||||
|
||||
localized.Culture = cultureRecord;
|
||||
localized.Culture = _cultureManager.GetCultureByName(culture);
|
||||
}
|
||||
|
||||
IEnumerable<LocalizationPart> ILocalizationService.GetLocalizations(IContent content) {
|
||||
@@ -71,12 +68,12 @@ namespace Orchard.Localization.Services {
|
||||
var localized = content.As<LocalizationPart>();
|
||||
|
||||
var query = versionOptions == null
|
||||
? _contentManager.Query(localized.ContentItem.ContentType)
|
||||
: _contentManager.Query(versionOptions, localized.ContentItem.ContentType);
|
||||
? _contentManager.Query<LocalizationPart>(localized.ContentItem.ContentType)
|
||||
: _contentManager.Query<LocalizationPart>(versionOptions, localized.ContentItem.ContentType);
|
||||
|
||||
int contentItemId = localized.ContentItem.Id;
|
||||
|
||||
if (localized.MasterContentItem != null) {
|
||||
if (localized.HasTranslationGroup) {
|
||||
int masterContentItemId = localized.MasterContentItem.ContentItem.Id;
|
||||
|
||||
query = query.Where<LocalizationPartRecord>(l =>
|
||||
@@ -89,7 +86,7 @@ namespace Orchard.Localization.Services {
|
||||
}
|
||||
|
||||
// Warning: May contain more than one localization of the same culture.
|
||||
return query.List().Select(i => i.As<LocalizationPart>());
|
||||
return query.List().ToList();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user