當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript ArcGIS intl.onLocaleChange用法及代碼示例

基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/intl"], (intl) => { /* code goes here */ });

ESM: import * as intl from "@arcgis/core/intl";

對象: esri/intl

自從:用於 JavaScript 4.12 的 ArcGIS API

用法說明

intl.onLocaleChange函數(或屬性)的定義如下:

onLocaleChange (callback) {Handle}


自從:ArcGIS 適用於 JavaScript 4.16 的 API

注冊 callback,當區域設置更改時會收到通知。當調用 setLocale() 時,或者當用戶更改 Web 瀏覽器區域設置並且當前區域設置等於 Web 瀏覽器的區域設置時,就會發生這種情況。

參數:

類型說明

當區域設置更改時觸發的函數。執行 setLocale() 方法後,使用 newly-set 語言環境調用它。

返回:

類型 說明
Handle 返回帶有 remove() 方法的處理程序,可以調用該方法來刪除回調並停止偵聽區域設置更改。

例子:

// Initially fetches the message bundle in the current language.
let bundle = await intl.fetchMessageBundle("my-application/MyBundle");
// Do something with the bundle

// Set the locale to French
intl.setLocale("fr");

// Listen for when locale is changed and then fetch the updated French message bundle
intl.onLocaleChange(function(locale) {
  console.log("locale changed to: ", locale);
  let bundle = await intl.fetchMessageBundle("my-application/MyBundle");
});

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 intl.onLocaleChange。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。