@@ -35,11 +35,14 @@ class MetadataHandler(metaclass=ABCMeta):
3535 """
3636
3737 @abstractmethod
38- def update_schema (self , jsonschema : dict , context , lang = None ):
38+ def update_schema (self , jsonschema : dict , context : dict , lang = None ):
3939 """
4040 It is called by the MetadataManager when creating the JSON Schema
4141 It adds the subschema handled by the handler, and returns the
4242 augmented instance of the JSON Schema.
43+ Context is populated by the manager with some common info:
44+ - key "labels": contains the localized label loaded from the db as a dict, where key is the ThesaurusKeyword about
45+ and value is the localized ThesaurusKeywordLabel, or the AltLabel if the localized label does not exist.
4346 """
4447 pass
4548
@@ -58,7 +61,7 @@ def update_resource(
5861 self , resource : ResourceBase , field_name : str , json_instance : dict , context : dict , errors : dict , ** kwargs
5962 ):
6063 """
61- Called when persisting data, updates the field field_name of the resource
64+ Called when persisting data, updates the field ` field_name` of the resource
6265 with the content content, where json_instance is the full JSON Schema instance,
6366 in case the handler needs some cross related data contained in the resource.
6467 """
@@ -135,15 +138,22 @@ def _set_error(errors: dict, path: list, msg: str):
135138
136139 @staticmethod
137140 def _localize_label (context , lang : str , text : str ):
138- # Try localization via thesaurus:
139- label = context ["labels" ].get (text , None )
140- # fallback: gettext()
141- if not label :
142- label = _ (text )
141+ label = MetadataHandler ._get_tkl_labels (context , lang , text )
142+ return label if label else _ (text )
143143
144- return label
144+ @staticmethod
145+ def _get_tkl_labels (context , lang : str , text : str ):
146+ return context ["labels" ].get (text , None )
145147
146148 @staticmethod
147- def _localize_subschema_label (context , subschema : dict , lang : str , annotation_name : str ):
148- if annotation_name in subschema :
149- subschema [annotation_name ] = MetadataHandler ._localize_label (context , lang , subschema [annotation_name ])
149+ def _localize_subschema_labels (context , subschema : dict , lang : str , property_name : str = None ):
150+ for annotation_name , synt in (
151+ ("title" , "" ),
152+ ("description" , "__descr" ),
153+ ):
154+ if annotation_name in subschema :
155+ subschema [annotation_name ] = MetadataHandler ._localize_label (context , lang , subschema [annotation_name ])
156+ elif property_name : # arrays may not have a name
157+ label = MetadataHandler ._get_tkl_labels (context , lang , f"{ property_name } { synt } " )
158+ if label :
159+ subschema [annotation_name ] = label
0 commit comments