Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
How to access a translation in Javascript of the Shopware 6 store front?

How can a translations snipped (created like here: https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-translations) be accessed in Javascript code of the frontend?

What first comes to my mind is to print the translated string into some kind of hidden tag / data attribute within the twig file and then read it from the JavaScript code.

But is there a suggested way to do this?

EDIT: I am looking for examples on how the Shopware 6 core developers do this, to find a best-practice and not invent something own.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you need it once a page, you can add it into data-attribute within plugin-related element. Other way, especually recommended when you need it multiple time on an page to save content:

I personally like set these texts in a variable for the window. Just where other window-variable are set and request them within the plugin.

{% block base_script_router %}
{{ parent() }}
<script>
    window.contactTexts = {
        product: '{{ 'anySnippet'|trans|e('js') }}',
        basket: '{{ 'anySnippet'|trans|e('js') }}',
        order: '{{ 'anySnippet'|trans|e('js') }}',
        inkl: '{{ 'anySnippet'|trans|e('js') }}'
    };
</script>
{% endblock %}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!