def count_entities(entities, project=None, locale=None):
    """Count the number of entities (i.e. source strings) with the given project and/or locale."""
    count = 0
    for ent in entities:
        if (project is None or project == ent["project"]) and (
            locale is None or locale == ent["locale"]
        ):
            count += ent["count"]
    return count