How to change the variant label to display sold out for out of stock products?

How to modify the variant label to show sold out when the product is not in stock?

If variants are sold out, they’ll have “{variant name} + (Sold out)” labels next to them in drop-down menus on product pages, similar to the image below: