index.dev.js 1.2 KB

123456789101112131415161718192021222324252627
  1. "use strict";
  2. //使用自执行函数,避免污染同名变量
  3. (function () {
  4. var languageList = ['zh-CN'];
  5. var LOCAL_LANGUAGE = navigator.language;
  6. var getLanguage = function getLanguage() {
  7. var language = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : localStorage.handPyLanguage || LOCAL_LANGUAGE;
  8. if (!languageList.includes(language) || !languageList.includes(language.split("-")[0])) language = 'zh-CN';
  9. var val = location.search.match(new RegExp('[?&]lang=([^&]+)'));
  10. language = val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : '';
  11. if (['en', 'zh-hant', 'zh-hans'].indexOf(language) < 0) {
  12. language = 'zh-hant';
  13. }
  14. localStorage.handPyLanguage = language;
  15. document.write('<script src="/blockly/msg/' + language + '/blockly_messages.js"><\/script>');
  16. document.write('<script src="/blockly/msg/' + language + '/blocks_messages.js"><\/script>');
  17. document.write('<script src="/blockly/msg/' + language + '/microbit_messages.js"><\/script>');
  18. document.write('<script src="/blockly/msg/' + language + '/other_messages.js"><\/script>');
  19. document.write('<script src="/blockly/msg/js/' + language + '.js"><\/script>');
  20. };
  21. getLanguage();
  22. })();