Browse Source

put lang in docs links

Gregg Tavares 6 years ago
parent
commit
141608280b
1 changed files with 16 additions and 2 deletions
  1. 16 2
      threejs/lessons/resources/lesson.js

+ 16 - 2
threejs/lessons/resources/lesson.js

@@ -18,8 +18,22 @@ function getQueryParams() {
 }
 }
 
 
 $(document).ready(function($){
 $(document).ready(function($){
+  const supportedLangs = {
+    'en': true,
+    'zh': true,
+  };
+
+  function insertLang(codeKeywordLinks) {
+    const lang = document.documentElement.lang.substr(0, 2).toLowerCase();
+    const langPart = `#api/${supportedLangs[lang] ? lang : 'en'}/`;
+    const langAddedLinks = {};
+    for (const [keyword, url] of Object.entries(codeKeywordLinks)) {
+      langAddedLinks[keyword] = url.replace('#api/', langPart);
+    }
+    return langAddedLinks;
+  }
 
 
-  const codeKeywordLinks = {
+  const codeKeywordLinks = insertLang({
     AnimationAction: 'https://threejs.org/docs/#api/animation/AnimationAction',
     AnimationAction: 'https://threejs.org/docs/#api/animation/AnimationAction',
     AnimationClip: 'https://threejs.org/docs/#api/animation/AnimationClip',
     AnimationClip: 'https://threejs.org/docs/#api/animation/AnimationClip',
     AnimationMixer: 'https://threejs.org/docs/#api/animation/AnimationMixer',
     AnimationMixer: 'https://threejs.org/docs/#api/animation/AnimationMixer',
@@ -265,7 +279,7 @@ $(document).ready(function($){
     PRWMLoader: 'https://threejs.org/docs/#examples/loaders/PRWMLoader',
     PRWMLoader: 'https://threejs.org/docs/#examples/loaders/PRWMLoader',
     Lensflare: 'https://threejs.org/docs/#examples/objects/Lensflare',
     Lensflare: 'https://threejs.org/docs/#examples/objects/Lensflare',
     GLTFExporter: 'https://threejs.org/docs/#examples/exporters/GLTFExporter',
     GLTFExporter: 'https://threejs.org/docs/#examples/exporters/GLTFExporter',
-  };
+  });
 
 
   function getKeywordLink(keyword) {
   function getKeywordLink(keyword) {
     const dotNdx = keyword.indexOf('.');
     const dotNdx = keyword.indexOf('.');