Search code examples
internationalizationprintftranslatepoedit

Position of words in sprintf strings for translation


In some languages, the words do not have the same position.

Here is an example:

sprintf( __( '%s left a %s on %s\'s %s.', 'o2' ), $commentAuthor, $commentLink, $postAuthor, $postLink );

This string returns for example:

John(1) left a comment(2) on Jane(3)'s post(4).

But in French, some words are not in the same position:

John(1) a laissé un commentaire(2) sur la publication(4) de Jane(3).

I translated the string in poedit:

%s a laissé un %s sur la %s de %s.

But the words are misplaced:

John(1) a laissé un commentaire(2) sur la Jane(3) de publication(4).

This is not a correct translation.

How to change the order with poedit or any other translation editor?


Solution

  • Well, I finally found the solution:

    sprintf( __( '%1$s left a %2$s on %3$s\'s %4$s.', 'o2' ), $commentAuthor, $commentLink, $postAuthor, $postLink );
    

    In poedit:

    %1$s a laissé un %2$s sur la %4$s de %3$s.