AI 给了这样的代码:
<script>
var lang = (navigator.language || navigator.userLanguage).toLowerCase();
switch (lang) {
case 'it':
window.location.href = 'it.html';
break;
case 'de':
window.location.href = 'de.html';
break;
case 'ja':
window.location.href = 'ja.html';
break;
case 'zh-cn':
window.location.href = 'zh-cn.html';
break;
case 'zh-tw':
window.location.href = 'zh-tc.html';
break;
case 'zh-hk':
window.location.href = 'zh-tc.html';
break;
default:
window.location.href = 'en.html'; // Default to English if no match found
}
</script>
我的疑问是,我通过 chrome 调试,选了 Tokyo ,它语言是 ja-JP ,那么这个 ja-JP 不会跳转 ja.html?
那么其他如 de-DE 也不会跳转 de.html ?那我岂不是还得收集全部的 de-XX 和 ja-XX 都写入这个代码?
<script>
var lang = (navigator.language || navigator.userLanguage).toLowerCase();
switch (lang) {
case 'it':
window.location.href = 'it.html';
break;
case 'de':
window.location.href = 'de.html';
break;
case 'ja':
window.location.href = 'ja.html';
break;
case 'zh-cn':
window.location.href = 'zh-cn.html';
break;
case 'zh-tw':
window.location.href = 'zh-tc.html';
break;
case 'zh-hk':
window.location.href = 'zh-tc.html';
break;
default:
window.location.href = 'en.html'; // Default to English if no match found
}
</script>
我的疑问是,我通过 chrome 调试,选了 Tokyo ,它语言是 ja-JP ,那么这个 ja-JP 不会跳转 ja.html?
那么其他如 de-DE 也不会跳转 de.html ?那我岂不是还得收集全部的 de-XX 和 ja-XX 都写入这个代码?