-
registerMessageBundleLoader(loader){Object} - 自從:ArcGIS 適用於 JavaScript 4.18 的 API
注冊消息加載器以加載翻譯字符串所需的指定消息包。需要在獲取應用程序的消息包之前調用此方法。
有兩個選項可用於創建所需的 MessageBundleLoader 參數。
- 通過實現 MessageBundleLoader 來定義您自己的加載器,或者
- 使用 API 通過便捷方法實現的加載器 createJSONLoader 。
下麵提供了兩者的示例。
參數:
類型 說明 loader intl.MessageBundleLoader消息包加載器。
返回:
類型 說明 Object 返回一個帶有 remove()應調用以注銷消息加載器的方法。屬性 類型 說明 remove Function 調用時,注銷消息加載器。 例子:
// This example defines a loader by implementing a MessageBundleLoader. // Register a loader that loads bundles with the specified bundle identifier // starting with "my-application\/" const patternBundle = /^my-application\/(.+)/g; intl.registerMessageBundleLoader({ pattern: patternBundle, // Calls the FetchMessageBundle function of the loader, passing in the bundle identifier and locale async fetchMessageBundle(bundleId, locale) { // extract the filename from the bundle id. const filename = pattern.exec(bundleId)[1]; // normalize the locale, e.g. 'fr-FR' > 'fr' const knownLocale = intl.normalizeMessageBundleLocale(locale); // Fetch the corresponding JSON file given the specified url path const response = await fetch(new Url(`./assets/translations/${filename}_${knownLocale}.json`, window.location.href)); return response.json(); } }); // If the locale changes, calling fetchMessageBundle resolves to the new localized message bundle. intl.onLocaleChange((newLocale) => { const bundle = await intl.fetchMessageBundle("my-application/translations/MyBundle"); // loads file: "https://myserver/my-application/translations/MyBundle_fr.json" }); // Updates the locale intl.setLocale("fr");// This example defines the loader via the createJSONLoader method. // Register a loader that loads bundles with the specified bundle identifier // starting with "my-application\/" const patternBundle = /^my-application\/(.+)/g; intl.registerMessageBundleLoader( intl.createJSONLoader({ pattern: patternBundle, base: "my-application/", location: new URL("./assets/", window.location.href) }) ); // If the locale changes, calling fetchMessageBundle resolves to the new localized message bundle. intl.onLocaleChange((newLocale) => { const bundle = await intl.fetchMessageBundle("my-application/MyBundle"); // loads file: "https://myserver/my-application/MyBundle_fr.json" }); // Updates the locale intl.setLocale("fr");
基本信息
以下是所在類或對象的基本信息。
AMD:
require(["esri/intl"], (intl) => { /* code goes here */ });
ESM:
import * as intl from "@arcgis/core/intl";
對象:
esri/intl
自從:用於 JavaScript 4.12 的 ArcGIS API
用法說明
intl.registerMessageBundleLoader函數(或屬性)的定義如下:
相關用法
- JavaScript ArcGIS intl.convertDateFormatToIntlOptions用法及代碼示例
- JavaScript ArcGIS intl.normalizeMessageBundleLocale用法及代碼示例
- JavaScript ArcGIS intl.fetchMessageBundle用法及代碼示例
- JavaScript ArcGIS intl.SubstituteOptions用法及代碼示例
- JavaScript ArcGIS intl.SubstituteDateTimeFormatOptions用法及代碼示例
- JavaScript ArcGIS intl.SubstituteNumberFormatOptions用法及代碼示例
- JavaScript ArcGIS intl.formatNumber用法及代碼示例
- JavaScript ArcGIS intl.convertNumberFormatToIntlOptions用法及代碼示例
- JavaScript ArcGIS intl.createJSONLoader用法及代碼示例
- JavaScript ArcGIS intl.setLocale用法及代碼示例
- JavaScript ArcGIS intl.MessageBundleLoader用法及代碼示例
- JavaScript ArcGIS intl.formatDate用法及代碼示例
- 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.registerMessageBundleLoader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
