title: Translation string extraction
body: <p>We have a translation extraction tool that we've written, that extracts strings that we've marked for translation in TypeScript. The JavaScript tool reads our Typescript files and has a regex like:</p>
  
  <pre><code>fileContent.match(/this.\translate\((.*?));/);
  </code></pre>
  
  <p>(simplified for readability, this works fine)</p>
  
  <p>The translation method takes 3 parameters: 1. The string to be translated, 2. any variables that might be interpolated, 3. description. The last 2 are optional. 
  Examples of the implementation:</p>
  
  <pre><code>this.translate('text to translate');
  this.translate('long text' + 
                 'over multiple lines');
  this.translate(`text to translate with backticks for interpolation`);
  this.translate(`some test with a ${variable}`, [variable]);
  this.translate(`some test with a ${variable}`, [variable], 'Description');
  </code></pre>
  
  <p>We need to extract these 3 parameters from text in JavaScript and have issues parsing it. We are currently using a regex to check the first opening string character (<code>'</code> or "`") and trying to match a closing character, but that is hard to do. </p>
  
  <p>I'm currently trying to use <code>eval</code> (the script doesn't run in the browser, but CLI), like this:</p>
  
  <pre><code>function getParameters(text, variables, description){ 
      return {text: text, variables: variables, description: description}
  }
  toEval = string.replace('this.translate', 'getParameters');
  eval(toEval);
  </code></pre>
  
  <p>Which works perfect if there are no variables, but complains that <code>"variables" not defined</code>, when we pass in variables.</p>
  
  <p>Can anyone suggest a good/better way to deal with this text extraction?</p>