Created
January 25, 2011 03:44
-
-
Save hasegawayosuke/794477 to your computer and use it in GitHub Desktop.
keep lang setting with localStorage. http://frepan.org/static/js/frepan.js?v=16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- C:/tmp/frepan.v16.org.js Tue Jan 25 12:35:53 2011 | |
+++ C:/tmp/frepan.js Tue Jan 25 12:39:39 2011 | |
@@ -86,13 +86,24 @@ | |
} | |
__MYLINGUAL.updateStatus = function () {} // display completed message | |
__MYLINGUAL.debugAlert = function (msg) { /* display debug message */ } | |
- var lang = navigator.language; | |
- var m = location.hash.match(/[#&]lang=(\w+)/); | |
- if (m) lang = m[1]; | |
+ var lang; | |
+ var m; | |
+ if( typeof localStorage == "object" ){ | |
+ lang = localStorage[ "lang" ]; | |
+ } | |
+ if( ( m = location.hash.match( /[#&]lang=(\w+)/ ) ) && m[ 1 ] ){ | |
+ lang = m[ 1 ]; | |
+ } | |
+ if( !lang ){ | |
+ lang = navigator.language.replace( /\-\w+$/,"" ); // fix "ja-JP" to "ja" | |
+ } | |
var scr = document.createElement('script'); | |
scr.setAttribute("id", "mylingual-core"); | |
scr.setAttribute("src", "http://mylingual.net/userjs/mylingual-core.js?lang=" + lang); | |
document.body.appendChild(scr); | |
+ if( typeof localStorage == "object" ){ | |
+ localStorage[ "lang" ] = lang; | |
+ } | |
})(); | |
// dist page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment