ZeLonewolf / openstreetmap-americana

A quintessentially American map style

Home Page:https://americanamap.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Norwegian names and language codes

hohMiyazawa opened this issue · comments

Being able to select a preferred display language for names is awesome!
Currently though, Norwegian language codes aren't working perfectly out of the box.

Quick rundown of the situation:

Norwegian, with the language code no is one language.
It does however have two written forms:

  • Nynorsk, with the language code nn
  • Bokmål, with the language codes nb

Both written forms are equal under the law, Norwegians learn both in school, but there is a geographic divide in which of the two forms is more commonly used.

For place names though, they rarely disagree. This means Norwegian names for places are usually using the keyname:no, with the keys name:nn and name:nb mostly being used when the spelling is different. (Though names abroad sometimes use both these keys too even when they are equal).

That means:

  • If a user selects "language=nn" (Norwegian Nynorsk), they want name:nn displayed on the map, but if no such key is present, the map should use name:no if it exists. Using name:nb as a further fallback depends on the usecase.
  • In the same way, if a user selects "language=nb" (Norwegian Bokmål), name:no should be used as a fallback for name:nb.
  • If a user selects "language=no" (Norwegian), if a name:no key is missing, the keys name:nn and name:nb should be used as fallback. This however only works if only one of them is present. If they are both present, they would need to be the same to be used. If they are different, one would have to open the can of worms of picking one of them as preferred, if one doesn't do something like peeking at the browser language to check which of the two forms the user prefers.

Just another slightly complicated language situation out there :)

(Is the name of countries special cased BTW? When selecting "language=nn", Chad is incorrectly spelled "Tchad", even though the name:nn key has correctly been "Tsjad" for many years in OSM)

If a user selects "language=nn" (Norwegian Nynorsk), they want name:nn displayed on the map, but if no such key is present, the map should use name:no if it exists.
In the same way, if a user selects "language=nb" (Norwegian Bokmål), name:no should be used as a fallback for name:nb.

Admittedly the language fallback logic is not very sophisticated. Here’s where it lives:

export function getLocales() {
// Check the language "parameter" in the hash.
let parameter = getLanguageFromURL(window.location)?.split(",");
// Fall back to the user's language preference.
let userLocales = parameter ?? navigator.languages ?? [navigator.language];
let locales = [];
let localeSet = new Set(); // avoid duplicates
for (let locale of userLocales) {
// Add progressively less specific variants of each user-specified locale.
let components = locale.split("-");
while (components.length > 0) {
let parent = components.join("-");
if (!localeSet.has(parent)) locales.push(parent);
localeSet.add(parent);
components.pop();
}
}
return locales;
}

We could certainly add these special cases for Norwegian, since they’re pretty straightforward. More subjective fallbacks should probably be a server-side responsibility when generating the tiles, since the MapLibre expression language doesn’t give us very thorough text processing capabilities.

If a user selects "language=no" (Norwegian), if a name:no key is missing, the keys name:nn and name:nb should be used as fallback. This however only works if only one of them is present. If they are both present, they would need to be the same to be used. If they are different, one would have to open the can of worms of picking one of them as preferred, if one doesn't do something like peeking at the browser language to check which of the two forms the user prefers.

Most browsers or operating systems have a setting that lets you list languages in a preferred order. We do support this setting. You can manually specify Bokmål or Nynorsk as a fallback using the widget in the lower-right corner of the map. Alternatively, you can set the language URL parameter to a comma-separated list of locales, such as nn,no.

Is the name of countries special cased BTW?

Yes, the vector tiles don’t actually indicate the name of the administrative area on either side of a boundary, just the country code, so the boundary edge labels rely on your Web browser to convert the country code into a name in your preferred language. Most browsers get these names from the CLDR project. We would prefer to get the names from the tiles, for consistency with the main country labels, but this is the best we can do for now. You can contribute to CLDR, which will improve the state of localization industry-wide.

Is this the logic that's requested?
nn means nn,no
nb means nb,no ?

This sounds similar to the case with simplified and traditional Chinese, which might both fall back to zh.

Yes, that's the gist of it.

The problem is what to do when being requested no ("I want these names in Norwegian"). I suppose that runs into the same issues as zh.