Goal is something more spiritual and mental and in your sentence : "I set myself the goal of learning a foreign language" the word "goal" is preferred. You mostly see the word "Target" used in military areas. Like the following sentence: "The target of the launched missile, was a desert !"
I hope this will be helpful.
June 8, 2020
You can use either: unfortunately the Cambridge online dictionary is not very helpful to learners it only gives the military or aggressive definition.
But Merriam Webster gives two definitions one which includes this.
: something that you are trying to do or achieve
Some Brits won't like this but the Merriam Webster webster [American] dictionary is often more useful to even British people than our own OXFORD or CAMBRIDGE [British] dictionaries