Skip to content

Commit

Permalink
Conflate local and preferred language names more aggressively
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1ec5 committed Dec 1, 2022
1 parent 479010d commit 8d4f092
Showing 1 changed file with 78 additions and 5 deletions.
83 changes: 78 additions & 5 deletions src/layer/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8d4f092

Please sign in to comment.