Skip to content

Commit

Permalink
V8: Allow localization of the backoffice using parent cultures… (#6090)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjac authored and nul800sebastiaan committed Aug 13, 2019
1 parent 31d6716 commit 4055385
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
15 changes: 14 additions & 1 deletion src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
});
}
}
}
Expand Down

0 comments on commit 4055385

Please sign in to comment.