Escaping C format string for percentage sign
A lightweight file manager for X
Brought to you by:
baudinr
Hello,
I have just finished translating XFE to Turkish. When I was checking my translation for any error with
/usr/bin/msgfmt -c --statistics tr.po
I got this error:
tr.po:6887: 'msgstr' is not a valid C format string, unlike 'msgid'. Reason: In the directive number 1, the character 'y' is not a valid conversion specifier
The problematic line is this:
" * Resmi 100% yakınlaştır - Ctrl-I\n"
The percentage sign in the translated string is perceived as a C format string. The original string is this:
#: src/help.h:8
#, c-format
msgid ""
...
" * Zoom image to 100% - Ctrl-I\n"
...
The original string is not treated as a C string. Curiously enough, there are 4 other similar strings which are not treated as a C string.
#: src/Preferences.cpp:1720
msgid "Zoom image to 100%"
msgstr "Resmi 100% yakınlaştır"
#: src/XFileImage.cpp:843
msgid "Zoom 100%"
msgstr "100% Yakınlaştır"
#: src/XFileImage.cpp:843 src/XFileImage.cpp:934
msgid "Zoom image to 100%."
msgstr "Resmi 100% yakınlaştır."
#: src/XFileImage.cpp:934
msgid "Zoo&m 100%"
msgstr "100% Yakı&nlaştır"
If I escape the problematic line with a double percentage sign — %% — then gettext complains about mismatched number of format specifications:
tr.po:6887: number of format specifications in 'msgid' and 'msgstr' does not match
The only solution that I can think of is escaping the percentage sign both in the original and translated strings.
Hi and sorry for the late replay.
Here follows the reason of the error. The english string that contains the '%' is:
" * Zoom image to 100% - Ctrl-I\n"
Since the msgid string to translate has the 'c-format' attribute, the '% - C' part of the string is interpreted as a printf format and you must keep the same format in your translated string.
So your translated string must look like:
" xxxxxxxxxxxxxx100% - Ctrl-I\n"
where xxxxxxxxxx are some characters (including spaces) in any number but without any other ' %'. The number of spaces between '%' and '-C' doesn't matter.