n How to translate a JS strings in Drupal 8 | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

we still have here the Drupal.t() and Drupal.formatPlural() functions to translate our interface text. To be able to use them you need to require the core/drupal library as a dependency in your library entry.


Drupal.t("My String");

Clear the Drupal Cache.

This string appear in /admin/config/regional/translate

if not then check your libraries.yml file
And add the corresponding dependencies THEME.libraries.yml:

  - core/jquery
  - core/drupal



Drupal.t('Something to translate');
Drupal.t('Comments to @type posts', {'@type': typeName});
Drupal.t('Something to translate', {}, {context: 'Javascript'});

var x = 'First text to translate';

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts


Page Facebook