Invented by Oswald Jacoby, a response of 2♦ (2♥) over an opening 1NT shows at least five cards in hearts (spades). Opener then bids the suit that responder has shown. You can make the transfer bid either with a weak hand (planning to pass when opener completes the transfer) or with a variety of stronger hands.
With the first hand, you respond 2♦ and then pass 2♥.
On the second hand, you respond 2♥ and then rebid in no-trumps (2NT if 1NT was weak, 3NT if 1NT was strong).