Skip to content
雲里
里雾

RN 0.83 新架构下的 locale 检测

react native 开发 更新于 2026/4/28

React Native 0.83 使用 TurboModules 新架构后,传统的 locale 检测 API(I18nManager、SettingsManager)不再可用,需改用 Hermes 引擎的 Intl API。

概述

在 React Native 旧架构中,检测系统语言常用两种方式:

升级到 RN 0.83(TurboModules 新架构)后,这两个 API 均失效:

用法

使用 Hermes 引擎内置的 Intl API,不依赖任何原生模块:

function getSystemLocale(): string | undefined {
  try {
    return Intl.DateTimeFormat().resolvedOptions().locale
  } catch {
    return undefined
  }
}

返回值示例:

配合语言匹配逻辑:

function matchLanguage(locale: string | undefined): 'cn' | 'tw' | 'en' {
  const normalized = locale?.toLowerCase().replace(/_/g, '-')
  if (
    normalized?.startsWith('zh-hant') ||
    normalized?.startsWith('zh-tw') ||
    normalized?.startsWith('zh-hk')
  ) {
    return 'tw'
  }
  return normalized?.startsWith('zh') ? 'cn' : 'en'
}

注意事项

版本说明

本页基于 React Native 0.83.2 + Hermes 引擎。旧架构(Bridge 模式)下 I18nManager.localeIdentifier 仍可用。

参见

参考