2

we are translating our site with Gettext, but recently we found some problems with our translate team.

we have some string like...

Hi Bob this evening you win *three* red *balloons*

and we get something like this...

sprintf("Hi %s this %s you %s %s %s %s", $name, $action, $number, $color, $object);

The problem is that our translate team don't know the variables order... and is very dificult for them to translate correctly that "encode" string, they only see in them poedit this text

Hi %s this %s you %s %s %s %s

¿How can we handle this complex strings?

aaronroman
  • 820
  • 1
  • 6
  • 10

2 Answers2

2

use poedit, which gives you an opportunity to add comments to strings.

David Jashi
  • 4,490
  • 1
  • 21
  • 26
  • Thanks for reply, the problem it that we have lot of lines similars, and is a hard job do this with everything... we need some other solution. We at first try to use variables like _("Hi {$name} there are {$number}") But we get lot of problems with poedit, because it doesn't get this variables. Any idea? – aaronroman Jun 03 '13 at 14:48
  • Unfortunately, that's the only way. It's tedious and tiresome job, but `poedit` (and `gettext`) only understand `printf`-styled substitution parameters. Maybe it would be easier for you to write a little application, that converts "Hi {$name} there are {$number}" to "Hi %s there are %d" and copies original string to comment, thus generating commented `.po` file? – David Jashi Jun 03 '13 at 14:52
1

Finally we found the best way for us.

We have strings like

sprintf("Hi %s this %s you %s %s %s %s", $name, $action, $number, $color, $object);

Then we can change de vars position like this

sprintf("Hi %1$s this %2$s you %3$s %4$s %5$s %6$s", $name, $action, $number, $color, $object); The translate team can change the position only changing the number

Then... the most important thing... tell to the translate team what are these variables... with a comment for gettext like...

<!-- //Hi translator... The variables are $name, $action, $number, $color, $object -->
sprintf(_('Hi %1$s this %2$s you %3$s %4$s %5$s %6$s'), $name, $action, $number, $color, $object);

Adding the option -c in xgettext line, you can put this comment INSIDE .po file, and this is the way we choice for work :)

I hope this be a great solution for you

aaronroman
  • 820
  • 1
  • 6
  • 10