From a4d18e25cbf45e1ae57f744f6ff8bbc396781490 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Fri, 15 Oct 2021 10:39:57 +0200 Subject: [PATCH 1/2] organisations: implement multilingual description * Updates organisation model to implement multilingual description. * Updates home template to use multilingual description. * Closes #639. --- data/organisations/data.json | 38 +++++++++++++- .../interface_language-v1.0.0.json | 33 ++++++++++++ .../organisation-v1.0.0_src.json | 50 ++++++++++++++++--- .../v7/organisations/organisation-v1.0.0.json | 10 +++- .../modules/organisations/marshmallow/json.py | 2 +- .../serializers/schemas/export.py | 2 +- sonar/theme/templates/sonar/frontpage.html | 2 +- .../templates/sonar/partial/organisation.html | 19 ++++++- .../sonar/partial/switch_aai_dropdown.html | 17 +++++++ 9 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 sonar/common/jsonschemas/interface_language-v1.0.0.json diff --git a/data/organisations/data.json b/data/organisations/data.json index 9b630028..24a620c9 100644 --- a/data/organisations/data.json +++ b/data/organisations/data.json @@ -13,7 +13,24 @@ { "code": "hepvs", "name": "HEP Valais", - "description": "Description in **markdown**", + "description": [ + { + "language": "ger", + "value": "Description in German in **markdown** format" + }, + { + "language": "eng", + "value": "Description in English in **markdown** format" + }, + { + "language": "fre", + "value": "Description in French in **markdown** format" + }, + { + "language": "ita", + "value": "Description in Italian in **markdown** format" + } + ], "isShared": true, "isDedicated": true, "platformName": "FREDI", @@ -40,7 +57,24 @@ { "code": "unifr", "name": "Université de Fribourg", - "description": "#### Français\nFOLIA est le serveur de dépôt institutionnel de l'Université de Fribourg (Suisse). Il fournit un accès libre aux publications des chercheurs et chercheuses de l'Université. FOLIA est géré par la Bibliothèque cantonale et universitaire de Fribourg.\n#### Deutsch\nFOLIA ist das institutionelle Repositorium der Universität Freiburg (Schweiz). Es bietet freien Zugang zu den Publikationen der Forschenden der Universität. FOLIA wird von der Kantons- und Universitätsbibliothek Freiburg betreut.\n#### English\nFOLIA is the institutional repository of the University of Fribourg (Switzerland). It provides free access to the publications of the researchers of the University. FOLIA is managed by the Bibliothèque cantonale et universitaire de Fribourg.\n#### Italiano\nFOLIA è l'archivio istituzionale dell'Università di Friburgo (Svizzera). Fornisce un accesso gratuito alle pubblicazioni dei ricercatrici e ricercatori dell'Università. FOLIA è gestito dalla Bibliothèque cantonale et universitaire de Fribourg.", + "description": [ + { + "language": "ger", + "value": "FOLIA ist das institutionelle Repositorium der Universität Freiburg (Schweiz). Es bietet freien Zugang zu den Publikationen der Forschenden der Universität. FOLIA wird von der Kantons- und Universitätsbibliothek Freiburg betreut." + }, + { + "language": "eng", + "value": "FOLIA is the institutional repository of the University of Fribourg (Switzerland). It provides free access to the publications of the researchers of the University. FOLIA is managed by the Bibliothèque cantonale et universitaire de Fribourg." + }, + { + "language": "fre", + "value": "FOLIA est le serveur de dépôt institutionnel de l'Université de Fribourg (Suisse). Il fournit un accès libre aux publications des chercheurs et chercheuses de l'Université. FOLIA est géré par la Bibliothèque cantonale et universitaire de Fribourg." + }, + { + "language": "ita", + "value": "FOLIA è l'archivio istituzionale dell'Università di Friburgo (Svizzera). Fornisce un accesso gratuito alle pubblicazioni dei ricercatrici e ricercatori dell'Università. FOLIA è gestito dalla Bibliothèque cantonale et universitaire de Fribourg." + } + ], "isShared": true, "isDedicated": true, "platformName": "# FOLIA\n#### Fribourg Open Library and Archive", diff --git a/sonar/common/jsonschemas/interface_language-v1.0.0.json b/sonar/common/jsonschemas/interface_language-v1.0.0.json new file mode 100644 index 00000000..00d8b056 --- /dev/null +++ b/sonar/common/jsonschemas/interface_language-v1.0.0.json @@ -0,0 +1,33 @@ +{ + "title": "language", + "type": "string", + "enum": [ + "ger", + "eng", + "fre", + "ita" + ], + "form": { + "templateOptions": { + "sort": true + }, + "options": [ + { + "label": "lang_ger", + "value": "ger" + }, + { + "label": "lang_eng", + "value": "eng" + }, + { + "label": "lang_fre", + "value": "fre" + }, + { + "label": "lang_ita", + "value": "ita" + } + ] + } +} diff --git a/sonar/modules/organisations/jsonschemas/organisations/organisation-v1.0.0_src.json b/sonar/modules/organisations/jsonschemas/organisations/organisation-v1.0.0_src.json index 0cd85082..5a220108 100644 --- a/sonar/modules/organisations/jsonschemas/organisations/organisation-v1.0.0_src.json +++ b/sonar/modules/organisations/jsonschemas/organisations/organisation-v1.0.0_src.json @@ -35,14 +35,50 @@ "minLength": 1 }, "description": { - "title": "Description", - "description": "HTML markup admitted.", - "type": "string", - "minLength": 1, + "title": "Descriptions", + "type": "array", + "minItems": 1, + "items": { + "title": "Description", + "type": "object", + "additionalProperties": false, + "properties": { + "value": { + "title": "Value", + "type": "string", + "minLength": 1, + "form": { + "type": "markdown", + "templateOptions": { + "rows": 5 + } + } + }, + "language": { + "$ref": "interface_language-v1.0.0.json" + } + }, + "propertiesOrder": [ + "language", + "value" + ], + "required": [ + "value", + "language" + ] + }, "form": { - "type": "markdown", - "templateOptions": { - "rows": 5 + "validation": { + "validators": { + "uniqueValueKeysInObject": { + "keys": [ + "language" + ] + } + }, + "messages": { + "uniqueValueKeysInObjectMessage": "Only one value per language is allowed" + } } } }, diff --git a/sonar/modules/organisations/mappings/v7/organisations/organisation-v1.0.0.json b/sonar/modules/organisations/mappings/v7/organisations/organisation-v1.0.0.json index badb8608..1810a424 100644 --- a/sonar/modules/organisations/mappings/v7/organisations/organisation-v1.0.0.json +++ b/sonar/modules/organisations/mappings/v7/organisations/organisation-v1.0.0.json @@ -15,7 +15,15 @@ "type": "keyword" }, "description": { - "type": "text" + "type": "object", + "properties": { + "language": { + "type": "keyword" + }, + "value": { + "type": "text" + } + } }, "name": { "type": "text", diff --git a/sonar/modules/organisations/marshmallow/json.py b/sonar/modules/organisations/marshmallow/json.py index 82a7e27d..359369da 100644 --- a/sonar/modules/organisations/marshmallow/json.py +++ b/sonar/modules/organisations/marshmallow/json.py @@ -43,7 +43,7 @@ class OrganisationMetadataSchemaV1(StrictKeysMixin): pid = PersistentIdentifier() code = SanitizedUnicode(required=True) name = SanitizedUnicode(required=True) - description = SanitizedUnicode() + description = fields.List(fields.Dict()) isShared = fields.Boolean() isDedicated = fields.Boolean() allowedIps = SanitizedUnicode() diff --git a/sonar/modules/organisations/serializers/schemas/export.py b/sonar/modules/organisations/serializers/schemas/export.py index 27efdb10..fefe34de 100644 --- a/sonar/modules/organisations/serializers/schemas/export.py +++ b/sonar/modules/organisations/serializers/schemas/export.py @@ -25,7 +25,7 @@ class ExportSchemaV1(Schema): code = fields.String(dump_only=True) name = fields.String(dump_only=True) - description = fields.String(dump_only=True) + description = fields.List(fields.Dict(dump_only=True)) isShared = fields.Boolean(dump_only=True) isDedicated = fields.Boolean(dump_only=True) files = fields.Method('get_files', dump_only=True) diff --git a/sonar/theme/templates/sonar/frontpage.html b/sonar/theme/templates/sonar/frontpage.html index 92093b90..1a3ff418 100755 --- a/sonar/theme/templates/sonar/frontpage.html +++ b/sonar/theme/templates/sonar/frontpage.html @@ -89,7 +89,7 @@
{% include config['SONAR_APP_ORGANISATION_CONFIG'][g.organisation.pid]['home_template'] %} {% else %} {% if g.organisation.get('description') %} - {{ g.organisation.description | markdown_filter | safe }} + {{ g.organisation.description | language_value | markdown_filter | safe }} {% endif %} {% endif %} diff --git a/sonar/theme/templates/sonar/partial/organisation.html b/sonar/theme/templates/sonar/partial/organisation.html index 22cc1b02..4d5245d8 100644 --- a/sonar/theme/templates/sonar/partial/organisation.html +++ b/sonar/theme/templates/sonar/partial/organisation.html @@ -1,3 +1,20 @@ +{# -*- coding: utf-8 -*- + Swiss Open Access Repository + Copyright (C) 2021 RERO + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} + {% if g.get('organisation') and not g.organisation['isDedicated'] %}
@@ -11,7 +28,7 @@

{{ g.organisation.name }}

{% if g.organisation.get('description') %} -

{{ g.organisation.description | markdown_filter | safe }}

+

{{ g.organisation.description | language_value | markdown_filter | safe }}

{% endif %}
diff --git a/sonar/theme/templates/sonar/partial/switch_aai_dropdown.html b/sonar/theme/templates/sonar/partial/switch_aai_dropdown.html index c9744acf..6be2a583 100644 --- a/sonar/theme/templates/sonar/partial/switch_aai_dropdown.html +++ b/sonar/theme/templates/sonar/partial/switch_aai_dropdown.html @@ -1,3 +1,20 @@ +{# -*- coding: utf-8 -*- + Swiss Open Access Repository + Copyright (C) 2021 RERO + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} +