When the time was near for Mary to give birth
This could mean ‘When it was near the end of Mary’s pregnancy.’
the Roman officials
Rome had conquered and ruled over Israel at this time.
to count all the people
The Romans probably counted the people so they could tax them.