1

I am using kendo-ui for rendering some complex controls on our website mainly used for data-entry. I want to have the content of these controls being translated by sitecore and also have the controls in a separate JavaScript file.

What is the best approach to use sitecore translations and still have a speedy site?

 $("#teams").kendoDropDownList({
  dataTextField: "TeamName",
  dataValueField: "TeamId",
  optionLabel: "@Translate.Text("SelectTeam")",
  dataSource: {
    transport: {
      read: {
        type: "POST",
        url: "/api/teams",
        dataType: "json",
      }
    },
    schema: {
      type: "json",
      data: "Data",
      model: {
        fields: {
          TeamName: { field: "Name", type: "string" },
          TeamId: { field: "TeamId", type: "string" }
        }
      }
    }
  },
  change: function () {
    $("#selectedTeam").val($("#teams").val());
  }
}).data("kendoDropDownList");
5
  • Can you pass the current language to the POST call to Sitecore to get the content? Then you could either 1) override the LanguageResolver to set the Context.Language based on your form parameter, or 2) use it in your controller action to ensure you get the right language of items and translations. Feb 28 '19 at 20:53
  • The issue is that the fields are inside javascript. How can I pass all translations into the .js functions? Mar 4 '19 at 9:54
  • Can you add an example of how you are passing the fields into JS now? Where does the text come from if you don't get it from Sitecore? Is it just hardcoded? Mar 4 '19 at 12:18
  • @DanSinclair we use inline javascript in razor files which can use '@translate directly, also see the example I posted. Mar 5 '19 at 7:39
  • I would recommend doing the translation in your controller or service layer; you should not be calling translation code in your views. Then you can pass the translated values to your views thereby sending them to your JS. Mar 5 '19 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.