language-link.tsx 698 B

1234567891011121314151617181920212223242526
  1. "use client";
  2. import { usePathname } from "next/navigation";
  3. import { useLocale, useT } from "@/components/locale-provider";
  4. import { htmlLang, localePath, stripLocale } from "@/lib/i18n";
  5. /** This page in the other language, named in that language. */
  6. export function LanguageLink({ className }: { className?: string }) {
  7. const lang = useLocale();
  8. const { nav } = useT();
  9. const path = stripLocale(usePathname());
  10. const other = lang === "en" ? "zh" : "en";
  11. return (
  12. <a
  13. className={className}
  14. data-cursor={nav.switchCursor}
  15. href={localePath(other, path)}
  16. hrefLang={htmlLang[other]}
  17. lang={htmlLang[other]}
  18. >
  19. {nav.switchCursor}
  20. </a>
  21. );
  22. }