TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Mapbox GL Language Build Status npm

Adds support for switching the language of your map style in Mapbox GL JS maps.

Requires mapbox-gl-js. For other platforms, such as Android and iOS, see this help document.

Multiple language supported with style transforms

Automatic style transformations for different languages

Switch language based on user agent

Switch language based on user agent


mapbox-gl-language is a Mapbox GL JS plugin that you can easily add on top of your map.

When using a CDN

    <script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-language/v1.0.0/mapbox-gl-language.js'></script>

When using modules

Check how to use Mapbox GL JS in a module bundler.

npm install --save mapbox-gl @mapbox/mapbox-gl-language
import mapboxgl from 'mapbox-gl';
import MapboxLanguage from '@mapbox/mapbox-gl-language';


mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';
const map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v10',
    center: [-77.0259, 38.9010],
    zoom: 9

// Add RTL support if you want to support Arabic
// mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.10.1/mapbox-gl-rtl-text.js');

const language = new MapboxLanguage();

Check examples/ for more usage examples.


Table of Contents


Create a new Mapbox GL JS plugin that modifies the layers of the map style to use the text-field that matches the browser language. As of Mapbox GL Language v1.0.0, this plugin no longer supports token values (e.g. {name}). v1.0+ expects the text-field property of a style to use an expression of the form ['get', 'name_en'] or ['get', 'name']; these expressions can be nested. Note that get expressions used as inputs to other expressions may not be handled by this plugin. For example:

  ["get", "name"],
  "Golden State",
    ["get", "name_en"],
    ["get", "name"]

Only styles based on Mapbox v8 styles are supported.


  • options object Options to configure the plugin.

    • options.supportedLanguages Array<string>? List of supported languages
    • options.languageTransform Function? Custom style transformation to apply
    • options.languageField RegExp RegExp to match if a text-field is a language field (optional, default /^name_/)
    • options.getLanguageField Function? Given a language choose the field in the vector tiles
    • options.languageSource string? Name of the source that contains the different languages.
    • options.defaultLanguage string? Name of the default language to initialize style after loading.
    • options.excludedLayerIds Array<string>? Name of the layers that should be excluded from translation.


Explicitly change the language for a style.

  • style object Mapbox GL style to modify
  • language string The language iso code

Returns object the modified style


Run the linter and watch for changes to rebuild with browserify.

npm install
npm run test


Showcasing the languages supported by Mapbox Streets.

Supported Styles

You can configure the plugin to support your own custom style using style transforms and custom language fields. By default, this plugin works best with official Mapbox styles or styles derived from official Mapbox styles. The styles must be based on Mapbox v8 styles:

  • mapbox://styles/mapbox/streets-v11
  • mapbox://styles/mapbox/outdoors-v11
  • mapbox://styles/mapbox/dark-v10
  • mapbox://styles/mapbox/light-v10
  • mapbox://styles/mapbox/satellite-streets-v9
  • mapbox://styles/mapbox/traffic-day-v2
  • mapbox://styles/mapbox/traffic-night-v2

Package Sidebar


npm i @mapbox/mapbox-gl-language

Weekly Downloads






Unpacked Size

52.8 kB

Total Files


Last publish


  • mbx-npm-ci-production
  • mbx-npm-ci-staging
  • mbx-npm-advanced-actions-production
  • mbx-npm-advanced-actions-staging
  • mbx-npm-09-production
  • mbx-npm-08-production
  • mbx-npm-07-production
  • mbx-npm-06-production
  • mbx-npm-05-production
  • mbx-npm-04-production
  • mbx-npm-03-production
  • mbx-npm-02-production
  • mbx-npm-01-production
  • mbx-npm-02-staging
  • mapbox-npm-01
  • mapbox-npm-02
  • mapbox-npm-07
  • mapbox-npm-03
  • mapbox-npm-04
  • mapbox-npm-09
  • mapbox-npm-05
  • mapbox-npm-06
  • mapbox-npm-08
  • mapbox-npm-advanced-actions
  • mapbox-npm-ci
  • mapbox-npm
  • mapbox-admin
  • mapbox-machine-user