From 105d5bd2ef345c29aa8d8ec13acdd9129fa55c5c Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Tue, 20 Feb 2024 21:12:32 -0800 Subject: [PATCH] Tweaks to ensure proper parsing of language codes and keywords. --- ricecooker/utils/SCORM_metadata.py | 14 +++++++++++--- .../complete_manifest_with_external_metadata.xml | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ricecooker/utils/SCORM_metadata.py b/ricecooker/utils/SCORM_metadata.py index d1dfe21a..12abb47e 100644 --- a/ricecooker/utils/SCORM_metadata.py +++ b/ricecooker/utils/SCORM_metadata.py @@ -4,6 +4,7 @@ from le_utils.constants.labels import learning_activities from le_utils.constants.labels import needs from le_utils.constants.labels import resource_type +from le_utils.constants.languages import getlang imscp_metadata_keys = { @@ -155,9 +156,16 @@ def infer_beginner_level_from_difficulty(metadata_dict): def update_node_from_metadata(node, metadata_dict): # Update the node with the general metadata node.description = metadata_dict.get("description") or node.description - if metadata_dict.get("language"): - node.set_language(metadata_dict.get("language")) - node.tags = node.tags + metadata_dict.get("keyword", []) + lang_code = metadata_dict.get("language", "") + lang_code = ( + lang_code.split("-")[0].lower() if getlang(lang_code) is None else lang_code + ) + if getlang(lang_code): + node.set_language(lang_code) + keyword = metadata_dict.get("keyword", []) + if keyword and isinstance(keyword, str): + keyword = [keyword] + node.tags = node.tags + keyword # Update the node with the educational metadata node.learning_activities = ( diff --git a/tests/testcontent/samples/ims_xml/complete_manifest_with_external_metadata.xml b/tests/testcontent/samples/ims_xml/complete_manifest_with_external_metadata.xml index 98afd161..804647ec 100644 --- a/tests/testcontent/samples/ims_xml/complete_manifest_with_external_metadata.xml +++ b/tests/testcontent/samples/ims_xml/complete_manifest_with_external_metadata.xml @@ -45,6 +45,7 @@ example of proper metadata element usage. Explore the fascinating world of hummingbirds, their unique characteristics and behaviors. + en-US