Skip to content

Commit

Permalink
feat: Landing page can be localized
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 1, 2023
1 parent 08fbffb commit 4d17f38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ You can also check the [release page](https://github.com/visualize-admin/visuali

## Unreleased

Nothing yet.
- Features
- Localized cube landing pages are now supported (dcat:landingPage) 🌎

# [3.24.2] - 2023-11-28

Expand Down
5 changes: 4 additions & 1 deletion app/rdf/query-cube-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export const getCubeMetadata = async (
?contactPoint ${ns.vcard.hasEmail} ?contactPointEmail .
}
OPTIONAL { ?iri ${ns.dcterms.publisher} ?publisher . }
OPTIONAL { ?iri ${ns.dcat.landingPage} ?landingPage . }
${buildLocalizedSubQuery("iri", "dcat:landingPage", "landingPage", {
locale,
fallbackToNonLocalized: true,
})}
OPTIONAL { ?iri ${ns.schema.expires} ?expires . }
OPTIONAL { ?iri ${ns.schema.workExample} ?workExample . }
`.GROUP().BY`?iri`.THEN.BY`?identifier`.THEN.BY`?title`.THEN.BY`?description`
Expand Down
15 changes: 11 additions & 4 deletions app/rdf/query-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ export const buildLocalizedSubQuery = (
s: string,
p: string,
o: string,
{ locale }: { locale: string }
{
locale,
fallbackToNonLocalized,
}: {
locale: string;
fallbackToNonLocalized?: boolean;
}
) => {
// Include the empty locale as well.
const locales = getOrderedLocales(locale).concat("");
Expand All @@ -23,9 +29,10 @@ export const buildLocalizedSubQuery = (
}`
)
.join("\n")}
BIND(COALESCE(${locales
.map((locale) => `?${o}_${locale}`)
.join(", ")}) AS ?${o})
${fallbackToNonLocalized ? `OPTIONAL { ?${s} ${p} ?${o}_raw }` : ""}
BIND(COALESCE(${locales.map((locale) => `?${o}_${locale}`).join(", ")} ${
fallbackToNonLocalized ? `, ?${o}_raw` : ``
}) AS ?${o})
`;
};

Expand Down

0 comments on commit 4d17f38

Please sign in to comment.