index.js 1.1 KB

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