Input placeholder depending on current language

I’m using a contact form and can’t find the right way to have a placeholder for input texts and textarea to depend on the current language. Can you help ?


Attributes are not supported by multilanguage feature, they are the same across all languages, and placehodler is an attribute.
We can create a plugin in future to cover this issues with placeholders, but for now, only way is if you can figure it out through JS.

One idea that comes to mind is to create attributes like:
placeholder-en: Your Message
placeholder-es: Tu mensaje

And then create javascript file that will be run on ‘onPageReady’, based on language to apply proper placeholder.

and inside you can write function:

let activeLang = $dh.language()?.active?.toLowerCase();

  let langPlaceholder = $(this).attr(`placeholder-${activeLang }`);
  if (  langPlaceholder  ) {
     $(this).attr("placeholder", langPlaceholder);

Keep in mind that I haven’t tested this, but it should be working.

1 Like

Thanks @Pakic , I’ll try that and let you know

@Pakic , thanks, using the code below, it works

let activeLang = $dh.language()?.active?.toLowerCase();

contact_name = document.getElementById("contact_nom")
contact_email = document.getElementById("contact_email")
contact_message = document.getElementById("contact_message")

contact_name.placeholder = contact_name.getAttribute(`placeholder-${activeLang }`);
contact_email.placeholder = contact_email.getAttribute(`placeholder-${activeLang }`);
contact_message.placeholder = contact_message.getAttribute(`placeholder-${activeLang }`);
1 Like