Multi-Language. TWIG in JS

I use Grav and Gantry Helium.

I have a function

// Handle a click on the hint button
hintButton.addEventListener(‘click’, function () {
if (score >= 3) {
score -= 3;
scoreElement.textContent = score;
hintImage.style.display = ‘block’;
setTimeout(() => {
hintImage.style.display = ‘none’;
}, 12000);
} else {
showNotification(‘Text Text Text Text’, ‘error’);
}
});

How to showNotification ‘Text Text Text Text’ in different languages?

In user/languages/ I have de.yaml en.yaml.

Me and claude.ai haven’t found a solution yet(.

I think you’re trying to solve it the other way around. Try JS in Twig. Set JS variables for your strings in twig and then use them in JS. At least that’s how I’d do

Hi, you can add translations to languages.yaml file in your theme folder

example:

en:
  THEME_NAME:
    TEXT: 'Text EN!’

de:
  THEME_NAME:
    TEXT: 'Text DE!’

then use it in your templates .html.twig

{{ 'THEME_NAME.TEXT’ | t }}

live example - press copy/kopiuj button en/pl:

This doesn’t answer the question. You can’t use twig in JS

thats why I propose possible solution and use translations in .html.twig