Fix finding __() and _n() i18n function calls
This commit is contained in:
@@ -23,6 +23,7 @@ module.exports = function (grunt) {
|
|||||||
cwd: '.', // base path where to look for translatable strings
|
cwd: '.', // base path where to look for translatable strings
|
||||||
domainPath: 'lang', // where to save the .pot
|
domainPath: 'lang', // where to save the .pot
|
||||||
exclude: [
|
exclude: [
|
||||||
|
'\.mp_svn/.*',
|
||||||
'assets/.*',
|
'assets/.*',
|
||||||
'lang/.*',
|
'lang/.*',
|
||||||
'node_modules/.*',
|
'node_modules/.*',
|
||||||
|
47
tasks/makepot/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/extract.php
generated
vendored
47
tasks/makepot/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/extract.php
generated
vendored
@@ -257,30 +257,41 @@ class StringExtractor {
|
|||||||
$current_argument = null;
|
$current_argument = null;
|
||||||
}
|
}
|
||||||
} elseif(in_array($extension, array('html', 'hbs'))) {
|
} 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++) {
|
$function_patterns = array(
|
||||||
// get match offset (position where the match was found)
|
'/(__)\(([\'"].+?[\'"])\)/',
|
||||||
$offset = array_pop($matches[0][$i]);
|
'/(_n)\(([\'"].+?[\'"],\s*[\'"].+?[\'"],\s*.+?)\)/'
|
||||||
// fetches all the text before the match
|
);
|
||||||
list($before) = str_split($code, $offset);
|
|
||||||
// calculate line number
|
$matches = array();
|
||||||
$line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1;
|
|
||||||
|
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)(?<!\\\\)(\"|')(?:[^\\\\]|\\\\.)*?\\1|[^,\\s]+/";
|
$arguments_pattern = "/(?s)(?<!\\\\)(\"|')(?:[^\\\\]|\\\\.)*?\\1|[^,\\s]+/";
|
||||||
preg_match_all($arguments_pattern, $matches[2][$i][0], $arguments_matches);
|
preg_match_all($arguments_pattern, $match['arguments'], $arguments_matches);
|
||||||
|
|
||||||
//echo var_dump($arguments_matches[0]);
|
$arguments = array();
|
||||||
$arguments = array();
|
foreach($arguments_matches[0] as $argument) {
|
||||||
foreach($arguments_matches[0] as $arg) {
|
$arguments[] = trim($argument, "'\"");
|
||||||
$arguments[] = trim($arg, "'\"");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$call = array(
|
$call = array(
|
||||||
'name' => $matches[1][$i][0],
|
'name' => $match['name'],
|
||||||
'args' => $arguments,
|
'args' => $arguments,
|
||||||
'line' => $line_number
|
'line' => $line_number
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user