knackforge
November 5, 2013
Drupal is known for being highly translatable. The localization team has done a fantastic job building out tools to make Drupal translatable and it's rare to find a contrib module that doesn't properly wrap its strings in the t() function or the lesser-known format_plural() function. While the Drupal community is doing fairly well on the PHP side, many people don't know there is a translation system for Drupal JavaScript as well through the use of Drupal.t() functions and Drupal.formatPlural() functions.
Drupal.t() function is the counterpart to the t() function in PHP. Generally, it is known to all Drupal developers that t() function is used for translating the strings to different languages. But many people don't know the purpose of Drupal.t() function which is used in a javascript file.
The other purpose of Drupal.t() is to replace the placeholders present in a string.
For example
var args = {};args['!url'] = 'https://example.com';args['%name'] = 'John Doe';var foo = Drupal.t('%name is the owner of !url', args);
var bar = Drupal.formatPlural(count, '@name has 1 site.', '@name has @count sites.', {'@name': John});
Just like how your fellow techies do.
We'd love to talk about how we can work together
Take control of your AWS cloud costs that enables you to grow!