ULB-Darmstadt / shacl-form

HTML5 web component for editing/viewing RDF data that conform to SHACL shapes
https://ulb-darmstadt.github.io/shacl-form/
MIT License
28 stars 5 forks source link

Use Accept-Language for owl:imports #19

Closed renevoorburg closed 4 months ago

renevoorburg commented 4 months ago

It is a nice feature to be able to do owl:imports!

The demo for those imports at https://ulb-darmstadt.github.io/shacl-form/#example returns the German labels for the Roles even when English is in my accept-language header and German isn't ("nl,en;q=0.7,en-US;q=0.3"). I would have expected the English labels to show up here.

s-tittel commented 4 months ago

Yes, the preferred languages were not handled correctly. Please check v1.4.7, that should work now.

renevoorburg commented 4 months ago

Now, when I have Accept-Language set to "nl,de-DE;q=0.7,en;q=0.3" it displays the English texts while it should display the German texts. Same with "nl,en;q=0.7,de-DE;q=0.3", so it seems to ignore German when English is in the list. Indeed, I only managed to get it to display the German texts again when removing English from the preferred languages (nl,de-DE;q=0.5).

s-tittel commented 4 months ago

That's because the langStrings in the mentioned taxonomy use "en" and "de". So "de" is not the same as "de-DE". Do you think it would be feasible to ignore the dash and everything that follows, so that "de-DE" gets converted to "de"?

renevoorburg commented 4 months ago

It is not the perfect approach, but in this context (linked data with language tags) I think a good approach would indeed be to ignore everything from the dash onward.

s-tittel commented 4 months ago

Please check v1.4.8, the languages are now constructed like this:

this.languages = [... new Set(navigator.languages.flatMap(lang => {
    if (lang.length > 2) {
        return [lang, lang.substring(0, 2)]
    } 
    return lang
}))]

So basically, when the list of navigator.languages contains a 5 letter code (e.g. de-DE), the corresponding 2 letter code (e.g. de) gets inserted directly after the 5 letter code.

renevoorburg commented 4 months ago

Works perfectly!