Skip to content

Commit e1f9191

Browse files
committed
fix: fix programming language default local
1 parent a81e014 commit e1f9191

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

api/src/core/adapters/wikidata/getWikidataSoftware.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,19 @@ function wikidataSingleLocalizedStringToLocalizedString(
310310
Object.fromEntries(languages.map(language => [language, wikidataSingleLocalizedString[language]?.value]))
311311
);
312312

313-
if (Object.keys(localizedString).length === 0) {
314-
return wikidataSingleLocalizedString[Object.keys(wikidataSingleLocalizedString)[0]]?.value;
313+
const wikidataLocals = Object.keys(localizedString);
314+
315+
if (wikidataLocals.length === 0) {
316+
const fallbackLocalForAllLanguage = "mul"; // used by wikidata
317+
const firstLocalInList = Object.keys(wikidataSingleLocalizedString)[0];
318+
return (
319+
wikidataSingleLocalizedString[fallbackLocalForAllLanguage]?.value ??
320+
wikidataSingleLocalizedString[firstLocalInList]?.value
321+
);
315322
}
316323

317324
if (Object.values(localizedString).reduce(...allEquals())) {
318-
return localizedString[Object.keys(localizedString)[0]];
325+
return localizedString[wikidataLocals[0]];
319326
}
320327

321328
return localizedString;

api/src/core/usecases/refreshExternalData.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ describe("fetches software extra data (from different providers)", () => {
297297
"//upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Vitejs-logo.svg/250px-Vitejs-logo.svg.png",
298298
sourceUrl: "https://github.com/vitejs/vite",
299299
websiteUrl: "https://vite.dev/",
300-
programmingLanguages: ["جافا سكريبت"],
300+
programmingLanguages: ["JavaScript"],
301301
referencePublications: undefined,
302302
identifiers: [
303303
{
@@ -410,7 +410,7 @@ describe("fetches software extra data (from different providers)", () => {
410410
"value": "Q11354"
411411
}
412412
],
413-
programmingLanguages: ["Си"],
413+
programmingLanguages: ["C"],
414414
softwareVersion: "2.5.0-alpha",
415415
publicationTime: new Date("2017-11-08T00:00:00.000Z"),
416416
lastDataFetchAt: expect.any(Number),

0 commit comments

Comments
 (0)