diff --git a/includes/locale.inc b/includes/locale.inc
index 971431933cbc987562593eab8538d8098b195546..726ade3cf858397e5336e973d7fa90041377db65 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -506,10 +506,40 @@ function _locale_parse_js_file($filepath) {
 
   // Match all calls to Drupal.t() in an array.
   // Note: \s also matches newlines with the 's' modifier.
-  preg_match_all('~[^\w]Drupal\s*\.\s*t\s*\(\s*(' . LOCALE_JS_STRING . ')\s*[,\)]~s', $file, $t_matches);
+  preg_match_all('~
+    [^\w]Drupal\s*\.\s*t\s*                       # match "Drupal.t" with whitespace
+    \(\s*                                         # match "(" argument list start
+    (' . LOCALE_JS_STRING . ')\s*                 # capture string argument
+    [,\)]                                         # match ")" or "," to finish
+    ~sx', $file, $t_matches);
 
   // Match all Drupal.formatPlural() calls in another array.
-  preg_match_all('~[^\w]Drupal\s*\.\s*formatPlural\s*\(\s*.+?\s*,\s*(' . LOCALE_JS_STRING . ')\s*,\s*((?:(?:\'(?:\\\\\'|[^\'])*@count(?:\\\\\'|[^\'])*\'|"(?:\\\\"|[^"])*@count(?:\\\\"|[^"])*")(?:\s*\+\s*)?)+)\s*[,\)]~s', $file, $plural_matches);
+  preg_match_all('~
+    [^\w]Drupal\s*\.\s*formatPlural\s*  # match "Drupal.formatPlural" with whitespace
+    \(                                  # match "(" argument list start
+    \s*.+?\s*,\s*                       # match count argument
+    (' . LOCALE_JS_STRING . ')\s*,\s*   # match singular string argument
+    (                             # capture plural string argument
+      (?:                         # non-capturing group to repeat string pieces
+        (?:
+          \'                      # match start of single-quoted string
+          (?:\\\\\'|[^\'])*       # match any character except unescaped single-quote
+          @count                  # match "@count"
+          (?:\\\\\'|[^\'])*       # match any character except unescaped single-quote
+          \'                      # match end of single-quoted string
+          |
+          "                       # match start of double-quoted string
+          (?:\\\\"|[^"])*         # match any character except unescaped double-quote
+          @count                  # match "@count"
+          (?:\\\\"|[^"])*         # match any character except unescaped double-quote
+          "                       # match end of double-quoted string
+        )
+        (?:\s*\+\s*)?             # match "+" with possible whitespace, for str concat
+      )+                          # match multiple because we supports concatenating strs
+    )\s*                          # end capturing of plural string argument
+    [,\)]
+    ~sx', $file, $plural_matches);
+
 
   // Loop through all matches and process them.
   $all_matches = array_merge($plural_matches[1], $t_matches[1]);
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index 854bd246ebfc7243a2d3d33649362ad6a5a03382..30ed39811148ddfa6cd79f406662ba4ef5eacae5 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -176,6 +176,73 @@ class LocaleConfigurationTest extends DrupalWebTestCase {
 
 }
 
+/**
+ * Functional tests for JavaScript parsing for translatable strings.
+ */
+class LocaleJavascriptTranslationTest extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Javascript translation',
+      'description' => 'Tests parsing js files for translatable strings',
+      'group' => 'Locale',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('locale', 'locale_test');
+  }
+
+  function testFileParsing() {
+
+    $filename = drupal_get_path('module', 'locale_test') . '/locale_test.js';
+
+    // Parse the file to look for source strings.
+    _locale_parse_js_file($filename);
+
+    // Get all of the source strings that were found.
+    $source_strings = db_select('locales_source', 's')
+      ->fields('s', array('source', 'lid'))
+      ->condition('s.location', $filename)
+      ->execute()
+      ->fetchAllKeyed();
+
+    // List of all strings that should be in the file.
+    $test_strings = array(
+      "Standard Call t",
+      "Whitespace Call t",
+
+      "Single Quote t",
+      "Single Quote \\'Escaped\\' t",
+      "Single Quote Concat strings t",
+
+      "Double Quote t",
+      "Double Quote \\\"Escaped\\\" t",
+      "Double Quote Concat strings t",
+
+      "Standard Call plural",
+      "Standard Call @count plural",
+      "Whitespace Call plural",
+      "Whitespace Call @count plural",
+
+      "Single Quote plural",
+      "Single Quote @count plural",
+      "Single Quote \\'Escaped\\' plural",
+      "Single Quote \\'Escaped\\' @count plural",
+
+      "Double Quote plural",
+      "Double Quote @count plural",
+      "Double Quote \\\"Escaped\\\" plural",
+      "Double Quote \\\"Escaped\\\" @count plural",
+    );
+
+    // Assert that all strings were found properly.
+    foreach ($test_strings as $str) {
+      $this->assertTrue(isset($source_strings[$str]), t("Found source string: %source", array('%source' => $str)));
+    }
+
+    $this->assertEqual(count($source_strings), count($test_strings), t("Found correct number of source strings."));
+  }
+}
 /**
  * Functional test for string translation and validation.
  */