Skip to content
Make with
D

Diplomat

Localize map labels to the reader's languages

Maintained by OpenStreetMap Americana

An internationalization plugin for MapLibre GL JS from OpenStreetMap Americana. It rewrites a style's labels to prefer the reader's languages, with fallbacks, optional local-name glosses, and locale-aware country names.

Live demo

Diplomat running on MapLibre GL JS in your browser

Loading the map…

Demo code
import * as Diplomat from "@americana/diplomat";
import type { PluginDemo } from "../types";

export default {
  center: [15, 50], // Central Europe
  zoom: 4.5,
  run({ map }) {
    // Label places with Diplomat's expression: the name in the chosen language,
    // followed by the local name in parentheses where it differs.
    for (const layer of map.getStyle().layers) {
      if (layer.type === "symbol" && layer["source-layer"] === "place") {
        map.setLayoutProperty(layer.id, "text-field", Diplomat.localizedNameWithLocalGloss);
      }
    }

    // Pick the language: Japanese here. Leave out ["ja"] to follow the reader's browser languages.
    Diplomat.localizeStyle(map, ["ja"]);
  },
} satisfies PluginDemo;