Language Selector
Internationalize your site. This script provides a quick way to implement a language switcher using a standard form element.
Copy the Script
<script>
function switchLang(selectObj) {
var langCode = selectObj.value;
if (langCode) {
// Redirect to /lang/index.html
window.location.href = "/" + langCode + "/index.html";
// OR Append parameter
// window.location.href = "?lang=" + langCode;
}
}
</script>
<select onchange="switchLang(this)">
<option value="en">English</option>
<option value="fr">French</option>
</select>
Frequently Asked Questions
No. This script only redirects users to a pre-existing translated page (e.g., from `index.html` to `index_es.html`). For auto-translation, you need an API like Google Translate.
Yes. Standard `
Not by default. You would need to add logic to save the selection to a Cookie or LocalStorage to keep the user on their preferred language when they return.