diff --git a/style/constants/label.js b/style/constants/label.js index a18a80674..aaec28050 100644 --- a/style/constants/label.js +++ b/style/constants/label.js @@ -7,3 +7,32 @@ export const name_en = [ ["get", "name:latin"], ["get", "name"], ]; + +const localizations = { + en: { + /// Appended to the road name label if the road is under construction. + under_construction_suffix: " (Under Construction)", + }, + es: { + under_construction_suffix: " (Bajo Construcción)", + }, +}; + +/** + * Returns a localized string for given string ID in the user’s current language. + */ +export function t(stringId) { + let locales = + (typeof navigator !== "undefined" && + (navigator.languages || [navigator.language])) || + []; + let locale = + locales + .map( + (locale) => locale && locale.match(/^\w+/) && locale.match(/^\w+/)[0] + ) + .find( + (locale) => locale in localizations && localizations[locale][stringId] + ) || "en"; + return localizations[locale][stringId]; +} diff --git a/style/layer/road_label.js b/style/layer/road_label.js index 60a4640e4..e809a03dd 100644 --- a/style/layer/road_label.js +++ b/style/layer/road_label.js @@ -1,5 +1,7 @@ "use strict"; +import * as labelUtils from "../constants/label.js"; + const textLayout = { "text-font": ["Metropolis Light"], "text-field": [ @@ -10,7 +12,7 @@ const textLayout = { [ "case", ["in", "_construction", ["get", "class"]], - " (UNDER CONSTRUCTION)", + labelUtils.t("under_construction_suffix").toLocaleUpperCase(), "", ], {