This is a migrated thread and some comments may be shown as answers.

How to load kendo.messages.xx-xx.min.js files from local disk when localization

2 Answers 137 Views
Globalization
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 26 Oct 2018, 08:02 AM

I am trying to load the culture files(kendo.messages.xx-xx.min.js) from the local disk, is there a good way to do that?

The method you provided is like following:

var baseUrl = 'https://kendo.cdn.telerik.com/2018.3.1017/js/messages/kendo.messages.';
$.getScript(baseUrl + "zh-CN.min.js", function () {
kendo.ui.progress($("#grid"), false);
CreateGrid();
});

 

I would like to load it like following, but it didn't work for me.

$.getScript("../culture/zh-CN.min.js", function () {
kendo.ui.progress($("#grid"), false);
CreateGrid();
});

2 Answers, 1 is accepted

Sort by
0
Nick
Top achievements
Rank 1
answered on 26 Oct 2018, 08:06 AM
Sorry, post on the wrong place.
0
Dimitar
Telerik team
answered on 29 Oct 2018, 02:23 PM
Hello Nick,

The jQuery $.getScript() method triggers an ajax request to load the script. Ajax calls are not allowed by default to fetch contents from your hard drive for security reasons. Therefore, to inject script files to the page, I would suggest to create a unique div at the start of the <body tag> of the application:
<body>
  <div id="locale">
    <script src="defaultLocaleUrl"></script>
  </div>
  ...
</body>

Then, simply inject the script in the locale div:
function changeLanguage(e) {          
  var baseUrl = '....';
                   
  var newLocaleScript = document.createElement("script");                           
  newLocaleScript.src = baseUrl + this.value() + ".min.js";
                   
  $("#locale").html(newLocaleScript);             
                 
  setTimeout(function() {                 
    createGrid(); 
  }, 500);                                  
}

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Globalization
Asked by
Nick
Top achievements
Rank 1
Answers by
Nick
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or