MapSnippets logo MapSnippets logo

Set Map Language with MapTiler SDK

MapTiler SDK

Localize map labels at runtime in MapTiler SDK by calling map.setLanguage() with a language code such as 'en', 'de', or 'local' to swap the label text.

progress_activity Loading map...
maptilersdk.config.apiKey = 'YOUR_MAPTILER_KEY';
const map = new maptilersdk.Map({
  container: 'map',
  style: maptilersdk.MapStyle.STREETS,
  center: [14.42, 50.08],
  zoom: 5,
  language: 'en'
});
window.setLang = function(lang) {
  map.setLanguage(lang);
};

How to change the map label language with MapTiler SDK

The MapTiler SDK provides a built-in language option in the Map constructor and a setLanguage() method for runtime changes. This is simpler than the raw MapLibre approach because you do not need to reconstruct the style URL yourself.

Pass a language code like 'en', 'de', or 'ja' to set labels globally. The special value 'local' displays each region’s native language. The SDK handles the style URL construction and reload internally.

Unlike calling setStyle() directly, setLanguage() is a dedicated method that the SDK optimizes for language switching. It updates label layers without requiring you to manually manage custom sources and layers.

Key APIs

API Description Docs
language option Set initial label language in constructor docs.maptiler.com/sdk-js/api/
map.setLanguage() Change label language at runtime docs.maptiler.com/sdk-js/api/
maptilersdk.MapStyle Built-in style constants docs.maptiler.com/sdk-js/api/

FAQ

Which languages are supported?

MapTiler supports 50+ languages including major world languages (en, de, fr, es, zh, ja, ar, ko) and regional languages (cs, uk, vi). Use 'local' to display each region’s native labels.

Does setLanguage() preserve my custom layers?

The SDK’s setLanguage() is designed to update labels without a full style reload. However, behavior may depend on the SDK version, so always test with your custom layers to confirm they persist.

Can I set the language per layer?

No. The language option and setLanguage() apply to all label layers in the style. For per-layer control, modify the style specification directly.

Common mistakes

  • Using setStyle() instead of the simpler setLanguage(), which avoids unnecessary style reloads
  • Forgetting the language constructor option and relying only on runtime switching instead of setting a sensible default
  • Passing a full locale string like 'en-US' instead of a two-letter code like 'en'

Build maps using MapTiler SDK with AI

Generate code like this set map language with maptiler sdk example using the MapTiler SDK skill in your IDE.