package localization // EntityDescriptor describes an entity type and its handler // Uses type erasure to store handlers of different concrete types type EntityDescriptor struct { Type string Fields []string Handler any // Type-erased handler - will be cast to specific type when used TableName string IDField string } // EntityRegistry holds all registered entity descriptors var EntityRegistry = make(map[string]*EntityDescriptor) // RegisterEntity registers a new entity type with its handler func RegisterEntity(descriptor *EntityDescriptor) { EntityRegistry[descriptor.Type] = descriptor } // GetEntityDescriptor returns the descriptor for a given entity type func GetEntityDescriptor(entityType string) (*EntityDescriptor, bool) { desc, exists := EntityRegistry[entityType] return desc, exists } // GetAllEntityTypes returns all registered entity types func GetAllEntityTypes() []string { types := make([]string, 0, len(EntityRegistry)) for entityType := range EntityRegistry { types = append(types, entityType) } return types } // GetEntityTypesForFilter filters entity types based on the filter string func GetEntityTypesForFilter(entityTypeFilter string) []string { switch entityTypeFilter { case "all": return GetAllEntityTypes() case "site", "sites", "building", "buildings": return []string{"site"} case "heritage_title", "title", "titles": return []string{"heritage_title"} case "heritage_timeline_item", "timeline", "timeline_item", "item": return []string{"heritage_timeline_item"} case "heritage_source", "source", "sources": return []string{"heritage_source"} case "organization", "organizations", "org", "orgs": return []string{"organization"} case "geographical_feature", "geographical_features", "geo", "geofeature": return []string{"geographical_feature"} case "product", "products": return []string{"product"} default: return []string{entityTypeFilter} } } // GetFieldsForEntityType returns the localizable fields for an entity type func GetFieldsForEntityType(entityType string) []string { if desc, exists := GetEntityDescriptor(entityType); exists { return desc.Fields } return []string{} }