Helpers

getDefaultLocale()

getDefaultLocale 服务器端方法的 API 参考

概述

getDefaultLocale() 函数检索应用程序的默认语言环境。 此语言环境在服务器启动时确定,并用作翻译的备用语言。 它返回一个语言环境字符串,例如,'en-US'

getDefaultLocale() 是一个服务器端方法,只能用于服务器端组件。

请参阅 withGTConfig() 以进行配置。 如果在 withGTConfig() 中未指定默认语言环境,则默认为 'en-US'。 对于客户端,请参阅 useDefaultLocale()

参考

返回值

一个表示应用程序默认语言环境的字符串,例如,'en-US'


示例

基本用法

检索应用程序的默认语言环境,并在您的服务器端逻辑中使用它。

GetDefaultLocale.jsx
import getDefaultLocale from 'gt-next/server';
 
export default function GetDefaultLocale() {
    const defaultLocale = getDefaultLocale(); 
    return <p>Default locale: {defaultLocale}</p>;
}

注意事项

  • getDefaultLocale() 返回在 withGTConfig() 中设置的默认语言环境。
  • getDefaultLocale() 仅在服务器端使用。
  • 返回的语言环境遵循 locale strings 格式。

下一步

在本页面