2424import json
2525from hashlib import sha256
2626from http import HTTPStatus
27- from typing import Any , Dict , List , Optional , Tuple , Union
27+ from typing import Any , Dict , List , Optional , Tuple , Type , Union
2828
2929import gramps
3030import jsonschema
4040 Citation ,
4141 Event ,
4242 Family ,
43+ GrampsType ,
4344 Media ,
4445 Note ,
4546 Person ,
@@ -819,6 +820,14 @@ def validate_object_dict(obj_dict: Dict[str, Any]) -> bool:
819820 return True
820821
821822
823+ def xml_to_locale (gramps_type_name : str , string : str ) -> str :
824+ """Translate and XML string type name to a localized type name."""
825+ gramps_type = getattr (gramps .gen .lib , gramps_type_name )
826+ typ = gramps_type ()
827+ typ .set_from_xml_str (string )
828+ return str (typ )
829+
830+
822831def fix_object_dict (object_dict : Dict , class_name : Optional [str ] = None ):
823832 """Restore a Gramps object in simplified representation to its full form.
824833
@@ -839,19 +848,31 @@ def fix_object_dict(object_dict: Dict, class_name: Optional[str] = None):
839848 ):
840849 if isinstance (v , str ):
841850 if class_name == "Family" :
842- d_out [k ] = {"_class" : f"{ class_name } RelType" , "string" : _ (v )}
851+ d_out [k ] = {
852+ "_class" : f"{ class_name } RelType" ,
853+ "string" : xml_to_locale (f"{ class_name } RelType" , v ),
854+ }
843855 else :
844- d_out [k ] = {"_class" : f"{ class_name } Type" , "string" : _ (v )}
856+ d_out [k ] = {
857+ "_class" : f"{ class_name } Type" ,
858+ "string" : xml_to_locale (f"{ class_name } Type" , v ),
859+ }
845860 else :
846861 d_out [k ] = v
847862 elif k == "role" :
848863 if isinstance (v , str ):
849- d_out [k ] = {"_class" : "EventRoleType" , "string" : _ (v )}
864+ d_out [k ] = {
865+ "_class" : "EventRoleType" ,
866+ "string" : xml_to_locale ("EventRoleType" , v ),
867+ }
850868 else :
851869 d_out [k ] = v
852870 elif k == "origintype" :
853871 if isinstance (v , str ):
854- d_out [k ] = {"_class" : "NameOriginType" , "string" : _ (v )}
872+ d_out [k ] = {
873+ "_class" : "NameOriginType" ,
874+ "string" : xml_to_locale ("NameOriginType" , v ),
875+ }
855876 else :
856877 d_out [k ] = v
857878 elif k in ["rect" , "mother_handle" , "father_handle" , "famc" ] and not v :
0 commit comments