For AI agents: the complete documentation index is available at https://rspress.rs/zh/llms.txt, the full documentation bundle is available at https://rspress.rs/zh/llms-full.txt, and this page is available as Markdown at https://rspress.rs/zh/ui/hooks/use-lang.md.
close

useLang

useLang 返回当前语言代码,便于渲染多语言文案或按语言跳转路由。

  • 类型:() => string

该 Hook 会从运行时上下文中读取语言,并在用户切换语言时保持同步。

当前语言:zh
import { useLang } from '@rspress/core/runtime';

export default function Comp() {
  const lang = useLang();
  return <span>当前语言:{lang}</span>;
}