Beispiel #1
0
            $files = _potx_explore_dir('', '*', POTX_API_CURRENT, TRUE);
            break;
    }
}
// Fall back to --auto, if --files are not specified
if (empty($files)) {
    $files = _potx_explore_dir('', '*', POTX_API_CURRENT, TRUE);
}
foreach ($files as $file) {
    potx_status('status', "Processing {$file}...\n");
    _potx_process_file($file);
}
_potx_build_files(POTX_STRING_RUNTIME, $build_mode);
_potx_build_files(POTX_STRING_INSTALLER, POTX_BUILD_SINGLE, 'installer');
_potx_write_files();
potx_status('status', "\nDone.\n");
return;
// These are never executed, you can run potx-cli.php on itself to test it
// -----------------------------------------------------------------------------
$a = t("Double quoted test string");
$b = t("Test string with %variable", array('%variable' => t('variable replacement')));
$c = t('Single qouted test string');
$d = t("Special\ncharacters");
$e = t('Special\\ncharacters');
$f = t("Embedded {$variable}");
$g = t('Embedded $variable');
$h = t("more \$special characters");
$i = t('even more \\$special characters');
$j = t("Mixed 'quote' \"marks\"");
$k = t('Mixed "quote" \'marks\'');
$l = t('Some repeating text');
Beispiel #2
0
/**
 * Parse a JavaScript file for translatables. Only from Drupal 6.
 *
 * Extracts strings wrapped in Drupal.t() and Drupal.formatPlural()
 * calls and inserts them into potx storage.
 *
 * Regex code lifted from _locale_parse_js_file().
 */
function _potx_parse_js_file($code, $file, $save_callback)
{
    $js_string_regex = '(?:(?:\'(?:\\\\\'|[^\'])*\'|"(?:\\\\"|[^"])*")(?:\\s*\\+\\s*)?)+';
    // 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*(' . $js_string_regex . ')\\s*[,\\)]~s', $code, $t_matches, PREG_SET_ORDER);
    if (isset($t_matches) && count($t_matches)) {
        foreach ($t_matches as $match) {
            // Remove match from code to help us identify faulty Drupal.t() calls.
            $code = str_replace($match[0], '', $code);
            // @todo: figure out how to parse out context, once Drupal supports it.
            $save_callback(_potx_parse_js_string($match[1]), POTX_CONTEXT_NONE, $file, 0);
        }
    }
    // Match all Drupal.formatPlural() calls in another array.
    preg_match_all('~[^\\w]Drupal\\s*\\.\\s*formatPlural\\s*\\(\\s*.+?\\s*,\\s*(' . $js_string_regex . ')\\s*,\\s*((?:(?:\'(?:\\\\\'|[^\'])*@count(?:\\\\\'|[^\'])*\'|"(?:\\\\"|[^"])*@count(?:\\\\"|[^"])*")(?:\\s*\\+\\s*)?)+)\\s*[,\\)]~s', $code, $plural_matches, PREG_SET_ORDER);
    if (isset($plural_matches) && count($plural_matches)) {
        foreach ($plural_matches as $index => $match) {
            // Remove match from code to help us identify faulty
            // Drupal.formatPlural() calls later.
            $code = str_replace($match[0], '', $code);
            // @todo: figure out how to parse out context, once Drupal supports it.
            $save_callback(_potx_parse_js_string($match[1]) . "" . _potx_parse_js_string($match[2]), POTX_CONTEXT_NONE, $file, 0);
        }
    }
    // Any remaining Drupal.t() or Drupal.formatPlural() calls are evil. This
    // regex is not terribly accurate (ie. code wrapped inside will confuse
    // the match), but we only need some unique part to identify the faulty calls.
    preg_match_all('~[^\\w]Drupal\\s*\\.\\s*(t|formatPlural)\\s*\\([^)]+\\)~s', $code, $faulty_matches, PREG_SET_ORDER);
    if (isset($faulty_matches) && count($faulty_matches)) {
        foreach ($faulty_matches as $index => $match) {
            $message = $match[1] == 't' ? t('Drupal.t() calls should have a single literal string as their first parameter.') : t('The singular and plural string parameters on Drupal.formatPlural() calls should be literal strings, plural containing a @count placeholder.');
            potx_status('error', $message, $file, NULL, $match[0], 'http://drupal.org/node/323109');
        }
    }
}
/**
 * Output a marker error with an extract of where the error was found.
 *
 * @param $file
 *   Name of file
 * @param $line
 *   Line number of error
 * @param $marker
 *   Function name with which the error was identified
 * @param $ti
 *   Index on the token array
 * @param $error
 *   Helpful error message for users.
 * @param $docs_url
 *   Documentation reference.
 */
function _potx_marker_error($file, $line, $marker, $ti, $error, $docs_url = NULL)
{
    global $_potx_tokens;
    $tokens = '';
    $ti += 2;
    $tc = count($_potx_tokens);
    $par = 1;
    while ($tc - $ti > 0 && $par) {
        if (is_array($_potx_tokens[$ti])) {
            $tokens .= $_potx_tokens[$ti][1];
        } else {
            $tokens .= $_potx_tokens[$ti];
            if ($_potx_tokens[$ti] == "(") {
                $par++;
            } else {
                if ($_potx_tokens[$ti] == ")") {
                    $par--;
                }
            }
        }
        $ti++;
    }
    potx_status('error', $error, $file, $line, $marker . '(' . $tokens, $docs_url);
}