Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8: Allow localization of the backoffice using parent cultures to the editor culture #6090

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
nul800sebastiaan marked this conversation as resolved.
Show resolved Hide resolved
}
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