Is there a way to get the URL of the localised version of a product variant? I have a website that uses Craft Commerce and I'm trying to add a language menu that points to the localised version of each product variant as follows:

  {% set variantID = craft.request.getParam('variant') %}
  {% set locales = craft.i18n.getSiteLocales() %}

  {% for locale in locales %}
     {% set localisedEntryUrl = craft.commerce.variants.id(variantID).locale(locale.id).first().url() %}
     {{ localisedEntryUrl }}
  {% endfor %}


The problem is that the code above always produces the variant url for one language. eg.

/en/shop/ornaments/melisa?variant=9356
/en/shop/ornaments/melisa?variant=9356
/en/shop/ornaments/melisa?variant=9356


whereas I would expect something like:

/en/shop/ornaments/melisa?variant=9356
/de/shop/ornaments/melisa?variant=9356
/es/shop/ornaments/melisa?variant=9356


What am I doing wrong?
Try using this code:

{% set variantID = craft.request.getParam('variant') %}
{% set locales = craft.i18n.getSiteLocaleIds() %}

{% for locale in locales %}
    {% if variantID is defined %}
        {% set localisedEntryUrl = craft.commerce.variants.id(variantID).locale(locale).first %}
        {% if localeEntry.locale == locale %}
            {{ localisedEntryUrl.getUrl() }}
        {% endif %}
    {% endif %}
{% endfor %}