V8: Allow localization of the backoffice using parent cultures… (#6090)

This commit is contained in:
Kenn Jacobsen
2019-08-13 20:26:22 +02:00
committed by Sebastiaan Janssen
parent 31d67161ab
commit 405538544f
3 changed files with 14 additions and 35 deletions
@@ -250,7 +250,6 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
lock (_codeIdMap)
{
if (_codeIdMap.TryGetValue(isoCode, out var id)) return id;
if (isoCode.Contains('-') && _codeIdMap.TryGetValue(isoCode.Split('-').First(), out var invariantId)) return invariantId;
}
if (throwOnNotFound)
throw new ArgumentException($"Code {isoCode} does not correspond to an existing language.", nameof(isoCode));
@@ -79,39 +79,6 @@ namespace Umbraco.Tests.Persistence.Repositories
}
}
[Test]
public void Can_Perform_Get_By_Invariant_Code_On_LanguageRepository()
{
var provider = TestObjects.GetScopeProvider(Logger);
using (var scope = provider.CreateScope())
{
var repository = CreateRepository(provider);
var es = new CultureInfo("es");
var esSpecific = new CultureInfo("es-ES");
var language = (ILanguage)new Language(es.Name)
{
CultureName = es.DisplayName,
FallbackLanguageId = 1
};
repository.Save(language);
language = repository.GetByIsoCode(es.Name);
var languageSpecific = repository.GetByIsoCode(esSpecific.Name);
// Assert
Assert.That(language, Is.Not.Null);
Assert.That(language.HasIdentity, Is.True);
Assert.That(language.IsoCode, Is.EqualTo(es.Name));
Assert.That(languageSpecific, Is.Not.Null);
Assert.That(languageSpecific.HasIdentity, Is.True);
Assert.That(languageSpecific.Id, Is.EqualTo(language.Id));
Assert.That(language.IsoCode, Is.EqualTo(language.IsoCode));
}
}
[Test]
public void Get_When_Id_Doesnt_Exist_Returns_Null()
{
@@ -122,7 +122,20 @@ namespace Umbraco.Web.Dictionary
//ensure it's stored/retrieved from request cache
//NOTE: This is no longer necessary since these are cached at the runtime level, but we can leave it here for now.
return _requestCache.GetCacheItem<ILanguage>(typeof (DefaultCultureDictionary).Name + "Culture" + Culture.Name,
() => _localizationService.GetLanguageByIsoCode(Culture.Name));
() => {
// find a language that matches the current culture or any of its parent cultures
var culture = Culture;
while(culture != CultureInfo.InvariantCulture)
{
var language = _localizationService.GetLanguageByIsoCode(culture.Name);
if(language != null)
{
return language;
}
culture = culture.Parent;
}
return null;
});
}
}
}