soupso
soupso

Reputation: 642

How to control translation in a gettext system?

I have extensively used gettext system in my c++ application in linux environment for translation into different languages. Everything works fine. Now, suppose that the whole application has been translated to English from German. But I need to query on some strings which should be in German (meaning query on the original string).

Like gettext("Energie") --> this is in German and translates to "Energy" in English and user can see that but I need the string "Energie".

There could be many solutions but I am specifically looking into gettext system. Is there way in gettext system to retrieve the original text ? Any help is appreciated.

Upvotes: 3

Views: 410

Answers (2)

virtualnobi
virtualnobi

Reputation: 1180

Maybe you need what the Python gettext documentation calls "deferred translation": Instead of applying the translation function at definition time, rather do it at print time.

Instead of this, which will use different array indices in each language:

name = _('Energie')
dict[name] = 50
print('%s is %d' % (name, dict[name]))

do this:

name = 'Energie'
dict[name] = 50
print('%s is %d' % (_(name), dict[name]))

(Assuming that _() is used as a real translation function; this won't work if it's a preprocessor directive as I read it's often the case in C environment.)

Upvotes: 0

fisharebest
fisharebest

Reputation: 1370

Reverse translation like this isn't possible with gettext. Here's a simple .PO file for French:

msgid "a strawberry"
msgstr "une fraise"

msgid "a drill"
msgstr "une fraise"

You cannot reverse-translate "une fraise" back into English, as there are two possible meanings, and gettext would not know which one you meant.

Upvotes: 2

Related Questions