You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
682 B
25 lines
682 B
"use client";
|
|
import React from "react";
|
|
|
|
export function LangSwitch() {
|
|
const onSwitch = () => {
|
|
const current = window.location.pathname;
|
|
const parts = current.split("/").filter(Boolean);
|
|
const currentLocale = parts[0] === "en" ? "en" : parts[0] === "zh-CN" ? "zh-CN" : null;
|
|
const nextLocale = currentLocale === "en" ? "zh-CN" : "en";
|
|
if (currentLocale) {
|
|
parts[0] = nextLocale;
|
|
} else {
|
|
parts.unshift(nextLocale);
|
|
}
|
|
const nextPath = "/" + parts.join("/");
|
|
window.location.assign(nextPath);
|
|
};
|
|
return (
|
|
<button onClick={onSwitch} className="text-sm text-gray-600 hover:text-gray-900">
|
|
中/EN
|
|
</button>
|
|
);
|
|
}
|
|
|
|
|
|
|