Skip to content

Commit f2f2ff9

Browse files
committed
fix(list): get labels in native languages
1 parent 8e233ab commit f2f2ff9

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/components/main/list/list.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function controller($state, $stateParams, $timeout, langService, leafletData, lo
88
const vm = this;
99
const icon = mapService.getMapIcon();
1010
const id = $stateParams.id.includes('Q') ? $stateParams.id : `Q${$stateParams.id}`;
11-
const langs = langService.getUserLanguages();
11+
let langs = langService.getUserLanguages();
1212

1313
vm.filters = {};
1414
vm.image = [];
@@ -35,28 +35,34 @@ function controller($state, $stateParams, $timeout, langService, leafletData, lo
3535
WHERE {
3636
?item p:P1435 ?monument; wdt:P131* wd:${id}; wdt:P131 ?admin; wdt:P625 ?coord .
3737
OPTIONAL { ?item wdt:P18 ?image }
38-
OPTIONAL { ?admin rdfs:label ?adminLabel. FILTER(LANG(?adminLabel) = "${langs[0]}"). }
38+
OPTIONAL { ?admin rdfs:label ?adminLabel . FILTER(LANG(?adminLabel) IN ("${langs[0]}")) }
3939
SERVICE wikibase:label { bd:serviceParam wikibase:language "${langs.join(',')}" }
4040
}
4141
GROUP BY ?item ?itemLabel
4242
ORDER BY ?itemLabel`);
4343
}
4444

4545
function getPlace() {
46-
wikidata.getById(id).then((data) => {
46+
return wikidata.getById(id).then((data) => {
4747
const first = Object.keys(data)[0];
4848
vm.place = data[first];
4949

50+
const claims = vm.place.claims;
5051
if (vm.place.claims.P18) {
51-
const claims = vm.place.claims;
5252
claims.P18.values.forEach(image => getImage(image.value));
5353
}
54+
if (vm.place.claims.P17) {
55+
const country = claims.P17.values[0];
56+
langs = langs.concat(langService.getNativeLanguages(country.value_id));
57+
}
58+
return true;
5459
});
5560
}
5661

5762
function init() {
58-
getPlace();
59-
getList().then((data) => {
63+
getPlace()
64+
.then(() => getList())
65+
.then((data) => {
6066
// console.log(data)
6167
vm.list = data.map(element => ({
6268
name: {

0 commit comments

Comments
 (0)