--- createdAt: 2026-09-19 updatedAt: 2026-09-19 title: useLocale 钩子文档 | astro-intlayer description: 了解如何在 Astro 应用程序中使用 useLocale 钩子访问和管理当前语言环境。 keywords: - useLocale - locale - astro - astro-intlayer - Intlayer - intlayer - 国际化 - 文档 slugs: - doc - packages - astro-intlayer - useLocale history: - version: 9.5.5 date: 2026-09-19 changes: "初始文档" author: aymericzip --- # useLocale 钩子文档 `astro-intlayer` 的 `useLocale` 钩子提供对 Astro 应用程序中当前请求语言环境、配置的默认语言环境以及所有可用语言环境的访问权限。 它在服务器渲染的 `.astro` frontmatter 和客户端 ` ``` ## 返回值 该钩子返回一个 `UseLocaleResult` 类型的对象: | 属性 | 类型 | 描述 | | ------------------ | -------------------------------------- | --------------------------------------------------------------------------- | | `locale` | `DeclaredLocales` | 活动语言环境。 | | `defaultLocale` | `DeclaredLocales` | 在 `intlayer.config.ts` 中配置的默认回退语言环境。 | | `availableLocales` | `DeclaredLocales[]` | 为项目配置的所有受支持语言环境的数组。 | | `setLocale` | `(locale: LocalesValues) => void` | 更新语言环境的函数。(在客户端 `