From 8d4f0927530440c6d7c0374c34a38f238e24c07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 30 Nov 2022 04:38:05 -0800 Subject: [PATCH] Conflate local and preferred language names more aggressively MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the name in the preferred language matches the name in the local language except for the addition of a prefix or suffix, which is likely to be an insignificant word like “City”, splice the local-language name into the preferred-language name to reduce redundancy. --- src/layer/place.js | 83 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/src/layer/place.js b/src/layer/place.js index e665c631d..280fb4cc8 100644 --- a/src/layer/place.js +++ b/src/layer/place.js @@ -198,14 +198,87 @@ export const city = { ["var", "localizedCollator"], ], ["var", "localizedName"], - // If the name in the local language and preferred language match except for diacritics, show only the localized name. + // If the name in the preferred language is the same as the name in the local language except for the omission of diacritics and/or the addition of a suffix (e.g., "City" in English), replace the common prefix with the local name. [ - "==", - ["var", "localizedName"], + "all", + [ + "==", + ["slice", ["var", "localizedName"], 0, ["length", ["get", "name"]]], + ["get", "name"], + ["var", "diacriticInsensitiveCollator"], + ], + [ + "in", + [ + "slice", + // "Montreal" vs. "Montréal" + ["concat", ["var", "localizedName"], " "], + ["length", ["get", "name"]], + ["+", ["length", ["get", "name"]], 1], + ], + // "Quebec City" vs. "Québec", "Washington, D.C." vs. "Washington" + " ,", + ], + ], + [ + "concat", + ["get", "name"], + ["slice", ["var", "localizedName"], ["length", ["get", "name"]]], + ], + // If the name in the preferred language is the same as the name in the local language except for the omission of diacritics and/or the addition of a prefix (e.g., "City of" in English or "Ciudad de" in Spanish), replace the common suffix with the local name. + [ + "all", + [ + "==", + [ + "slice", + ["var", "localizedName"], + [ + "-", + ["length", ["var", "localizedName"]], + ["length", ["get", "name"]], + ], + ], + ["get", "name"], + ["var", "diacriticInsensitiveCollator"], + ], + [ + "==", + [ + "slice", + ["var", "localizedName"], + [ + "-", + [ + "-", + ["length", ["var", "localizedName"]], + ["length", ["get", "name"]], + ], + 1, + ], + [ + "-", + ["length", ["var", "localizedName"]], + ["length", ["get", "name"]], + ], + ], + " ", + ], + ], + [ + "concat", + [ + "slice", + ["var", "localizedName"], + 0, + [ + "-", + ["length", ["var", "localizedName"]], + ["length", ["get", "name"]], + ], + ], ["get", "name"], - ["var", "diacriticInsensitiveCollator"], ], - ["get", "name"], // Gloss the name in the local language if it differs from the localized name. [ "format",