U4-7873 - fix GetCulture issue with languages
This commit is contained in:
@@ -73,5 +73,47 @@ namespace Umbraco.Tests.Integration
|
||||
content.Id, content.Path, new Uri("http://domain1.fr/"));
|
||||
Assert.AreEqual("de-DE", culture.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCultureWithWildcard()
|
||||
{
|
||||
var contentTypeService = ServiceContext.ContentTypeService;
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType("umbBlah", "test Doc Type");
|
||||
contentTypeService.Save(contentType);
|
||||
var contentService = ServiceContext.ContentService;
|
||||
|
||||
var c1 = contentService.CreateContentWithIdentity("content", -1, "umbBlah");
|
||||
var c2 = contentService.CreateContentWithIdentity("content", c1, "umbBlah");
|
||||
var c3 = contentService.CreateContentWithIdentity("content", c1, "umbBlah");
|
||||
var c4 = contentService.CreateContentWithIdentity("content", c3, "umbBlah");
|
||||
|
||||
foreach (var l in ServiceContext.LocalizationService.GetAllLanguages().Where(x => x.CultureName != "en-US").ToArray())
|
||||
ServiceContext.LocalizationService.Delete(l);
|
||||
|
||||
var l0 = ServiceContext.LocalizationService.GetLanguageByIsoCode("en-US");
|
||||
var l1 = new Core.Models.Language("fr-FR");
|
||||
var l2 = new Core.Models.Language("de-DE");
|
||||
ServiceContext.LocalizationService.Save(l1);
|
||||
ServiceContext.LocalizationService.Save(l2);
|
||||
|
||||
foreach (var d in ServiceContext.DomainService.GetAll(true).ToArray())
|
||||
ServiceContext.DomainService.Delete(d);
|
||||
|
||||
ServiceContext.DomainService.Save(new UmbracoDomain("*0000") { DomainName = "*0000", RootContentId = c1.Id, LanguageId = l2.Id });
|
||||
ServiceContext.DomainService.Save(new UmbracoDomain("*0001") { DomainName = "*0001", RootContentId = c3.Id, LanguageId = l1.Id });
|
||||
//ServiceContext.DomainService.Save(new UmbracoDomain("*100112") { DomainName = "*100112", RootContentId = c3.Id, LanguageId = l2.Id });
|
||||
|
||||
var content = c2;
|
||||
var culture = Web.Models.ContentExtensions.GetCulture(null,
|
||||
ServiceContext.DomainService, ServiceContext.LocalizationService, ServiceContext.ContentService,
|
||||
content.Id, content.Path, new Uri("http://domain1.com/"));
|
||||
Assert.AreEqual("de-DE", culture.Name);
|
||||
|
||||
content = c4;
|
||||
culture = Web.Models.ContentExtensions.GetCulture(null,
|
||||
ServiceContext.DomainService, ServiceContext.LocalizationService, ServiceContext.ContentService,
|
||||
content.Id, content.Path, new Uri("http://domain1.fr/"));
|
||||
Assert.AreEqual("fr-FR", culture.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,16 +78,14 @@ namespace Umbraco.Web.Models
|
||||
domain = pos == 0
|
||||
? null
|
||||
: domainHelper.DomainForNode(int.Parse(route.Substring(0, pos)), current).UmbracoDomain;
|
||||
}
|
||||
}
|
||||
|
||||
if (domain == null || domain.LanguageIsoCode.IsNullOrWhiteSpace())
|
||||
return GetDefaultCulture(localizationService);
|
||||
var rootContentId = domain == null ? -1 : domain.RootContentId;
|
||||
var wcDomain = DomainHelper.FindWildcardDomainInPath(domainService.GetAll(true), contentPath, rootContentId);
|
||||
|
||||
var wcDomain = DomainHelper.FindWildcardDomainInPath(domainService.GetAll(true), contentPath, domain.RootContentId);
|
||||
|
||||
return wcDomain == null
|
||||
? new CultureInfo(domain.LanguageIsoCode)
|
||||
: new CultureInfo(wcDomain.LanguageIsoCode);
|
||||
if (wcDomain != null) return new CultureInfo(wcDomain.LanguageIsoCode);
|
||||
if (domain != null) return new CultureInfo(domain.LanguageIsoCode);
|
||||
return GetDefaultCulture(localizationService);
|
||||
}
|
||||
|
||||
private static CultureInfo GetDefaultCulture(ILocalizationService localizationService)
|
||||
|
||||
Reference in New Issue
Block a user