From c2bd604e35c6909f96e18cc889986828bc57835f Mon Sep 17 00:00:00 2001 From: Matthew Foster Date: Wed, 14 Feb 2024 16:29:53 -0800 Subject: [PATCH] update bilingual template to handle translation key --- .../iso19115-cioos-template/bilingual.j2 | 10 ++++++---- metadata_xml/iso19115-cioos-template/main.j2 | 8 ++++---- sample_records/record.yml | 20 +++++++++++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/metadata_xml/iso19115-cioos-template/bilingual.j2 b/metadata_xml/iso19115-cioos-template/bilingual.j2 index 3af350c..afda0c6 100644 --- a/metadata_xml/iso19115-cioos-template/bilingual.j2 +++ b/metadata_xml/iso19115-cioos-template/bilingual.j2 @@ -1,4 +1,4 @@ -{% macro bilingual(element,key,record_section, translationKey) -%} +{% macro bilingual(element,key,record_section) -%} {% set value = record_section[key] %} {% if (value is not mapping) or (value.items()|length==1 and lang in value) %} @@ -17,10 +17,12 @@ {{- value[lang]|e -}} {% endif %} + {% set translations = value.get("translations", {})%} {% for secondary_lang,val in value.items() %} - {% if secondary_lang != lang %} - {% if translationKey %} - + {% if secondary_lang != lang and secondary_lang != 'translations'%} + {% set translationMessage = translations.get(secondary_lang,{}).get("message")%} + {% if translationMessage %} + {% else %} {% endif %} diff --git a/metadata_xml/iso19115-cioos-template/main.j2 b/metadata_xml/iso19115-cioos-template/main.j2 index d848881..3b3d1d1 100644 --- a/metadata_xml/iso19115-cioos-template/main.j2 +++ b/metadata_xml/iso19115-cioos-template/main.j2 @@ -228,7 +228,7 @@ {# title: mandatory #} - {{- bl.bilingual('cit:title','title', record['identification'], 'titleTranslationMethod') -}} + {{- bl.bilingual('cit:title','title', record['identification']) -}} {# date pubished/revised isnt required #} {% if 'dates' in record['identification'] %} @@ -283,7 +283,7 @@ {# abstract: mandatory #} {# CIOOS core mandatory element #} {# MI_Metadata/identificationInfo/MD_DataIdentification/abstract/CharacterString #} - {{- bl.bilingual('mri:abstract', 'abstract', record['identification'], 'abstractTranslationMethod') -}} + {{- bl.bilingual('mri:abstract', 'abstract', record['identification']) -}} {{- bl.bilingual('mri:credit', 'acknowledgement', record['identification']) -}} @@ -586,7 +586,7 @@ {# MD_Constraints: CIOOS core mandatory #} {# useLimitation: CIOOS core mandatory #} - {{- bl.bilingual('mco:useLimitation', 'limitations', record['metadata']['use_constraints'], 'limitationsTranslationMethod') -}} + {{- bl.bilingual('mco:useLimitation', 'limitations', record['metadata']['use_constraints']) -}} {% endif %} @@ -757,7 +757,7 @@ {# description: mandatory #} {# CIOOS core mandatory element #} {# MI_Metadata/acquisitionInformation/MI_AcquisitionInformation/platform/MI_Platform/description/CharacterString #} - {{- bl.bilingual('mac:description', 'description', record['platform'], 'platformDescriptionTranslationMethod') -}} + {{- bl.bilingual('mac:description', 'description', record['platform']) -}} {% for instrument in record['platform']['instruments'] %} {# instrument: Recommended, if platform not used then this should be under mac:MI_AcquisitionInformation #} diff --git a/sample_records/record.yml b/sample_records/record.yml index 65c18ce..a9de04c 100644 --- a/sample_records/record.yml +++ b/sample_records/record.yml @@ -16,7 +16,10 @@ metadata: limitations: en: limitations in english fr: limitations in french - limitationsTranslationMethod: Auto-translated using AWS + translations: + fr: + validated: false + message: Auto-translated using AWS licence: title: Creative Commons Attribution 4.0 code: CC-BY-4.0 @@ -41,13 +44,19 @@ identification: title: en: title in english fr: title in french - titleTranslationMethod: Auto-translated using AWS + translations: + fr: + validated: false + message: Auto-translated using AWS identifier: http://dx.doi.org/10.1093/ajae/aaq063 abstract: en: abstract in english fr: abstract in french - abstractTranslationMethod: Auto-translated using AWS + translations: + fr: + validated: false + message: Auto-translated using AWS associated_resources: - title: en: associated resource title in english @@ -131,7 +140,10 @@ platform: description: en: platformDescription in English fr: platformDescription in French - platformDescriptionTranslationMethod: Auto-translated using AWS + translations: + fr: + validated: true + message: Auto-translated using AWS instruments: - id: 123 manufacturer: manufacturer en 1