Skip to main content
Category:

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()

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:

dependencies:
  - core/jquery
  - core/drupal

 

Examples:

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';
Drupal.t(x);

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

Search

Page Facebook