- 自從:ArcGIS 適用於 JavaScript 4.18 的 API
加載與當前 API 語言環境一起使用的本地化消息包。消息包是一個包含翻譯的對象,可以作為文件存儲在磁盤上,也可以作為代碼中的對象存儲。在內部,用於 JavaScript 的ArcGIS API 使用包含本地化翻譯的 JSON 文件。這些捆綁包由唯一的字符串標識,即。
bundleId
。fetchMessageBundle
方法應該在函數使用小部件外部的翻譯字符串時使用。然而,如果 widget 需要使用消息包,它應該通過 @messageBundle 裝飾器來實現。fetchMessageBundle
方法詞通過找到與消息標識符匹配的pattern
的第一個加載程序。然後它調用加載程序自己的fetchMessageBundle 函數。如果返回的 Promise 被拒絕,fetchMessageBundle
會找到另一個加載器並重複該操作,直到加載器成功獲取一個包,或者沒有更多的加載器可用。下麵是用於美國英語區域設置的 Home 小部件的 JSON 消息包示例。下麵是為法國的法語語言環境翻譯的同一個小部件字符串的包。
參數:
類型 說明 bundleId String消息包的標識符,傳遞給使用 registerMessageBundleLoader 注冊的加載程序。
返回:
類型 說明 Promise<Object> 解析後,包含本地化消息字符串的對象。 例子:
// This snippet shows the JSON message bundle used for the Home widget in English { "widgetLabel": "Home", "button": "Home", "title": "Default map view" }
// This snippet shows the same translation strings in the French locale { "widgetLabel": "Accueil", "button": "Accueil", "title": "Vue cartographique par défaut" }
// Fetches the message bundle from the specified location const bundle = await intl.fetchMessageBundle("my-application/MyBundle"); // English message bundle is loaded // If needing to update or set locale, call setLocale intl.setLocale("fr"); // Once locale is updated, fetch the new French message bundle const bundle = await intl.fetchMessageBundle("my-application/MyBundle");
基本信息
以下是所在類或對象的基本信息。
AMD:
require(["esri/intl"], (intl) => { /* code goes here */ });
ESM:
import * as intl from "@arcgis/core/intl";
對象:
esri/intl
自從:用於 JavaScript 4.12 的 ArcGIS API
用法說明
intl.fetchMessageBundle
函數(或屬性)的定義如下:
相關用法
- JavaScript ArcGIS intl.formatNumber用法及代碼示例
- JavaScript ArcGIS intl.formatDate用法及代碼示例
- JavaScript ArcGIS intl.convertDateFormatToIntlOptions用法及代碼示例
- JavaScript ArcGIS intl.normalizeMessageBundleLocale用法及代碼示例
- JavaScript ArcGIS intl.SubstituteOptions用法及代碼示例
- JavaScript ArcGIS intl.SubstituteDateTimeFormatOptions用法及代碼示例
- JavaScript ArcGIS intl.SubstituteNumberFormatOptions用法及代碼示例
- JavaScript ArcGIS intl.convertNumberFormatToIntlOptions用法及代碼示例
- JavaScript ArcGIS intl.createJSONLoader用法及代碼示例
- JavaScript ArcGIS intl.registerMessageBundleLoader用法及代碼示例
- JavaScript ArcGIS intl.setLocale用法及代碼示例
- JavaScript ArcGIS intl.MessageBundleLoader用法及代碼示例
- JavaScript ArcGIS intl.onLocaleChange用法及代碼示例
- JavaScript ArcGIS intl.substitute用法及代碼示例
- JavaScript includes()用法及代碼示例
- JavaScript isFinite()用法及代碼示例
- JavaScript isNaN()用法及代碼示例
- JavaScript ArcGIS imageService.getSamples用法及代碼示例
- JavaScript ArcGIS SceneView double-click事件用法及代碼示例
- JavaScript ArcGIS geometryEngineAsync.overlaps用法及代碼示例
- JavaScript ArcGIS Expand.when用法及代碼示例
- JavaScript ArcGIS Sublayer.JoinTableDataSource用法及代碼示例
- JavaScript ArcGIS FillSymbol3DLayer.outline用法及代碼示例
- JavaScript ArcGIS Ground.loadAll用法及代碼示例
- JavaScript Object valueOf()用法及代碼示例
注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 intl.fetchMessageBundle。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。