Spain has announced it will grant legal status to 500,000 undocumented migrants, in a move that goes against a trend of anti-immigration rhetoric and policies in the United States and much of Europe.