From 367de2f06a80975d159fa991ca9c192a798c60fc Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Thu, 8 Aug 2019 21:33:52 +0200 Subject: [PATCH 1/2] Revert changes from #4519 --- .../Implement/LanguageRepository.cs | 1 - .../Repositories/LanguageRepositoryTest.cs | 33 ------------------- 2 files changed, 34 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs index 8429532b01f4..8597bbf19f79 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs @@ -250,7 +250,6 @@ public ILanguage GetByIsoCode(string isoCode) 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)); diff --git a/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs index 39f6e3e11406..03c1713268c3 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs @@ -79,39 +79,6 @@ public void Can_Perform_Get_By_Iso_Code_On_LanguageRepository() } } - [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() { From 1704b9d8eb53dea7aedaf4bf445e2332e5702a7d Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Thu, 8 Aug 2019 21:34:49 +0200 Subject: [PATCH 2/2] Walk up the culture tree to find a language matching the current culture when localizing the backoffice --- .../Dictionary/UmbracoCultureDictionary.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs b/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs index 6e1c35352acd..92c141263887 100644 --- a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs +++ b/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs @@ -122,7 +122,20 @@ private ILanguage Language //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(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; + }); } } }