3

Currently in a view I have this:

<span style="color: #2363a2;"><?php echo __('Accèdez à tous les %spronostics%s d\'%s', '<span style="font-weight: bold; text-transform: uppercase">', '</span>', AppController::getSiteName()); ?></span>

In my .po file I have this:

msgid "Accèdez à tous les %spronostics%s d'%s"
msgstr "Reach all the %s %spicks%s"

The translation I get (from french - msgid - to english - msgstr -) is wrong.

The 1st %s value in msgstr should be the 3rd %s value in msgid. I did some researches related to i18n for cakephp but I didn't find nothing related to my issue.

Do you know how to 'set the order' of the translated %s ?

Thanks.

zeflex
  • 1,487
  • 1
  • 14
  • 29

1 Answers1

1

I've had issues in the past when passing the replacement arguments as multiple function arguments. Using an array tends to be more reliable:-

__(
    'Accèdez à tous les %spronostics%s d\'%s', 
    [
        '<span style="font-weight: bold; text-transform: uppercase">', 
        '</span>', 
        AppController::getSiteName()
    ]
)

Update:

You need to specify the correct order in the translated string like this:-

msgid "Accèdez à tous les %spronostics%s d'%s"
msgstr "Reach all the %3$s %1$spicks%2$s"

Using %3$s tells Cake which of the parameters to use where the integer number represents the original ordering.

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59
  • Ok but the issue is still the same. Instead of having `AppController::getSiteName()` in the 1st position (once translated to english), it's still on the 3rd one (like original transaction). – zeflex May 12 '15 at 14:36
  • Sorry, I misunderstood your original question. Looking at the code that handles the translation I'm not even sure you can easily fix the ordering of the replacements. :-/ – drmonkeyninja May 12 '15 at 15:06
  • I've just updated my answer with how to change the word sequence. – drmonkeyninja May 12 '15 at 15:26
  • 1
    Thanks it works. Simply by editing the .po file according to your explanations. Editing the __() is not needed. – zeflex May 12 '15 at 15:47