I'm updating the spanish translation of biblio module from 1.9 to 1.10
The steps I did was:
1.- Install drupal + biblio 1.10 + potx
2.- Import de 1.9 biblio translation
3.- Go to http://localhost/drupal/?q=admin/settings/locale/string/search and search the "Non translated Strings"
4.- Edit the strings.
5.- Go to http://localhost/drupal/?q=admin/settings/locale/potx and extract the spanish template for Biblio

Some strings was missed. In my drupal local server are translated, but not in the .po file. I don't know if is relevant, but all the missing strings I revised (not all yet) have an spanish "special" character (ñ, é, í, etc...). Some other strings with this characters are extracted ok.

Screenshot and .po file attached

CommentFileSizeAuthor
#7 potx.inc_.zip11.09 KBGocho
bug_example.png255.36 KBGocho
biblio.es-buggy.po_.zip8.44 KBGocho
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gocho’s picture

A second revision shows me why the strings was not extracted. All the missing strings have the " character in it.
It's seems as potx doesn't converts the " character to \" when extracts the strings.

Gábor Hojtsy’s picture

Hm? The attached shot shows the "By default..." string on the interface and extracted as well. Now what is missing? It would be better to know more about what was missing. Also, did potx provide an error message about those? (After you reload the export page).

Gocho’s picture

The problem is that potx doesn't extract the translated strings when they have any " character.

As you can see, the "By default..." was extracted, but the translated one doesn't.
For the original string potx extract it ok and converts the " characters to \" but doesn't for the translated.

Gábor Hojtsy’s picture

Ah, i see. The problem is that when _potx_translation_export() gets called, it gets called with the escaped source string, so it will not find the translation in the database. The reverse of _potx_format_quoted_string() should be applied when calling _potx_translation_export(). From the looks of how _locale_import_parse_quoted() does it, we might be enough with calling stripcslashes($string) on the value passed to _potx_translation_export(), whenever it is called. Can you test this?

Gocho’s picture

No luck :(

I edit the potx.inc callin stripcslashes() before _potx_translation_export() and the bug is still here.
The only place where I edit in the potx.inc file is the _potx_build_files function:

function _potx_build_files($string_mode = POTX_STRING_RUNTIME, $build_mode = POTX_BUILD_SINGLE, $force_name = 'general',  $save_callback = '_potx_save_string', $version_callback = '_potx_save_version', $header_callback = '_potx_get_header', $template_export_langcode = NULL, $translation_export_langcode = NULL, $api_version = POTX_API_6) {
  global $_potx_store;

  // Get strings and versions by reference.
  $strings  = $save_callback(NULL, NULL, 0, $string_mode);
  $versions = $version_callback();

  // We might not have any string recorded in this string mode.
  if (!is_array($strings)) {
    return;
  }

  foreach ($strings as $string => $file_info) {
    // Build a compact list of files this string occured in.
    $occured = $file_list = array();
    foreach ($file_info as $file => $lines) {
      $occured[] = "$file:". join(';', $lines);
      if (isset($versions[$file])) {
        $file_list[] = $versions[$file];
      }
    }

    // Mark duplicate strings (both translated in the app and in the installer).
    $comment = join(" ", $occured);
    if (strpos($comment, '(dup)') !== FALSE) {
      $comment = '(duplicate) '. str_replace('(dup)', '', $comment);
    }
    $output = "#: $comment\n";

    // File name forcing in single mode.
    if ($build_mode == POTX_BUILD_SINGLE) {
      $file_name = $force_name;
    }
    // Store .info file strings either in general.pot or the module pot file,
    // depending on the mode used.
    elseif (strpos($comment, '.info')) {
      $file_name = ($build_mode == POTX_BUILD_CORE ? 'general' : str_replace('.info', '.module', $file_name));
    }
    // Else if occured more than once, store in general.pot.
    else {
      $file_name = (count($occured) > 1 ? 'general' : $file);
    }

    if (strpos($string, "\0") !== FALSE) {
      // Plural strings have a null byte delimited format.
      list($singular, $plural) = explode("\0", $string);
      $output .= "msgid \"$singular\"\n";
      $output .= "msgid_plural \"$plural\"\n";
      if (isset($translation_export_langcode)) {
        //Added for bug http://drupal.org/node/201253
        stripcslashes($singular);
        //End of add.
        $output .= _potx_translation_export($translation_export_langcode, $singular, $plural, $api_version);
      }
      else {
        $output .= "msgstr[0] \"\"\n";
        $output .= "msgstr[1] \"\"\n";
      }
    }
    else {
      // Simple strings.
      $output .= "msgid \"$string\"\n";
      if (isset($translation_export_langcode)) {
        //Added for bug http://drupal.org/node/201253
        stripcslashes($string);
        //End of add.
        $output .= _potx_translation_export($translation_export_langcode, $string, NULL, $api_version);
      }
      else {
        $output .= "msgstr \"\"\n";
      }
    }
    $output .= "\n";

    // Store the generated output in the given file storage.
    if (!isset($_potx_store[$file_name])) {
      $_potx_store[$file_name] = array(
        'header'  => $header_callback($file_name, $template_export_langcode, $translation_export_langcode, $api_version),
        'sources' => $file_list,
        'strings' => $output,
        'count'   => 1,
      );
    }
    else {
      // Maintain a list of unique file names.
      $_potx_store[$file_name]['sources']  = array_unique(array_merge($_potx_store[$file_name]['sources'], $file_list));
      $_potx_store[$file_name]['strings'] .= $output;
      $_potx_store[$file_name]['count']   += 1;
    }
  }
}

Gábor Hojtsy’s picture

The stripcslashes($singular); does not modify $singular, but $singular = stripcslashes($singular); does :) The same for $plural should be done there and the same for $string.

Gocho’s picture

Status: Active » Reviewed & tested by the community
FileSize
11.09 KB

:$

Great! Now works ok. Thanks :)
New version of potx.inc attached and ready to be comitted.

Farreres’s picture

When will this be committed? I think it is a rather important bugfix to generate a new official version.

Gábor Hojtsy’s picture

Fully agreed. I still need to work out how this will get into the four branches of potx: 5.x-1, 5.x-2, 6.x-1, 6.x-2

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Hm, finally found some time. Committed the fix to all four branches, and released the 5.x-1.1 and 6.x-1.1 versions. The 6.x-2 and 5.x-2 versions are still in development but their latest snapshots will have the fixes.

Note that I have finally implemented a different solution, as it can be seen in the diffs, I modified _potx_translation_export(). http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/potx/potx.i... I hope you find this working just as well, as it is just the same code moved to a little bit different place (maybe more logical, but I am not 100% sure). Thanks for testing!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.