From 405538544f9a778a4f0ddd625280abfa6f2a7d4c Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Tue, 13 Aug 2019 20:26:22 +0200 Subject: [PATCH] =?UTF-8?q?V8:=20Allow=20localization=20of=20the=20backoff?= =?UTF-8?q?ice=20using=20parent=20cultures=E2=80=A6=20(#6090)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implement/LanguageRepository.cs | 1 - .../Repositories/LanguageRepositoryTest.cs | 33 ------------------- .../Dictionary/UmbracoCultureDictionary.cs | 15 ++++++++- 3 files changed, 14 insertions(+), 35 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() { 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; + }); } } }