# General Translation React SDKs (gt-react, gt-next, gt-react-native): isLocaleSupported URL: https://generaltranslation.com/zh/docs/react/nextjs/reference/functions/is-locale-supported.mdx --- title: isLocaleSupported description: 检查路由值是否会解析为已配置的 gt-next 区域设置。isLocaleSupported 的 API 参考。 --- 如果应拒绝未知的路由区域设置,而不是回退到默认区域设置,请使用 `isLocaleSupported`。从 `gt-next` 导入该函数。 ## 概览 [#overview] ```tsx import { isLocaleSupported } from 'gt-next'; isLocaleSupported('es'); // true 或 false ``` ## 参数 [#parameters] | 参数 | 描述 | 类型 | 可选 | 默认值 | | -------- | -------------------- | --------- | -- | --- | | `locale` | 要根据当前配置进行验证的区域设置候选项。 | `unknown` | 否 | — | ## 返回 [#returns] **类型** `locale is string` 当该值可解析为某个已配置的区域设置时,返回 `true`。该检查接受已配置的别名,并可用作 TypeScript 类型守卫。 对于不受支持的区域设置、空字符串和非字符串值,返回 `false`。 ## 示例 [#example] 在渲染本地化布局前,验证 root 路由参数: ```tsx title="app/[locale]/layout.tsx" import { isLocaleSupported } from 'gt-next'; import { notFound } from 'next/navigation'; export default async function LocaleLayout({ children, params, }: { children: React.ReactNode; params: Promise<{ locale: string }>; }) { const { locale } = await params; if (!isLocaleSupported(locale)) { notFound(); } return ( {children} ); } ``` 当请求区域设置不受支持时,`gt-next`会发出警告并使用`defaultLocale`。对于要求区域设置前缀的严格路由,请使用此显式检查。