diff --git a/tasks/makepot/makepot.js b/tasks/makepot/makepot.js index 32b13cb33a..67d1fbb237 100644 --- a/tasks/makepot/makepot.js +++ b/tasks/makepot/makepot.js @@ -23,6 +23,7 @@ module.exports = function (grunt) { cwd: '.', // base path where to look for translatable strings domainPath: 'lang', // where to save the .pot exclude: [ + '\.mp_svn/.*', 'assets/.*', 'lang/.*', 'node_modules/.*', diff --git a/tasks/makepot/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/extract.php b/tasks/makepot/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/extract.php index 189415adab..f952a508ae 100644 --- a/tasks/makepot/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/extract.php +++ b/tasks/makepot/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/extract.php @@ -257,30 +257,41 @@ class StringExtractor { $current_argument = null; } } elseif(in_array($extension, array('html', 'hbs'))) { - // get all translatable strings - $functions_pattern = '/('.join('|', $function_names).')\((.*)\)/Us'; - preg_match_all($functions_pattern, $code, $matches, PREG_OFFSET_CAPTURE); - for($i = 0, $count = count($matches[1]); $i < $count; $i++) { - // get match offset (position where the match was found) - $offset = array_pop($matches[0][$i]); - // fetches all the text before the match - list($before) = str_split($code, $offset); - // calculate line number - $line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1; + $function_patterns = array( + '/(__)\(([\'"].+?[\'"])\)/', + '/(_n)\(([\'"].+?[\'"],\s*[\'"].+?[\'"],\s*.+?)\)/' + ); + + $matches = array(); + + foreach($function_patterns as $pattern) { + preg_match_all($pattern, $code, $function_matches, PREG_OFFSET_CAPTURE); + for($i = 0; $i < count($function_matches[1]); $i += 1) { + $matches[] = array( + 'call' => $function_matches[0][$i][0], + 'call_offset' => $function_matches[0][$i][1], + 'name' => $function_matches[1][$i][0], + 'arguments' => $function_matches[2][$i][0] + ); + } + } + + foreach($matches as $match) { + list($text_before_match) = str_split($code, $match['call_offset']); + $number_of_newlines = strlen($text_before_match) - strlen(str_replace("\n", "", $text_before_match)); + $line_number = $number_of_newlines + 1; - // extract arguments (potentially multiple) $arguments_pattern = "/(?s)(? $matches[1][$i][0], + 'name' => $match['name'], 'args' => $arguments, 'line' => $line_number );