From d2e2e30b64e2627fcaf0bb50247c327a1de76acf Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Thu, 11 Jan 2024 11:23:38 -0800 Subject: [PATCH 1/3] fix sample command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f02fa9b..fde963c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ To convert a Yaml file to XML, run: eg: -`python -m metadata_xml -f sample_records/record.yaml` +`python -m metadata_xml -f sample_records/record.yml` ## Importing into other Python projects From 9b96ccc3fdfe6f51fae8cfc1d0c6d3a46fbee459 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Thu, 11 Jan 2024 11:28:48 -0800 Subject: [PATCH 2/3] update sample yml and jinja templates for translation message --- .gitignore | 3 ++- metadata_xml/iso19115-cioos-template/bilingual.j2 | 6 +++++- metadata_xml/iso19115-cioos-template/main.j2 | 8 ++++---- sample_records/record.yml | 12 ++++++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 67f47ac..4714e08 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,10 @@ __pycache__ *.egg-info venv/ +env/ .vscode .mypy* notforrepo *.xml cioos-schema -build +build \ No newline at end of file diff --git a/metadata_xml/iso19115-cioos-template/bilingual.j2 b/metadata_xml/iso19115-cioos-template/bilingual.j2 index 8ff8437..3af350c 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) -%} +{% macro bilingual(element,key,record_section, translationKey) -%} {% set value = record_section[key] %} {% if (value is not mapping) or (value.items()|length==1 and lang in value) %} @@ -19,7 +19,11 @@ {% for secondary_lang,val in value.items() %} {% if secondary_lang != lang %} + {% if translationKey %} + + {% else %} + {% endif %} {{- val|e -}} {% endif %} diff --git a/metadata_xml/iso19115-cioos-template/main.j2 b/metadata_xml/iso19115-cioos-template/main.j2 index 3b3d1d1..d848881 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']) -}} + {{- bl.bilingual('cit:title','title', record['identification'], 'titleTranslationMethod') -}} {# 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']) -}} + {{- bl.bilingual('mri:abstract', 'abstract', record['identification'], 'abstractTranslationMethod') -}} {{- 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']) -}} + {{- bl.bilingual('mco:useLimitation', 'limitations', record['metadata']['use_constraints'], 'limitationsTranslationMethod') -}} {% 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']) -}} + {{- bl.bilingual('mac:description', 'description', record['platform'], 'platformDescriptionTranslationMethod') -}} {% 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 13fcd98..65c18ce 100644 --- a/sample_records/record.yml +++ b/sample_records/record.yml @@ -13,7 +13,10 @@ metadata: language: en maintenance_note: maintenance_note use_constraints: - limitations: limitations + limitations: + en: limitations in english + fr: limitations in french + limitationsTranslationMethod: Auto-translated using AWS licence: title: Creative Commons Attribution 4.0 code: CC-BY-4.0 @@ -38,11 +41,13 @@ identification: title: en: title in english fr: title in french + titleTranslationMethod: 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 associated_resources: - title: en: associated resource title in english @@ -123,7 +128,10 @@ platform: name: platform_name authority: platform_authority id: platform id - description: platform_description + description: + en: platformDescription in English + fr: platformDescription in French + platformDescriptionTranslationMethod: Auto-translated using AWS instruments: - id: 123 manufacturer: manufacturer en 1 From c2bd604e35c6909f96e18cc889986828bc57835f Mon Sep 17 00:00:00 2001 From: Matthew Foster Date: Wed, 14 Feb 2024 16:29:53 -0800 Subject: [PATCH 3/3] 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