Add translation phrase in the default culture
I have a facet with the field set as template. The facet lists all the referred templates that are coming up in the search results page. I need to translate the template names based on the target sites language exp: "de". How can this be done? Can I extend the de.js culture file somehow?
I have added the below script at the end of my "CoveoSearch.ascx" file but it dint work for me.
The answer depends on how your search page is implemented. Is it possible to see results of multiple languages in the same search session (either with a facet to toggle the language or by avoiding to filter on the current site language)?
If you can see results from the same template but with different languages in the same result set, you need to decide whether you want to see the all the localized template names as separate facet values or to have them merged in a single facet value of a single language.
If you cannot see results of a language different than the site language once the page is loaded or if you want only one facet item per template but always localized in the current site language, you can implement the translation directly in the UI with the facet's valueCaption option. You'll need to dynamically render the JSON object to map the original strings to the localized ones on the server based on the current site language while rendering the page. This render-time operation is not optimal as it takes more time to render the page but has the advantage of having only one facet value per template. If you go with this solution, note that you will have to duplicate the facet sublayout/rendering and its ascx/cshtml file to add an
id attribute to the facet
<div> element and set its value to
Model.UniqueId because the
valueCaption option cannot be set as a
If you can see results from different languages in a single session and decide to have a facet value per language, you can store the localized template name directly in the CES indexed documents with the help of a computed field. Your computed field would read the template name of the item to be indexed and return the localized template name. You'll need to reindex all your Sitecore indexes to. You'll also need to define a new "Localized Template Name" facet field in "
/sitecore/System/Settings/Buckets/Facets" and use this facet item as the field of your UI facet.
In all the cases, you can store the translated strings in a Sitecore dictionary and use its API to get the translations.
For the dictionary to work, I believe you need to run this script before the call to
Also, for the template name facet, maybe creating the template items in all the desired languages would work. When indexing the item, I believe Coveo loads the item's template item in the item language and fallback to the default language if the specific language is not available in Sitecore.