# gt-next: General Translation Next.js SDK: getDefaultLocale URL: https://generaltranslation.com/zh/docs/next/api/helpers/get-default-locale.mdx --- title: getDefaultLocale description: getDefaultLocale 服务端方法的 API 参考文档 --- ## 概述 `getDefaultLocale` 函数用于获取应用的默认区域设置。 该区域设置会在服务器启动时确定,并作为翻译的后备语言使用。 它会返回一个[区域设置代码](/docs/core/locales),例如 `'en'`。 `getDefaultLocale` 是一个服务端方法,只能在服务端组件中使用。 有关设置,请参阅 [`withGTConfig`](/docs/next/api/config/with-gt-config)。 如果未在 [`withGTConfig`](/docs/next/api/config/with-gt-config) 中指定默认区域设置,则默认使用 `'en'`。 客户端请参阅 [`useDefaultLocale`](/docs/next/api/helpers/use-default-locale)。 ## 参考 ### 返回值 表示应用默认区域设置的字符串,例如 `'en'`。 *** ## 示例 ### 基本用法 获取应用的默认区域设置,并在服务端逻辑中使用它。 ```jsx title="GetDefaultLocale.jsx" copy import { getDefaultLocale } from 'gt-next/server'; export default function GetDefaultLocale() { const defaultLocale = getDefaultLocale(); // [!code highlight] return

Default locale: {defaultLocale}

; } ``` *** ## 说明 * `getDefaultLocale` 返回在 [`withGTConfig`](/docs/next/api/config/with-gt-config) 中设置的默认区域设置。 * `getDefaultLocale` 仅可在服务端使用。 * 返回的区域设置符合[区域设置代码](/docs/core/locales)格式。 ## 后续步骤 * 请参阅 [`useLocale`](/docs/next/api/helpers/use-locale) 和 [`getLocale`](/docs/next/api/helpers/get-locale) 来获取用户的区域设置。