Repository navigation
consider name:* tags with the full locale code when labelling features - #10911
Conversation
tyrasd
left a comment
There was a problem hiding this comment.
It improves the current implementation significantly, so 👍 from my side. Feel free to merge as is, or to address the comments below.
- while this works well for the case reported in #10882, it does not seem to fully address the original issue from #10219:
- the common keys for Chinese names include ones with script codes (e.g.
name:zh-Hansorname:zh-Hant), but if, for example, a user hasnavigator.languages = ['zh-Hans-CN'], the labels would not be shown for tags likename:zh-Hans.
- It feels slightly odd that this is tied to iD's UI translations.
- Let's say a user has
navigator.language == 'lld'. They will get iD inen, as that's the best available fallback for UI translations. Ideally, they should see labels inlld - Similarly, if
navigator.languages = ['de-AT', 'de']. iD would be inde, but why would the user not get labels forde-AT
- Also, what's your opinion to extend this even further:
- when a user has multiple languages in their
navigator.languages, we could check the full fallback list: e.g. when a user hasnavigator.languages = ['lld', 'it', 'de', 'en'], features could be labeled by the respective languages in that order - we could consider "looking ahead" for any region codes in the
name:tag. e.g. if a user hasnavigator.languages = ['pt'], it might be ok to also display a label for aname:pt-BRtag, if there is noname:pt - same as the previous point, but for scripts: if
navigator.languages = ['zh-Hans-CN'], (thenlocalizer.localeCodes() == ['zh-CN'],) it would be ok to display labels inname:zh-Hans, maybe even in other scripts likename:zh-Hantorname:zh-Latn-pinyin
|
PS: do you have a clue what could cause this CI error? |
|
I was planning to send a third PR which does the special-casing for
Yeah, I also think this would be useful, but maybe in a separate PR? While this would be nice for me personally, it might be unexpected for others (#9499 in one such example) |
|
Let's prioritize #11082 for now, as that one is addressing the more often occurring situation in practice (i.e. a user has multiple locales as their preference and also solves the |
|
Since #11082 is stale, I've redone this PR to use This PR can now match |
| @@ -0,0 +1,45 @@ | |||
| import { utilArrayUniq } from './array'; | |||
|
|
|||
| function collectLocale({ script, region, language }: Intl.Locale) { | |||
There was a problem hiding this comment.
Some common tags require a variant code, such as the tarask in name:be-tarask=*. maximize() returns be-Cyrl-BY-tarask. There’s a variant property but only Firefox supports it.
This is an edge case that we can ticket out as tail work. iD doesn’t currently have any localizations that require a variant. The closest is our “ar-AA” locale, which should probably be just “ar”. (I think Transifex made up a country code for the Unitag variant.)
1ec5
left a comment
There was a problem hiding this comment.
This looks good to go from a code perspective. Before merging, please spot-check iD in any tricky localizations like Arabic, Chinese, or Serbian in places that might have secondary localized names in those languages.
435e7bb to
601f5c8
Compare
|
i made one change (5fe8f6e..601f5c8), so that base language is the last fallback, to fix case #3 below. seems like this works well:
🆕 means the behaviour was changed by this PR |
|
if there are no objections, i think we could merge this one? |
|
I implemented osm-americana/diplomat#30 based on the approach taken here. It works well. Diplomat needs to handle #11731 and even more complex language tags, so I modified the implementation to calculate a powerset instead of hard-coding specific combinations of language tag components. But I think what we have here is more than adequate for the issues iD users are noticing. |
I agree, we should not hard-coding the language combinations. For example, there are "name:zh name:zh-Hans name:zh-Hant name:zh-Hans-CN name:zh-Hans-SG name:zh-Hant-TW name:zh-Hant-HK name:zh-Hant-MO" and endless name:zh tags. If we just hard-coding, we can't handle all situations. |
|
Actually, I think we should allow users to customize language fallback solution, in My Advanced Preferences, users can define more than one preferred languages, can we allow users to directly write osm language tag(e.g. name:zh name:zh-Latn-pinyin) there? This way users can customized the language variants order. |
perhaps that should be discussed in #11730 ? |
|
sorry I forgot to update that part of the PR description, fixed now. #10219 will be fully fixed by this PR |
| // between runtimes. | ||
| it.each` | ||
| input | output | ||
| ${'en'} | ${['en', 'en-Latn-US', 'en-US', 'en-Latn']} |
There was a problem hiding this comment.
why 'en-Latn-US' is preferred over 'en-US' but en over 'en-Latn'?
(not saying it does not make sense, just I do not understand yet what is going on)
There was a problem hiding this comment.
and note it may affect anyone running tests after this is merged, including test attempts of something unrelated
There was a problem hiding this comment.
The fallback order I’m using in Diplomat and OSM Americana is en-Latn-US, en-Latn, en-US, en. (That’s what I meant by “powerset” in #10911 (comment).) The middle ones are more or less tied, but I’d err on the side of ensuring readability for someone who doesn’t necessarily know a writing system other than their own.
There was a problem hiding this comment.
why
'en-Latn-US'is preferred over'en-US'butenover'en-Latn'?
My original approach was to make the exact match come first (the user requested en so they get en).
But I implemented this before seeing Minh's more advanced version (which i think is brilliant btw), so we could change it to match diplomat's ordering if that's preferred (?)
There was a problem hiding this comment.
Personally I think that @1ec5 ordering seems to make more sense, but I lack expertise or experience or anything similar in this area.
There was a problem hiding this comment.
Yeah, ordering from most specific to least specific is important because of languages like Chinese. Browsers generally indicate the maximized locale, but mappers rarely tag that much detail because it doesn’t make a difference to the place name.
There was a problem hiding this comment.
sorry for the delay, i had to think about this a bit. I've copied the powerset approach from diplomat, with 2 changes that i find useful:
- if
x !== new Intl.Locale(x).baseName, then include and prioritisex. This is required to supportcmn, which the browser transforms into the macrolanguagezh1 - if the final array of locale codes does not include the original input, then include and prioritise the original. This is required to support extensions like
-u-sd-, for examplename:mi-u-sd-nzwko
unit tests added for both cases. I'm not certain if these are a good idea, and/or whether they're worth including in diplomat
Footnotes
There was a problem hiding this comment.
Feel free to post issues about any improvements that could potentially apply to Diplomat. I’ve been unsure what to do about cmn/zh. Despite it being a more specific code, BCP 47 and CLDR in practice favor zh-Hans-CN for backwards compatibility. As a result, some mappers have gone around replacing name:cmn=* with name:zh-Hans=*. I suspect this is motivated more by interoperability with the broader software ecosystem rather than a particular OSM data consumer. It probably deserves a forum discussion at some point.
Diplomat does have a later step to prefer the Unicode extensions, but a more elegant approach would be welcome.
There was a problem hiding this comment.
BTW, I found https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3_Retirements.tab via https://iso639-3.sil.org/code_tables/download_tables listing tripple letter deprecated language codes
are there other double letter deprecated language codes except iw, ji, in ?
There was a problem hiding this comment.
somehow i missed your question sorry. yes, the javascript API will transform 9 deprecated language codes:
bh→bho(Bhojpuri)in→id(Indonesian)iw→he(Hebrew)ji→yi(Yiddish)jw→jv(Javanese)mo→ro(Romanian)sh→sr(Serbian)tl→fil(Filipino)tw→ak(Akan)
(determined using brute force)
for (let i = 0; i < 26; i++) {
for (let j = 0; j < 26; j++) {
const old = String.fromCharCode(97+i) + String.fromCharCode(97+j);
const nēw = new Intl.Locale(old).language;
if (old !== nēw) {
const label = new Intl.DisplayNames(navigator.languages, { type: 'language' }).of(nēw);
console.log(`${old} → ${nēw} (${label})`);
}
}
}the only one i was suprised to see was tl, which is quite common in OSM, and iD also uses tl for localisations. i've added a test case for one "deprecated" code, but i don't think we need to anything else.
d200f48 to
e0bb401
Compare
Closes #10219, Closes #10882, Closes #11315, Closes #11731, Closes #11082 (superseeds that PR)
Thanks to
Intl.Locale#maximize, we can expand the user's locale code to add likely subtags, then try every combination oflanguage[+script[ +region]] until we find a matchingname:*tag.For example, we can expand
zh-CNtozh-Hans-CN, and expandzh-TWtozh-Hant-TW, without hardcoding these cases.Then, we use the most appropriate
name:*tag, first checkingname:zh-Hans-CN, thenname:zh-CN, thenname:zh-Hans, thenname:zh.This also fixes the
pt-BRcase from #10882