CMS Development

Amit_95
Participant | Platinum Partner
Participant | Platinum Partner

Pulling data from HubDB based on language selected

I have a `products` table with multiple prices since these products are available in several countries.

 

Based on this, if a user decides to change the language of the site they're on, I want to show them that countries price. But unsure on how this can be achieved?

 

This is how I'm displaying prices currently:

 

{% set query = hubdb_table_rows([table_id], "&product_id="~module.link_product) %}
        
      {% for row in query %}

        {% set product_price_global = row["price_global"] %}
        {% set product_price_france = row["price_france"] %}

        <a href="#">{{ product_price_global }}</a>

    {% endfor %}

As you can see, I only have the global price displayed. However, if a user chooses to change language to French, I want to display the France prices.

 

How can this be achieved? The only way I can think of is to check if a cookie exists i.e. "if a cookie with the value `fr` exists, show this price", but I can't see a way on how you can check cookies then perform statements around them in HubL.

 

 

0 Upvotes
2 Replies 2
nhinzmann
Member | Elite Partner
Member | Elite Partner

Pulling data from HubDB based on language selected

Hi, @Amit_95

 

The solution depends on how you have your multilingual content set up. Is it using Hubspot's language selector module? If so, you could utilize Hubspot's Format Currency filter within conditionals.

 

{% set query = hubdb_table_rows([table_id], "&product_id="~module.link_product) %}
        
      {% for row in query %}

          {% set product_price_global = row["price_global"] %}
          {% if content.language.languageTag == "fr" %}
              {{ product_price_global|format_currency("fr-FR") }}
          {% elif content.language.languageTag == "es" %}
{{ product_price_global|format_currency("es-ES") }}
{% else %}
{{ product_price_global|format_currency("en-US") }}
{% endif %}

<a href="#">{{ product_price_global }}</a>
{% endfor %}


 

If you're translating the content using something else like Google Translate, you'll probably have to use some Javascript to detect which language the page is translated to and then set up your conditionals - or give it a shot using your cookie idea. 

 

If nothing above works, can you provide a little more info on exactly how you're currently determining which language to display the content into, etc? I can further assist from there 🙂

0 Upvotes
jennysowyrda
Community Manager
Community Manager

Pulling data from HubDB based on language selected

Hi @Amit_95,

 

Are you still experiencing this issue? 

If so, can you provide additional information and links to your pages so we can see what you are working on? 

 

The more screenshots, details and information you can provide, the better the Community can assist!

 

Thank you,

Jenny

0 Upvotes