Use ISO codes instead of language IDs for fallback languages and translations (#13751)
* Use language ISO code for language fallback instead of language ID * Remove language and language ID from dictionary item and dictionary item translation * ADd unit test for dictionary item translation value extension * Make the internal service implementations sealed * Rename translation ISO code to be more explicit in its origin (Language) * Add breaking changes suppression * Handle save of invalid fallback iso code * Fixed test * Only allow non-UserCustomCulture's * Fixed and added tests * Rename ISO code validation method * Fix language telemetry test (create Swedish with the correct ISO code) --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -126,11 +126,7 @@ internal class LocalizationService : RepositoryService, ILocalizationService
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
IDictionaryItem? item = _dictionaryRepository.Get(id);
|
||||
|
||||
// ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(item);
|
||||
return item;
|
||||
return _dictionaryRepository.Get(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +320,7 @@ internal class LocalizationService : RepositoryService, ILocalizationService
|
||||
// mimic old Save behavior
|
||||
if (result.Status == LanguageOperationStatus.InvalidFallback)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot save language {language.IsoCode} with fallback id={language.FallbackLanguageId}.");
|
||||
throw new InvalidOperationException($"Cannot save language {language.IsoCode} with fallback {language.FallbackIsoCode}.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,31 +341,4 @@ internal class LocalizationService : RepositoryService, ILocalizationService
|
||||
return _dictionaryRepository.GetDictionaryItemKeyMap();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is here to take care of a hack - the DictionaryTranslation model contains an ILanguage reference which we
|
||||
/// don't want but
|
||||
/// we cannot remove it because it would be a large breaking change, so we need to make sure it's resolved lazily. This
|
||||
/// is because
|
||||
/// if developers have a lot of dictionary items and translations, the caching and cloning size gets much larger
|
||||
/// because of
|
||||
/// the large object graphs. So now we don't cache or clone the attached ILanguage
|
||||
/// </summary>
|
||||
private void EnsureDictionaryItemLanguageCallback(IDictionaryItem? d)
|
||||
{
|
||||
if (d is not DictionaryItem item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
item.GetLanguage = GetLanguageById;
|
||||
IEnumerable<DictionaryTranslation>? translations = item.Translations?.OfType<DictionaryTranslation>();
|
||||
if (translations is not null)
|
||||
{
|
||||
foreach (DictionaryTranslation trans in translations)
|
||||
{
|
||||
trans.GetLanguage = GetLanguageById;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user