# uni.getLocale()

Get the currently set language

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 华为快应用 360小程序 京东小程序
3.2.5+ 3.2.5+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+

If the current application has set the language, it will get the previously set language, and if it is not set, it will return to the language automatically selected according to the system language type.

# uni.setLocale(locale)

Set current language

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 华为快应用 360小程序 京东小程序
3.2.5+ 3.2.5+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+

仅可设置为框架内置语言与自定义扩展的语言,遵循 BCP47 规范。

Parameter Description

Parameter name Type Required
locale String Yes

# uni.onLocaleChange(callback)

Used to listen to the application language switching

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 华为快应用 360小程序 京东小程序
3.2.7+ 3.2.7+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+ 3.4.14+

Description of callback return parameter

Parameter name Type Instruction
locale String Current language

# Precautions

  • Display of components and interfaces will automatically switch according to the set language environment, and the unsupported system language environment will be displayed in English.
  • App-Android, App-iOS platform will restart the application after modifying the system language.
  • App-Android platform will automatically restart the app after setting a new language.
  • The following languages are built into the framework. If you need to customize the content or add other language references: Customize internationalized content.
    • en
    • Simplified Chinese zh-Hans
    • Traditional Chinese zh-Hant
    • fr
    • es
  • The default language of the application can be configured in manifest.json -> locale.
  • 仅 3.1.5 - 3.2.4 版本会自动使用 vue-i18n 内配置的语言。
  • 在小程序平台仅影响用户业务层(vue-i18n)的语言配置,不能影响小程序原生组件和接口的语言。

# 语言回退规则

需要注意的是,语言的处理逻辑是建立在应用locale目录 配置了对应资源的前提下。 资源配置文档

  • 如果应用的 locale目录下配置了对应的资源,那么语言的设置和获取是一致的

  • 如果应用的 locale目录没有配置对应的资源,则会根据具体的平台规则进行回退。

举个例子,应用中仅配置了英文和中文资源,没有配置日语资源,但是通过系统设置修改语言为日文,此时调用 uni.getLocale() 在android平台上获取到的返回值不会是jp 而是en