Background of the issue:
I'm trying to get the URL to a term in a different language than the request language using the get_term_link() function. Even after changing the current language, the request language is used. The issue seems to be in the home_url_filter method, where the request language is used instead of the current language. Replacing $url_language = $this->get_request_language(); with $url_language = $this->sitepress->get_current_language(); seems to solve the issue when testing. I have tried both to set the current language with do_action('wpml_switch_language', $language_code); and $sitepress->switch_lang($language_code);. The result is the same.
Symptoms:
The get_term_link() function returns an invalid term URL prefixed with /pl/ (request language) resulting in a 404 error when visited, instead of a valid and correct URL prefixed with the current language (/no/) (or without the prefix when it's the the main language).
Questions:
Why does get_term_link() return a URL for the request language instead of the current language?
How can I ensure that get_term_link() returns a URL prefixed with the current language?