Skip to content

Commit

Permalink
Put a message in the logs when we find a string that's not
Browse files Browse the repository at this point in the history
concatenated.  Concatenating them is not easy because the two strings
can have different quoting (single vs. double quotes) and may have to
be treated separately in the code.

Fixes ticket #1321
  • Loading branch information
bharat committed Aug 30, 2010
1 parent 2018831 commit 0879a26
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions modules/gallery/helpers/l10n_scanner.php
Expand Up @@ -74,10 +74,21 @@ static function scan_php_file($file, &$cache) {
unset($raw_tokens);

if (!empty($func_token_list["t"])) {
l10n_scanner::_parse_t_calls($tokens, $func_token_list["t"], $cache);
$errors = l10n_scanner::_parse_t_calls($tokens, $func_token_list["t"], $cache);
foreach ($errors as $line => $error) {
Kohana_Log::add(
"error", "Translation scanner error. " .
"file: " . substr($file, strlen(DOCROOT)) . ", line: $line, context: $error");
}
}

if (!empty($func_token_list["t2"])) {
l10n_scanner::_parse_plural_calls($tokens, $func_token_list["t2"], $cache);
$errors = l10n_scanner::_parse_plural_calls($tokens, $func_token_list["t2"], $cache);
foreach ($errors as $line => $error) {
Kohana_Log::add(
"error", "Translation scanner error. " .
"file: " . substr($file, strlen(DOCROOT)) . ", line: $line, context: $error");
}
}
}

Expand All @@ -91,6 +102,7 @@ static function scan_info_file($file, &$cache) {
}

private static function _parse_t_calls(&$tokens, &$call_list, &$cache) {
$errors = array();
foreach ($call_list as $index) {
$function_name = $tokens[$index++];
$parens = $tokens[$index++];
Expand All @@ -103,14 +115,21 @@ private static function _parse_t_calls(&$tokens, &$call_list, &$cache) {
$message = self::_escape_quoted_string($first_param[1]);
l10n_scanner::process_message($message, $cache);
} else {
// t() found, but inside is something which is not a string literal.
// @todo Call status callback with error filename/line.
if (is_array($first_param) && ($first_param[0] == T_CONSTANT_ENCAPSED_STRING)) {
// Malformed string literals; escalate this
$errors[$first_param[2]] =
var_export(array($function_name, $parens, $first_param, $next_token), 1);
} else {
// t() found, but inside is something which is not a string literal. That's fine.
}
}
}
}
return $errors;
}

private static function _parse_plural_calls(&$tokens, &$call_list, &$cache) {
$errors = array();
foreach ($call_list as $index) {
$function_name = $tokens[$index++];
$parens = $tokens[$index++];
Expand All @@ -127,11 +146,17 @@ private static function _parse_plural_calls(&$tokens, &$call_list, &$cache) {
$plural = self::_escape_quoted_string($second_param[1]);
l10n_scanner::process_message(array("one" => $singular, "other" => $plural), $cache);
} else {
// t2() found, but inside is something which is not a string literal.
// @todo Call status callback with error filename/line.
if (is_array($first_param) && $first_param[0] == T_CONSTANT_ENCAPSED_STRING) {
$errors[$first_param[2]] = var_export(
array($function_name, $parens, $first_param,
$first_separator, $second_param, $next_token), 1);
} else {
// t2() found, but inside is something which is not a string literal. That's fine.
}
}
}
}
return $errors;
}

/**
Expand Down

0 comments on commit 0879a26

Please sign in to comment.