# generaltranslation: General Translation Core SDK: determineLocale URL: https://generaltranslation.com/zh/docs/core/functions/locales/determine-locale.mdx --- title: determineLocale description: determineLocale 函数的 API 参考文档 --- ## 概述 `determineLocale` 函数会根据用户偏好,从已批准的区域设置中确定最匹配的区域设置,无需 GT 类实例。 *** ## 参考 ### 参数 ### 返回值 `string | undefined` - 最匹配的区域设置;如果没有匹配项,则返回 `undefined` *** ## 示例 ### 内容协商 ```typescript import { determineLocale } from 'generaltranslation'; const approvedLocales = ['en-US', 'es-ES', 'fr-FR', 'de-DE']; // 精确匹配 console.log(determineLocale('en-US', approvedLocales)); // 'en-US' // 语言回退 console.log(determineLocale('en-GB', approvedLocales)); // 'en-US' // 多个偏好语言 console.log(determineLocale(['fr-CA', 'es-MX'], approvedLocales)); // 'es-ES' // 无匹配 console.log(determineLocale('it-IT', approvedLocales)); // undefined ``` *** ## 说明 * 实现智能区域设置协商 * 从允许列表中返回首个精确匹配项或语言匹配项 * 遵循输入数组中的偏好顺序 * 找不到匹配项时返回 undefined * 是 Web 应用进行区域设置协商的关键功能 ## 后续步骤 * 使用 GT 类方法 [`determineLocale`](/docs/core/class/methods/locales/determine-locale) * 使用 [`requiresTranslation`](/docs/core/functions/locales/requires-translation) 检查是否需要翻译