Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Gábor Hojtsy on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
7.10
Issue links:
Description:
This was unfortunately not done in time for the release of Drupal 7.0, so while you can use string context values in t() to designate a specific meaning of a string, this was not possible in JavaScript. Drupal 7 versions > 7.9 and Drupal 8 solves this problem.
PHP in Drupal 7 and 8:
$short_may = t('May');
$long_may = t('May', array(), array('context' => 'Long month name'));
JavaScript in Drupal 7 versions < 7.10:
shortMay = Drupal.t('May');
longMay = .... not possible in JS ....
JavaScript in Drupal 7 versions > 7.9 and Drupal 8:
shortMay = Drupal.t('May');
longMay = Drupal.t('May', {}, {context: "Long month name"});