ZeLonewolf / openstreetmap-americana

A quintessentially American map style
https://zelonewolf.github.io/openstreetmap-americana
Creative Commons Zero v1.0 Universal
173 stars 56 forks source link

Norwegian names and language codes #1114

Open hohMiyazawa opened 5 days ago

hohMiyazawa commented 5 days ago

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:

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:

Just another slightly complicated language situation out there :)

hohMiyazawa commented 5 days ago

(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)

1ec5 commented 5 days ago

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:

https://github.com/ZeLonewolf/openstreetmap-americana/blob/d4a95a6a9080b0b4032137719d7729a1622c8b59/src/constants/label.js#L14-L32

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.

ZeLonewolf commented 2 days ago

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.

hohMiyazawa commented 2 days ago

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.