Creating link tags with hreflang attributes in CraftCMS

I want to preface this with the following; I think CraftCMS is a poor CMS. I dislike many things that it does and cannot recommend it as a professional CMS. Having said, that, I am working with it a lot these days at work and recently had to add link tags with hreflang attributes to the head. For some reason the CMS does not do this for you. SproutSEO does not do this either.

What this Twig snippet is doing is iterating over all of the defined site locales, looks up the current entries locale information to get the current entries specific locale slug. We grab the SiteURL parameter defined in the general config file and render the url with the locale specific entry slug and site url. And since this particular site wants to make en-us the default, we check for that and render accordingly if the locale matches. If there is no entry, we just take the request path and locale specific site url to render the url.

General.php config example:

It really bugs me that there isn’t a Twig variable or method in Craft CMS to do this for me.