Hey everyone, I'm currently using Umbraco v11.3.1 on .net7.0, and I'm developing a translation feature for my build. While implementing this feature, I encountered a deprecated warning when I'm querying the ILanguage property of an IEnumerable of IDictionaryTranslations like below:
Since IDictionaryTranslations.Language is going to be obsolete, I'd like to update my code to use the ILanguageService, but I could not find much information about the ILanguageService that we are meant to use.
There is a .net documentation about ILanguageService that is applicable up to .net4.6 but it is an empty interface. Could someone point me to the intended ILanguageService that this warning is referring to?
Here is the implementation of the translation:
public Dictionary<string, string?> GetTranslationByKeys(string? cultureCode = null, params string[] keys)
{
if (string.IsNullOrEmpty(cultureCode))
cultureCode = _localizationService.GetDefaultLanguageIsoCode();
var dictionary = new Dictionary<string, string?>();
foreach (var key in keys)
{
var dictionaryItem = _localizationService.GetDictionaryItemByKey(key);
if (dictionaryItem != null)
{
var translation = dictionaryItem.Translations.FirstOrDefault(x => x.Language!.CultureInfo!.Name == cultureCode); //the culprit in question
if (translation != null)
{
dictionary.Add(key, translation.Value);
}
else
{
dictionary.Add(key, "");
}
}
else
{
dictionary.Add(key, "");
}
}
return dictionary;
}
IDictionaryTranslation.Language deprecated
Hey everyone, I'm currently using Umbraco v11.3.1 on .net7.0, and I'm developing a translation feature for my build. While implementing this feature, I encountered a deprecated warning when I'm querying the ILanguage property of an IEnumerable of IDictionaryTranslations like below:
Since IDictionaryTranslations.Language is going to be obsolete, I'd like to update my code to use the ILanguageService, but I could not find much information about the ILanguageService that we are meant to use.
There is a .net documentation about ILanguageService that is applicable up to .net4.6 but it is an empty interface. Could someone point me to the intended ILanguageService that this warning is referring to?
Here is the implementation of the translation:
Cheers, Bryan
Hey everyone, update to this:
For the time being the deprecated warnings can be ignored, but in future versions of Umbraco there will be changes to how the Languages are retrieved:
https://github.com/umbraco/Umbraco-CMS/pull/13753#issuecomment-1599091466
Cheers to the Umbraco devs who helped me out!
is working on a reply...