The title speaks for itself. Would this be the same as shorting a company that goes bankrupt? So you basically get to keep all your money?
It would depend on what 'nationalized' means - it could mean a lot of things.
It is hard to imagine that in the US, the government would 'nationalize' a company by declaring all shares in the market as void - sure, that would mean all share owners lose all their money, but that government would be in dire straits in the next election.
On the other hand, they could buy out all share owners, like a normal take-over, and then each share holder gets his value in cash, which most would find acceptable.
This would probably include forcing all short sales to close out the positions within some time limit.
Nationalization carries a broad range of meaning. In some cases a government might choose to nationalize a company or even an entire industry (Jose Lopez Portillo did this in Mexico in the 1980s when he nationalized the banks to seize the dollar accounts that Mexican citizens could keep in Mexican banks) and provide compensation in whole or part, or maybe nothing at all.
When Portillo acted to do this in Mexico with the banks,he didn't give the owners anything at the time, so essentially everyone who held a stake in those banks lost everything.
Nationalization is an extreme action and doesn't happen often, mainly because it rarely has the intended consequence the government hoped for and also because it serves to undermine confidence in that's industry's sector in particular and in the economy of the country as a whole.
I don't see any scenario (reasonable, anyway) under which the U.S. government would ever nationalize a company. The nearest examples to this might be AIG following the financial collapse in 2008 and the GM bankruptcy, but in both cases the companies went through the bankruptcy process with the government's backing and support and reemerged with the government as one of the largest shareholders. Eventually the government bled off its stake in those companies and, in both cases, actually managed to post a small profit on them.
What happens to your short position in a nationalization all depends on how it happens, to be honest. There's no blanket answer that anyone can give. The government may seize operational control of the company but still allow it to trade in the public markets or any other combination of possibilities - who knows?