According to Matthew’s Gospel, Joseph learned that Mary was pregnant while she “was promised in marriage to Joseph ” but before they were united.
حسبما يروي انجيل متى ،‏ علِم يوسف ان مريم خطيبته حامل قبل ان يجتمعا .‏