Browse Source

Docs: Automatically set language from hash.

Mr.doob 6 years ago
parent
commit
f3e697fc5e
1 changed files with 17 additions and 5 deletions
  1. 17 5
      docs/index.html

+ 17 - 5
docs/index.html

@@ -54,18 +54,30 @@
 
 			var hash = window.location.hash.substring( 1 );
 
-			// Route non-localised api links
+			// Localisation
 
-			if ( /^(api|manual)/.test( hash ) && /^(api|manual)\/(en|zh)\//.test( hash ) === false ) {
+			var language = 'en';
+
+			if ( /^(api|manual)/.test( hash ) ) {
+
+				var hashLanguage = /^(api|manual)\/(en|zh)\//.exec( hash );
+
+				if ( hashLanguage === null ) {
+
+					// Route old non-localised api links
+
+					window.location.hash = hash.replace( /^(api|manual)/, '$1/en' );
 
-				window.location.hash = hash.replace( /^(api|manual)/, '$1/en' );
+				} else {
+
+					language = hashLanguage[ 2 ];
+
+				}
 
 			}
 
 			//
 
-			var language = 'en';
-
 			function setLanguage( value ) {
 
 				language = value;