Skip to content

Commit

Permalink
Localizable under construction suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Mar 6, 2022
1 parent fc9bd04 commit d33682b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
29 changes: 29 additions & 0 deletions style/constants/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
4 changes: 3 additions & 1 deletion style/layer/road_label.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

import * as labelUtils from "../constants/label.js";

const textLayout = {
"text-font": ["Metropolis Light"],
"text-field": [
Expand All @@ -10,7 +12,7 @@ const textLayout = {
[
"case",
["in", "_construction", ["get", "class"]],
" (UNDER CONSTRUCTION)",
labelUtils.t("under_construction_suffix").toLocaleUpperCase(),
"",
],
{
Expand Down

0 comments on commit d33682b

Please sign in to comment.