wemon,
пробуйте ...
<!DOCTYPE html>
<html >
<head ></head>
<body><select class="lang">
<option value="ru">ru</option>
<option value="ua">ua</option>
</select>
</body>
<script>
document.addEventListener("DOMContentLoaded", () => {
const select = document.querySelector(".lang");
let url = window.location.href, value, reg;
for ({ value } of select.options) {
reg = new RegExp(`/${value}/`);
if (value && reg.test(url)) {
select.value = value;
break;
}
};
select.addEventListener("change", _ => {
if(!select.value) return;
url = url.replace(reg, `/${select.value}/`);
window.location.href = url;
})
});
</script>
</html>