Skip to content

Commit

Permalink
Use user's locale for fetching wikidata label/description
Browse files Browse the repository at this point in the history
(closes #5563)
  • Loading branch information
bhousel committed Dec 12, 2018
1 parent 9aceb8f commit 3de0343
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions modules/services/wikidata.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _uniq from 'lodash-es/uniq';

import { json as d3_json } from 'd3-request';

import { utilQsString } from '../util';
Expand All @@ -24,9 +26,11 @@ export default {
}

lang = lang || 'en';

d3_json(endpoint + utilQsString({
action: 'wbgetentities',
format: 'json',
formatversion: 2,
sites: lang.replace(/-/g, '_') + 'wiki',
titles: title,
languages: 'en', // shrink response by filtering to one language
Expand All @@ -40,6 +44,7 @@ export default {
});
},


entityByQID: function(qid, callback) {
if (!qid) {
callback('', {});
Expand All @@ -50,15 +55,20 @@ export default {
return;
}

var lang = currentLocale.replace(/-/g, '_');
var langs = _uniq([
currentLocale.toLowerCase(),
currentLocale.split('-', 2)[0].toLowerCase(),
'en'
]);

d3_json(endpoint + utilQsString({
action: 'wbgetentities',
format: 'json',
formatversion: 2,
ids: qid,
props: /*sitelinks|*/'labels|descriptions',
//sitefilter: lang + 'wiki',
languages: lang,
languages: langs.join('|'),
languagefallback: 1,
origin: '*'
}), function(err, data) {
Expand Down

0 comments on commit 3de0343

Please sign in to comment.