0

I have created a computed field based on media library'item path like:

    protected string GetSupportedPath => GetConfigurationValue("supportedPath")?.ToLower();    
    var sitecoreItemAbsolutePath = indexableItem.AbsolutePath.ToLower();
    
    if (!sitecoreItemAbsolutePath.Contains("/sitecore/media library/somepath") || !sitecoreItemAbsolutePath.Contains(GetSupportedPath))
    {
      return null;
    }
    
    if (sitecoreItemAbsolutePath.Contains($"{GetSupportedPath}/somepath"))
    {
      return Sitecore.Globalization.Translate.TextByDomain("SomeDomain", "someKey");
    }

The GetConfigurationValue gets the value from config files, such as a standard Coveo computed field would do. Anyway, it is working for the most part, the missing part is the media lib translation.

I am using Sitecore Dictionary, and it seems it works well for the English version. However, when it comes to a French version of the items, it is still using the English version of the Dictionary item.

  • I can validate the computed field works fine (See the indexed values on the Coveo platform, and on the views)
  • I can validate the dictionary items are being considered, as it is computed in the pipeline and are well rendered in the indexes.
  • The issue is about the Language version of the media lib item not being considered.

Any ideas?

1 Answer 1

2

You can try adding following wrapper on your code, to read translation of dictionary on media library items.

using Sitecore.ContentSearch;
using Sitecore.ContentSearch.ComputedFields;
using Sitecore.Data.Items;
using Sitecore.Globalization;

public object ComputeFieldValue(IIndexable indexable)
{
     Item item = (Item)(indexable as SitecoreIndexableItem);
     using (new LanguageSwitcher(item.Language))
     {
        return Sitecore.Globalization.Translate.TextByDomain("DictionaryDomain", "DictionaryKey");
     }
}

By adding the language switcher, this enables to return translated version of dictionary items from getTranslation pipeline.

Hope this helps!!!

2
  • It worked. I had in mind this would work, but I don't get why I have to apply this, shouldn't be supported natively ? Anyways, accepted the answer, thank you ! Commented Jun 11 at 18:53
  • @Jean-NicolasG. Glad it worked. Thank you!!! I believe you have upvoted the answer, can you please accept the answer as well so that it can be helpful to others in the community, when they face the same issue.
    – ckhanna
    Commented Jun 11 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.