Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • bryansoo2503 2 posts 22 karma points
    Jun 26, 2023 @ 05:10
    bryansoo2503
    0

    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:

    enter image description here

    enter image description here

    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;
    }
    

    Cheers, Bryan

  • bryansoo2503 2 posts 22 karma points
    Jun 26, 2023 @ 08:56
    bryansoo2503
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft