Select to view content in your preferred language

intl fetchMessageBundle for existing widget

1371
5
Jump to solution
08-26-2021 07:38 AM
René_Ténière
Frequent Contributor

I have been trying to access the message bundle for existing widgets, i.e. Legend. The instructions are clear on creating and accessing your own custom widget bundles, however, I need to access the locale specific label for an existing widget. What do I use for the BundleID for @arcgis/core/widgets/Legend as an example?

 

Thanks,

René

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Honored Contributor

Sorry, the locales for existing widgets are not extensible at this time.

View solution in original post

0 Kudos
5 Replies
ReneRubalcava
Honored Contributor

Sorry, the locales for existing widgets are not extensible at this time.

0 Kudos
René_Ténière
Frequent Contributor

Ok, thanks René.

I was looking into it because when the widget is wrapped in an Expand, only the expandTooltip is shown on hover (title) and results to the default ("Expand" in En, and "Développer" in Fr). I was hoping to capture the label from the widget to override using expandTooltip() so that a user with a screen reader will be able to read the widget label instead.

0 Kudos
ReneRubalcava
Honored Contributor

If that's the case, you can do something like this.

view.when(() => {
    bgExpand.expandTooltip = `${bgExpand.label} ${basemapGallery.label}`;
});

I think this will help get you there.

 https://codepen.io/odoe/pen/powJRyM?editors=1000

The widget labels will change with locales, so you can update the expandTooltip from another widget. You do need to widget.watch("label", method) or wait for view.when() to get the labels.

0 Kudos
René_Ténière
Frequent Contributor

Yes, that looks good... Thanks!

0 Kudos
René_Ténière
Frequent Contributor

After doing more research, a quick hack is to do the following:

import esriConfig from "@arcgis/core/config.js";
import * as intl from "@arcgis/core/intl";

export function functionName() {
    var lang = intl.getLocale().toLowerCase().slice(0, 2);
    var widgetsAssetsPath = esriConfig.assetsPath + "/esri/widgets/";
    var legendT9n = `${widgetsAssetsPath}${widget.widget_id}/t9n/${widget.widget_id}_${lang}.json`;
    var t9n = {widgetLabel: "Layer List"}; // Default value
    returnConfig(legendT9n).then(t9nResults => {
        if(t9nResults){
            t9n = t9nResults;
        }
    }).then(function (){
        console.log(t9n.widgetLabel);
    });

 

Just something for now so I don't have to define the labels elsewhere... 

0 Kudos