Learn how to localize place labels in the basemap.
The ArcGIS Basemap Styles service provides a number of different styles you can use in Esri Leaflet applications. Each style accepts a language
parameter, which allows you to localize place labels. There are currently over 30 different languages available.
In this tutorial, you use Esri Leaflet Vector to create a language selector and switch between different languages.
Prerequisites
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Get the starter app
Select a type of authentication below and follow the steps to create a new application.
Set up authentication
Create developer credentials in your portal for the type of authentication you selected.
Set developer credentials
Use the API key or OAuth developer credentials so your application can access ArcGIS services.
Create a basemap language function
Create a function that accepts a language code and returns a basemap style formatted with that language.
-
Define a new
get
function that accepts a language code and returns aLanguage Vector
.Basemap Layer Use dark colors for code blocks function getLanguage(languageCode) { return L.esri.Vector.vectorBasemapLayer(basemapStyle, ) }
-
In the basemap layer properties, set the
language
option to yourlanguage
. SetCode version
to access the styles service, and pass your access token.:2 Use dark colors for code blocks function getLanguage(languageCode) { return L.esri.Vector.vectorBasemapLayer(basemapStyle, { language: languageCode, token: accessToken } ) }
Add a language selector
Add a menu that allows users to change the display language of your map.
-
Use
L.esri.get
to make a request to the Basemap Styles service. This dynamically fetches the available basemap languages. For each enumerated language, call theget
function to populate theLanguage languages
list.Use dark colors for code blocks function getLanguage(languageCode) { return L.esri.Vector.vectorBasemapLayer(basemapStyle, { language: languageCode, token: accessToken } ) } L.esri.get( "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self", { token: accessToken }, (error, response) => { if (error) { console.error("Error fetching languages:", error); return; } const languages = {}; let firstLanguage; response.languages.forEach((language, index) => { const layer = getLanguage(language.code); languages[language.name] = layer; if (index === 0) { firstLanguage = layer; firstLanguage.addTo(map); } });
-
Create a Leaflet
Control
and add it to your map. Pass thelanguages
object to display all of the supported languages.Use dark colors for code blocks L.esri.get( "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self", { token: accessToken }, (error, response) => { if (error) { console.error("Error fetching languages:", error); return; } const languages = {}; let firstLanguage; response.languages.forEach((language, index) => { const layer = getLanguage(language.code); languages[language.name] = layer; if (index === 0) { firstLanguage = layer; firstLanguage.addTo(map); } }); L.control.layers(languages, null, { collapsed: false }).addTo(map);
Add RTL language support
Esri Leaflet Vector does not automatically display right-to-left languages, such as Arabic and Hebrew, correctly. Use the Mapbox GL RTL Text plugin to configure settings for RTL languages.
-
Call the L.Esri.Vector.setRTLTextPlugin with the URL of the Mapbox GL RTL Text plugin to configure support for RTL languages.
Use dark colors for code blocks L.control.layers(languages, null, { collapsed: false }).addTo(map); } ); L.esri.Vector.setRTLTextPlugin('https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.2.3/mapbox-gl-rtl-text.js');
Run the app
Run the app.
You should be able to use the Leaflet control to switch between basemap languages.What's next?
Learn how to use additional location services in these tutorials:

Change the basemap style
Switch a vector basemap style on a map.

Display a custom basemap style
Add a custom vector basemap style to a map.

Change the static basemap tiles style
Switch a static basemap style on a map.

Add a feature layer as GeoJSON
Display and style GeoJSON features from a feature service.