Use Locale from URL parameter in Arcade IF Statement

135
5
Jump to solution
2 weeks ago
ShareUser
Esri Community Manager

This might be a bit of a stretch, but I am wondering if there is a way to take the locale setting on an Experience Builder, and have it be used in an if statement on the pop up in a web map.

We are building an Experience Builder to share information publicly, we need to display our information in English and French. We are utilizing the URL parameter locale=FR to show the French, however this does not translate our pop up information (date and budget number specifically, we have other fields such as DESC and DESCFR for the written word attributes).

Essentially I'm wondering if there's a way to do something like:

 

var price = $feature.BUDGET;;
//if(locale=ENGLISH)
When(
    price < 1000000, "$" + Text(price, "###,###"),
    price < 1000000000, "$" + round(price/1000000, 3) + " million",
"")

//if{locale=FRENCH)
When(
    price < 1000000, Replace(Text(price, "###,### $"),',',' '),
    price < 1000000000, round(price/1000000, 3) + " M$",
"")

 

I found this Using Arcade to Translate Pop-Ups for Use in the ArcGIS Instant Apps (esri.com) and it seems to be going down the right path, but I'm not sure if it works in ExB. The way my colleague set up the ExB is 1 map underlying the whole thing, then an EN ExB, a FR ExB, then an ExB that has them each embedded as URLs, with the French URL including &locale=fr

 

0 Kudos
1 Solution

Accepted Solutions
RobertAnderson3
MVP Regular Contributor

Okay so I figured out the problem, in our embed we were using &locale=fr when it apparently needs to be ?locale=fr (why are they different sometimes? I've run into this issue before and it drives me nuts)

And then for the money and the dates the info from Using Arcade to Translate Pop-Ups for Use in the ArcGIS Instant Apps (esri.com) worked out!

 

var price = $feature.BUDGET;;
 
var env = GetEnvironment();
var locale = env['locale'];

if (locale == 'en'){
return When(
    price < 1000000, "$" + Text(price, "###,###"),
    price < 1000000000, "$" + round(price/1000000, 3) + " million",
"")
}

if(locale == 'fr'){
return When(
    price < 1000000, Replace(Text(price, "###,### $"),',',' '),
    price < 1000000000, round(price/1000000, 3) + " M$",
"")
}

 

 

View solution in original post

0 Kudos
5 Replies
JeffreyThompson2
MVP Regular Contributor

https://community.esri.com/t5/experience-builder-tips-and-tricks/starter-widget-for-getting-informat...

You can capture the URL parameter as in this widget and then modify the popupTemplate for your featureLayer based on the results. The expressionInfos parameter allows for use of Arcade within the Javascript API.

https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#expressionInfo...

GIS Developer
City of Arlington, Texas
RobertAnderson3
MVP Regular Contributor

Is this something you are able to do with the web version of Experience Builder and not the developer edition?

I have the link in an embed with the locale=fr set in it, but it's not respecting that? (I even changed my browser settings to make sure it wasn't overwriting it for some reason)

0 Kudos
JeffreyThompson2
MVP Regular Contributor

Developer Edition only.

Experience Builder in general should respect locale settings passed in URL parameters, but if it doesn't account for re-formatting dates/money in the popups, you will have to use the power of the API to correct this oversight.

GIS Developer
City of Arlington, Texas
0 Kudos
RobertAnderson3
MVP Regular Contributor

Okay so I figured out the problem, in our embed we were using &locale=fr when it apparently needs to be ?locale=fr (why are they different sometimes? I've run into this issue before and it drives me nuts)

And then for the money and the dates the info from Using Arcade to Translate Pop-Ups for Use in the ArcGIS Instant Apps (esri.com) worked out!

 

var price = $feature.BUDGET;;
 
var env = GetEnvironment();
var locale = env['locale'];

if (locale == 'en'){
return When(
    price < 1000000, "$" + Text(price, "###,###"),
    price < 1000000000, "$" + round(price/1000000, 3) + " million",
"")
}

if(locale == 'fr'){
return When(
    price < 1000000, Replace(Text(price, "###,### $"),',',' '),
    price < 1000000000, round(price/1000000, 3) + " M$",
"")
}

 

 

0 Kudos
JeffreyThompson2
MVP Regular Contributor

It is possible to use multiple URL parameters in the same URL. The ? goes on the first parameter being used to tell the browser, "I'm using some URL parameters". The & goes on any additional parameters as, "hey browser, also use this."

GIS Developer
City of Arlington, Texas