-
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。