Tesseract used to have that same bug. To fix it, I now poll /api/v3/federated_instances
at startup and save those to a lookup variable. Before localizing a community, user, post, or comment link, it checks to see if the domain is to a known federated instance by looking for it in the list of federated instances.
There may be other ways to solve that problem, but that was what I went with. Bonus is it doesn't require any extra network calls beyond the one to fetch the list of federated instances at startup.