Substitutes substrings with different strings. Similar to doing multiple replacements while making sure that none of the replacements overlap.

This function is valid in v2.24.0 to v2.24.2. This function has been downloaded 2 times.


{string} string
The string with substrings that may be translated to new substrings. If null or undefined the value returned from translate() will be a partial function which will only accept the string to be translated.
{Array|Object} translations
If this is an array then it must be an array of arrays where the first item in each sub-array is either a regular expression or a string indicating the substring to be found and the second item must specify the replacement. If this is an object then each key indicates the substring to be found and the value specifies the replacement. If the replacement is ever a function then it will be called with the first argument being the substring found and any subsequent arguments only be passed if there were any capture groups specified.
{boolean=} opt_replaceShortest Optional, Default:false
If true then the shortest translation targets will be preferred over the longer ones. Otherwise the longest translation targets will be preferred over the shorter ones.


A new version of string with all of the translations carried out as defined.

Required Functions

This function directly requires the following functions which are included automatically:

  • execAll()
    Gets all of the matches found when matching a regular expression against a string.
  • nativeType()
    Gets the native type name of a primitive or an object. Unlike YourJS.typeOf(), the types are solely determined by the system.