Next to strings themselves I'd also like their placeholders to be extracted. My particular use case: prevent placeholders from being marked as incorrect English by Text Review during a Coder review or by the future l10n_server text review Gábor and I talked about. Text Review needs to know about those placeholders in order to ignore them.

Backport to Drupal 6 would be greatly appreciated, although I understand if it's not an option.

Comments

Gábor Hojtsy’s picture

Status: Active » Postponed (maintainer needs more info)

What would be the output of this? I understand you'd like to have a mode which outputs strings without placeholders, right? How could this be input for coder review?

Xano’s picture

Coder doesn't do anything with this. Coder Text Review (a submodule of Text Review–note the capitals, it's a bit tricky.) however provides a Coder review method, similar to the coding standards review method. It uses potx to extract the UI strings from the code files that are to be reviewed during a particular Coder review and reviews them using Text Review. If potx would not only extract strings, but placeholders as well, Coder Text Review could remove those from the strings before passing the strings on to the Text Review review methods.

I do *not* need potx to remove placeholders from extracted strings, as that would corrupt the string. I need the original string *and* the placeholders, so Text Review knows the original positions of all characters in the strings.

Gábor Hojtsy’s picture

This is still unclear to me. Would you please document the data format you need?

Xano’s picture

The second parameter for t() is a keyed array. I need those keys together with the string they belong to (the first parameter).

hron84’s picture

So you need something like the following (it is for one string)?


function potx_extract_placeholders($string) {
   preg_match_all('/[@%!]([a-z][a-z0-9_]+[a-z0-9])/', $string, $found);
   if(isset($found) && is_array($found[1]) && count($found[1])) {
     return array('message' => $string, 'placeholders' => $found[1]);
   }
}