当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS intl.createJSONLoader用法及代码示例


基本信息

以下是所在类或对象的基本信息。

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

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

对象: esri/intl

自从:用于 JavaScript 4.12 的 ArcGIS API

用法说明

intl.createJSONLoader函数(或属性)的定义如下:

createJSONLoader (params) {MessageBundleLoader}


自从:ArcGIS 适用于 JavaScript 4.18 的 API

创建一个消息包加载器,专门用于将翻译文件加载为 JSON 文件。在内部,这是用于 JavaScript 的ArcGIS API 加载语言环境的加载器。

参数:

规格:
类型说明
params Object

装载机的配置。

规格:
pattern

String|RegExp

用于检查是否应该使用加载器来加载候选人的消息包。

base

String

用于计算要加载的文件的相对路径。

location

String|URL|Function

翻译文件的位置。它可以是指向文件所在文件夹的stringURL,也可以是使用指定路径调用的函数。该函数应返回最终路径。

返回:

类型 说明
intl.MessageBundleLoader loader - 消息包加载器。

例子:

// Assume the following directory structure
src/
  assets/
    translations/
      MyBundle.json
      MyBundle_fr.json
  widgets/
    MyWidget.ts

// Configure the message bundle loader given the directory structure noted above

const loader = intl.createJSONLoader({
  pattern: "my-application/", // The pattern is used to match the string in `intl.fetchMessageBundle("my-application/translations/MyBundle")`
  base: "my-application", // This removes the base, ie. "translations/MyBundle"
  location: new Url("./assets/", window.location.href) // Add the location, ie. "assets/translations/MyBundle"
});

// This loads file, "./assets/translations/MyBundle.json" or
// "./assets/translations/MyBundle_en.json" (unless locale is updated to something, e.g. like `fr`).

// Register the message bundle created from the createJSONLoader method
intl.registerMessageBundleLoader(loader);

// Fetches the message bundle, "./assets/translations/MyBundle.json"
const bundle = await intl.fetchMessageBundle("my-application/MyBundle");

// If no `base` property is specified for the loader method, the assets would read as,
src/
  assets/
    my-application/
      translations/
        MyBundle.json
        MyBundle_en.json
        MyBundle_fr.json

// The method would load file, "./assets/my-application/translations/MyBundle.json" or
// "./assets/my-application/translations/MyBundle_en.json" (unless locale is updated to something, e.g. like `fr`).

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 intl.createJSONLoader。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。