Translate string in javascript There is a string which gets displayed in the mobile menu.

var arrowimages = {
down: 'downarrowclass',
right: 'rightarrowclass'
}, $mainNav = $('#navigation'), $mainList  = $mainNav.find('ul').eq(0), optionsList = '&lt;option value="" selected&gt;Navigate...&lt;/option&gt;', $submenu = $mainList.find("ul").parent();


I want to make this string translatable using t() function. So edited the JS file like this:

var arrowimages = {
down: 'downarrowclass',
right: 'rightarrowclass'
}, $mainNav = $('#navigation'), $mainList  = $mainNav.find('ul').eq(0), optionsList = '&lt;option value="" selected&gt;'.t('Navigate...').'&lt;/option&gt;', $submenu = $mainList.find("ul").parent();


After that the string was available for translation but the menu option was missing from the mobile view. Is there any solution for this? Or am I doing any mistake?
t() is a PHP function. You are looking for Drupal.t() which is the equivalent function Drupal makes available for JavaScript.

These are some example of how Drupal.t() and Drupal.formatPlural() can be used in JavaScript.

var comments = Drupal.t('Comments');
var commentsOnType = Drupal.t('Comments to @type posts', {'@type': typeName});
var commentCount = Drupal.formatPlural(count, '1 comment', '@count comments');
var commentCountOnType = Drupal.formatPlural(count, '1 comment on @type posts', '@count comments on @type posts', {'@type': typeName});


Notice what reported in Translating strings in JavaScript:


For performance reasons, Drupal caches the JavaScript files it has parsed. So, when you add or change strings in a JavaScript file, you have to clear the cache to have Drupal pick up the new strings and make them available for translation.
Automatic extraction does not work for packed JavaScript files. For this reason, module authors should only include unpacked versions of their JavaScript files. Drupal's JavaScript aggregator will create a packed version from these files anyway.


Just replace t() with Drupal.t(), and you are done.

var arrowimages = {
down: 'downarrowclass',
right: 'rightarrowclass'
};
var $mainNav = $('#navigation');
var $mainList = $mainNav.find('ul').eq(0);
var  optionsList = '&lt;option value="" selected&gt;'+ Drupal.t('Navigate...') + '&lt;/option&gt;',
  $submenu = $mainList.find("ul").parent();


Your code also contains a syntax error: . is not the string concatenation operator, in JavaScript; JavaScript uses +, for that purpose.