t() function - get specific language
You can choose the target language, see more information in the API. 

In code it would look like this.

$variables['string_in_spanish'] = t(
  'Hello World',
  [], // (The args in the string)
  ['langcode' =&gt; 'es'] //  The options
);


note that when using the t() function, the source language has to be English.