Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wikidata field broken for some languages #9638

Closed
wants to merge 1 commit into from

Conversation

k-yle
Copy link
Collaborator

@k-yle k-yle commented May 13, 2023

today is an amazing day.... for years I thought the wikidata field was a dumb readonly field, and I've always used the raw tag editor to set this key.

I only realized today that it's supposed to have dropdown suggestions.... It's never worked for me, because my language is set to en-NZ which the wikidata API rejects, causing the field to delete everything you type into it

I'm not sure if simply stripping out the -XX country code suffix is the right solution, but this is an incredible QOL improvement

image

(although the suggestions are a bit weird)

@@ -32,9 +32,11 @@ export default {
search: query,
type: 'item',
// the language to search
language: lang,
// do not include the country-code suffix
language: lang.split('-')[0],
Copy link
Collaborator

@1ec5 1ec5 May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if simply stripping out the -XX country code suffix is the right solution, but this is an incredible QOL improvement

Unfortunately, this would regress important behavior in several languages, such as Serbian and Chinese, where the country or script would be quite significant. Even in English, Wikibase supports en-ca, en-gb, and en-us but not en-nz for some reason. This API request returns the list of languages supported for labels in Wikibase.

Considering that NZ English has some terms that differ from both British and American English, it may make sense to request it as a new Wikibase language on Phabricator, where a contributor recently worked out how to add new languages.

Actually, MediaWiki requires the language codes to be fully lowercase, not with uppercase regions as is the norm. iD has a workaround for American English that appears to be unnecessary, but I guess you could use it as a simple workaround for NZ English:

}).filter(function(code) {
// HACK: en-us isn't a wikidata language. We should really be filtering by
// the languages known to be supported by wikidata.
return code !== 'en-us';
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, that's really helpful!

I had a look thru all the languages that iD supports, and of those, this issue seems to affect en-NZ, en-AU, en-IE, en-IN, nl-NL, he-IL, fa-IR, fr-FR, and ar-AA

I'm a bit confused though, I see this request to support en-IN and this one for en-AU appear to be "resolved", but neither locale is supported by the API...1

Footnotes

  1. I've been testing this by opening this URL in a new tab and tweaking language=*

Copy link
Collaborator

@1ec5 1ec5 May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused though, I see this request to support en-IN and this one for en-AU appear to be "resolved", but neither locale is supported by the API...1

These were requests for Wikibase to accept new languages as the language of the value of a statement for which the property’s data type is “monolingual text”. For example, you can now add a statement to say this item’s name is something different in Indian English or that this item’s title is something different in Australian English, but this doesn’t affect either item’s label in any language.

Yes, MediaWiki/Wikibase have multiple differing lists of all the languages for hysterical reasons.

// the language for the label and description in the result
uselang: lang,
// do not include the country-code suffix
uselang: lang.split('-')[0],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API query returns the list of interface languages supported by MediaWiki. However, MediaWiki is more lenient; you can use en-NZ as an interface language to get the expected results in English. (Using a more obscure interface language tends to prevent a site’s customized messages from coming through, but this is irrelevant for item queries.)

@tyrasd tyrasd added the bug A bug - let's fix this! label May 23, 2023
@tyrasd tyrasd closed this in 862ca65 May 23, 2023
@tyrasd
Copy link
Member

tyrasd commented May 23, 2023

I solved this slightly differently in 862ca65 by just re-requesting the API with the simplified language code if the returned error looks like the language was the issue. This gracefully falls back to the intended behavior once the wikidata API adds supports for en-NZ, etc.

@k-yle k-yle deleted the wikidata-field-broken branch May 23, 2023 19:17
@1ec5
Copy link
Collaborator

1ec5 commented May 25, 2023

Possibly relevant MediaWiki issue:

https://phabricator.wikimedia.org/T156220

@tyrasd tyrasd added this to the 2.26 milestone May 26, 2023
@k-yle
Copy link
Collaborator Author

k-yle commented Jul 6, 2023

hey @tyrasd, your fix in 862ca65 doesn't seem to work for me, I think it might be because there's no return statement after this line, so the code is calling callback() immediately instead of retrying the request

@tyrasd
Copy link
Member

tyrasd commented Jul 7, 2023

Good catch! It was that in combination with the this parameter not being available in the retry code path. That's now fixed in ea054a0. Can you please double-check if it works?

@k-yle
Copy link
Collaborator Author

k-yle commented Jul 7, 2023

thanks! it works perfectly now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug - let's fix this!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants