Skip to content

Commit

Permalink
Add some basic translations/mappings for facet values
Browse files Browse the repository at this point in the history
Add a custom web componetn which looks up translations based
on a fixed form at and the typesense field name.

While at it also change the "mime type" to "file format" and map
the PDF mime type, since no one knows what mime types are.

TODO:

* language switcher doesn't work, don't know why
* use the translations in the form build as well
* don't register the web component globally
  • Loading branch information
lazka committed Jan 16, 2025
1 parent ded808f commit 71cc03c
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 7 deletions.
45 changes: 42 additions & 3 deletions src/components/dbp-cabinet-facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,52 @@
import {ScopedElementsMixin} from '@dbp-toolkit/common';
import {css, html, render, unsafeCSS} from 'lit';
import * as commonStyles from '@dbp-toolkit/common/styles';
import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element';
import DBPCabinetLitElement from '../dbp-cabinet-lit-element.js';
import {panel, refinementList } from 'instantsearch.js/es/widgets/index.js';
import {connectCurrentRefinements, connectClearRefinements} from 'instantsearch.js/es/connectors';
import {createDateRefinement} from './dbp-cabinet-date-facet.js';
import {getIconSVGURL} from '../utils.js';
import {createInstance} from '../i18n.js';

class FacetLabel extends DBPLitElement {
constructor() {
super();
this._i18n = createInstance();
this.lang = this._i18n.language;
this.namespace = "";
this.value = "";
}

static get properties() {
return {
...super.properties,
lang: {type: String},
namespace: {type: String},
value: {type: String},
};
}

render() {
let text = this._i18n.t(`typesense-schema.${this.namespace}.${this.value}`, this.value);
return html`${text}`;
}

update(changedProperties) {
changedProperties.forEach((oldValue, propName) => {
switch (propName) {
case 'lang':
this._i18n.changeLanguage(this.lang);
break;
}
});

super.update(changedProperties);
}
}

// FIXME: don't register globally
customElements.define('dbp-cabinet-facet-label', FacetLabel);

export class CabinetFacets extends ScopedElementsMixin(DBPCabinetLitElement) {
constructor() {
Expand Down Expand Up @@ -355,9 +396,7 @@ export class CabinetFacets extends ScopedElementsMixin(DBPCabinetLitElement) {
value="${item.value}"
checked=${item.isRefined} />
</label>
<span class="refinement-list-item-name" title="${item.label}">
${item.label}
</span>
<dbp-cabinet-facet-label subscribe="lang" class="refinement-list-item-name" title="${item.label}" namespace="${schemaField}" value="${item.value}"></dbp-cabinet-facet-label>
</div>
<span class="refinement-list-item-count">(${item.count})</span>
</div>
Expand Down
118 changes: 116 additions & 2 deletions src/i18n/de/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,118 @@
{
"typesense-schema": {
"@type": {
"Person": "Person",
"DocumentFile": "Dokument"
},
"file.base.fileSource": {
"cabinet-bucket": "Manuell hochgeladen"
},
"file.base.isPartOf": {
"CostReimbursement": "Kostenerstattung"
},
"file.file-cabinet-admissionNotice.decision": {
"rejected": "Abgelehnt",
"refused": "Verweigert",
"granted": "Bewilligt"
},
"file.base.mimeType": {
"application/pdf": "PDF (.pdf)"
},
"file.file-cabinet-citizenshipCertificate.nationality": {
"ALB": "Albanien",
"AND": "Andorra",
"AUT": "Österreich",
"BLR": "Belarus",
"BEL": "Belgien",
"BIH": "Bosnien und Herzegowina",
"BGR": "Bulgarien",
"HRV": "Kroatien",
"CYP": "Zypern",
"CZE": "Tschechische Republik",
"DNK": "Dänemark",
"EST": "Estland",
"FIN": "Finnland",
"FRA": "Frankreich",
"DEU": "Deutschland",
"GRC": "Griechenland",
"HUN": "Ungarn",
"ISL": "Island",
"IRL": "Irland",
"ITA": "Italien",
"LVA": "Lettland",
"LIE": "Liechtenstein",
"LTU": "Litauen",
"LUX": "Luxemburg",
"MLT": "Malta",
"MDA": "Moldawien",
"MCO": "Monaco",
"MNE": "Montenegro",
"NLD": "Niederlande",
"MKD": "Nordmazedonien",
"NOR": "Norwegen",
"POL": "Polen",
"PRT": "Portugal",
"ROU": "Rumänien",
"RUS": "Russland",
"SMR": "San Marino",
"SRB": "Serbien",
"SVK": "Slowakei",
"SVN": "Slowenien",
"ESP": "Spanien",
"SWE": "Schweden",
"CHE": "Schweiz",
"UKR": "Ukraine",
"GBR": "Vereinigtes Königreich",
"VAT": "Vatikanstadt"
},
"file.file-cabinet-identityDocument.nationality": {
"ALB": "Albanien",
"AND": "Andorra",
"AUT": "Österreich",
"BLR": "Belarus",
"BEL": "Belgien",
"BIH": "Bosnien und Herzegowina",
"BGR": "Bulgarien",
"HRV": "Kroatien",
"CYP": "Zypern",
"CZE": "Tschechische Republik",
"DNK": "Dänemark",
"EST": "Estland",
"FIN": "Finnland",
"FRA": "Frankreich",
"DEU": "Deutschland",
"GRC": "Griechenland",
"HUN": "Ungarn",
"ISL": "Island",
"IRL": "Irland",
"ITA": "Italien",
"LVA": "Lettland",
"LIE": "Liechtenstein",
"LTU": "Litauen",
"LUX": "Luxemburg",
"MLT": "Malta",
"MDA": "Moldawien",
"MCO": "Monaco",
"MNE": "Montenegro",
"NLD": "Niederlande",
"MKD": "Nordmazedonien",
"NOR": "Norwegen",
"POL": "Polen",
"PRT": "Portugal",
"ROU": "Rumänien",
"RUS": "Russland",
"SMR": "San Marino",
"SRB": "Serbien",
"SVK": "Slowakei",
"SVN": "Slowenien",
"ESP": "Spanien",
"SWE": "Schweden",
"CHE": "Schweiz",
"UKR": "Ukraine",
"GBR": "Vereinigtes Königreich",
"VAT": "Vatikanstadt"
}
},
"cabinet-search": {
"filters": "Filter",
"type-filter-group-title": "Kategorie",
Expand Down Expand Up @@ -26,8 +140,8 @@
"filter-study-type-title": "Abschlussziel",
"filter-study-status-text-title": "Studienstatus",
"filter-file-base-additional-type-text-title": "Dokumenttyp",
"filter-file-base-mime-type-title": "MIME typ",
"filter-file-base-file-source-title": "Digitalisatsquelle",
"filter-file-base-mime-type-title": "Dateiformat",
"filter-file-base-file-source-title": "Dateiquelle",
"filter-file-base-semester-title": "Semester",
"filter-file-base-study-field-name-title": "Studium",
"filter-file-base-is-part-of-title": "Zugeordneter Vorgang",
Expand Down
118 changes: 116 additions & 2 deletions src/i18n/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,118 @@
{
"typesense-schema": {
"@type": {
"Person": "Person",
"DocumentFile": "Document"
},
"file.base.fileSource": {
"cabinet-bucket": "Manually uploaded"
},
"file.base.isPartOf": {
"CostReimbursement": "Cost Reimbursement"
},
"file.file-cabinet-admissionNotice.decision": {
"rejected": "Rejected",
"refused": "Refused",
"granted": "Granted"
},
"file.base.mimeType": {
"application/pdf": "PDF (.pdf)"
},
"file.file-cabinet-citizenshipCertificate.nationality": {
"ALB": "Albania",
"AND": "Andorra",
"AUT": "Austria",
"BLR": "Belarus",
"BEL": "Belgium",
"BIH": "Bosnia and Herzegovina",
"BGR": "Bulgaria",
"HRV": "Croatia",
"CYP": "Cyprus",
"CZE": "Czech Republic",
"DNK": "Denmark",
"EST": "Estonia",
"FIN": "Finland",
"FRA": "France",
"DEU": "Germany",
"GRC": "Greece",
"HUN": "Hungary",
"ISL": "Iceland",
"IRL": "Ireland",
"ITA": "Italy",
"LVA": "Latvia",
"LIE": "Liechtenstein",
"LTU": "Lithuania",
"LUX": "Luxembourg",
"MLT": "Malta",
"MDA": "Moldova",
"MCO": "Monaco",
"MNE": "Montenegro",
"NLD": "Netherlands",
"MKD": "North Macedonia",
"NOR": "Norway",
"POL": "Poland",
"PRT": "Portugal",
"ROU": "Romania",
"RUS": "Russia",
"SMR": "San Marino",
"SRB": "Serbia",
"SVK": "Slovakia",
"SVN": "Slovenia",
"ESP": "Spain",
"SWE": "Sweden",
"CHE": "Switzerland",
"UKR": "Ukraine",
"GBR": "United Kingdom",
"VAT": "Vatican City"
},
"file.file-cabinet-identityDocument.nationality": {
"ALB": "Albania",
"AND": "Andorra",
"AUT": "Austria",
"BLR": "Belarus",
"BEL": "Belgium",
"BIH": "Bosnia and Herzegovina",
"BGR": "Bulgaria",
"HRV": "Croatia",
"CYP": "Cyprus",
"CZE": "Czech Republic",
"DNK": "Denmark",
"EST": "Estonia",
"FIN": "Finland",
"FRA": "France",
"DEU": "Germany",
"GRC": "Greece",
"HUN": "Hungary",
"ISL": "Iceland",
"IRL": "Ireland",
"ITA": "Italy",
"LVA": "Latvia",
"LIE": "Liechtenstein",
"LTU": "Lithuania",
"LUX": "Luxembourg",
"MLT": "Malta",
"MDA": "Moldova",
"MCO": "Monaco",
"MNE": "Montenegro",
"NLD": "Netherlands",
"MKD": "North Macedonia",
"NOR": "Norway",
"POL": "Poland",
"PRT": "Portugal",
"ROU": "Romania",
"RUS": "Russia",
"SMR": "San Marino",
"SRB": "Serbia",
"SVK": "Slovakia",
"SVN": "Slovenia",
"ESP": "Spain",
"SWE": "Sweden",
"CHE": "Switzerland",
"UKR": "Ukraine",
"GBR": "United Kingdom",
"VAT": "Vatican City"
}
},
"cabinet-search": {
"filters": "Filters",
"type-filter-group-title": "Category",
Expand Down Expand Up @@ -26,8 +140,8 @@
"filter-study-type-title": "Degree",
"filter-study-status-text-title": "Study status",
"filter-file-base-additional-type-text-title": "Document type",
"filter-file-base-mime-type-title": "MIME type",
"filter-file-base-file-source-title": "Digital document source",
"filter-file-base-mime-type-title": "File format",
"filter-file-base-file-source-title": "File source",
"filter-file-base-semester-title": "Semester",
"filter-file-base-study-field-name-title": "Study field",
"filter-file-base-is-part-of-title": "Assigned process",
Expand Down

0 comments on commit 71cc03c

Please sign in to comment.