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


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

基本信息

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

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

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

對象: esri/intl

自從:用於 JavaScript 4.12 的 ArcGIS API

用法說明

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

MessageBundleLoader


自從:ArcGIS 適用於 JavaScript 4.18 的 API

消息包加載器是一個用於加載用戶區域設置中的翻譯字符串的對象。它必須使用registerMessageBundleLoader 在intl 中注冊。在 API 中加載消息包時,首先評估最後注冊的加載器。

屬性:

類型說明
pattern String|RegExp

用於檢查是否應該使用加載器來加載候選消息包。

fetchMessageBundle FetchMessageBundle

如果 pattern 與包標識符匹配,則調用以加載消息包。

例子:

const loader = {
  // The loader matches all the bundle identifiers starting with "my-application/"
  pattern: "my-application/",
  // fetch the JSON file from a `translations` folder
  async fetchMessageBundle(bundleId, locale) {
    const url = new URL(`/assets/translations/${bundleId}_${locale}.json`, window.location.href);
    const response = await fetch(url);
    return response.json();
  }
};

registerMessageBundleLoader(loader);

// Fetch file `./translations/my-application/MyBundle_en-US.json`
const bundle = await fetchMessageBundle("my-application/translations/MyBundle");

相關用法


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