You should use a flag when you're referring to a country or region, for example when you have an e-commerce website and are just distributing in certain areas. But languages do not have flags associated and then should not be used in language selectors.
Check that the example in the GH thread has Spanish as one of their choices and has the Spanish flag. Spanish is talked in a lot of countries including Spain, but also Spain has 4 different official languages in its own state territory. So, there exists es_ES, es_MX, es_PE but also es_ES and ca_ES. What flag should we paint in each case?
I've seen this mistake soo many times...