#5 parameter inversion doesn't work

open
nobody
None
5
2008-06-17
2008-06-17
Kamy
No

when a translation invert 2 parameters, that doesn't work anymore...

gettext-0.13.1 : win32

example :

after "set LANG=en", it prints "parameters (1 & 2)"

after "set LANG=fr", it prints "parametres ($d & $d)"

The "fr" translation string is "parametres(%2$d & %1$d)"

It works well on linux(0.14.5), but not on windows...

Discussion

  • Kamy
    Kamy
    2009-01-19

    I do include this file !!!

    I also try to call the _lib_intl_printf function directly ... and it doesn't work !!!

    gettext-0.13.1 : win32 doesn't work correctly ... that's the bug ! :-p

     
  • Robert Simac
    Robert Simac
    2011-03-24

    I can also confirm this bug.

    I dig a bit deeper and found out the win (woe) gettext port somehow fails to use windows flavor of positional printf, called _printf_p() (http://msdn.microsoft.com/en-us/library/bt7tawza%28v=vs.80%29.aspx)

    It is using plain windows printf which is smart enough to throw assertion when it hits positional parameters ($1...).

    This is the stack at the time of assertion failure on this code line:
    printf(gettext("Demonstrating the argument swapping, dependent on language where first(%s) arg may be translated as second(%s)"), "first", "second");

    > msvcr100d.dll!_output_l(_iobuf * stream, const char * format, localeinfo_struct * plocinfo, char * argptr) Line 1685 + 0x61 bytes C++
    msvcr100d.dll!_snprintf(char * string, unsigned __int64 count, const char * format, ...) Line 130 + 0x1a bytes C
    NIBBLER.exe!libintl_vasnprintf(char * resultbuf, unsigned __int64 * lengthp, const char * format, char * args) Line 731 + 0x65 bytes C
    NIBBLER.exe!libintl_vfprintf(_iobuf * stream, const char * format, char * args) Line 87 + 0x16 bytes C
    NIBBLER.exe!libintl_vprintf(const char * format, char * args) Line 117 C
    NIBBLER.exe!libintl_printf(const char * format, ...) Line 127 + 0xf bytes C
    NIBBLER.exe!test_gettext() Line 1732 C++

    I do have an workaround for this, although it makes the source windows specific.
    Instead of sprintf, use native win _printf_p() to format/print your positional messages.
    That works fine with gettext()
    Failing Sample:
    printf(gettext("Demonstrating the argument swapping, dependent on language where first(%s) arg may be translated as second(%s)"), "first", "second");

    Working Sample:
    _printf_p(gettext("Demonstrating the argument swapping, dependent on language where first(%s) arg may be translated as second(%s)"), "first", "second");

    Ideal solution would be for gettext package printf version (libintl_printf) to recognize positional parameters and to call proper windows printf flavor internally.

    I'll try to make it work and will post here if any success, fwiw.

    Thanks to original authors and woe32 porters for hard work.

    Robert