简体   繁体   English

如何在gettext系统中控制翻译?

[英]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. 我在linux环境下的c ++应用程序中广泛使用了gettext系统,可以翻译成不同的语言。 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". 像gettext(“Energie”) - >这是德语,用英语翻译成“能量”,用户可以看到,但我需要字符串“Energie”。

There could be many solutions but I am specifically looking into gettext system. 可能有很多解决方案,但我特别关注gettext系统。 Is there way in gettext system to retrieve the original text ? 在gettext系统中有没有办法检索原始文本? Any help is appreciated. 任何帮助表示赞赏。

Reverse translation like this isn't possible with gettext. 使用gettext无法实现这样的反向转换。 Here's a simple .PO file for French: 这是一个简单的法语.PO文件:

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. 你不能将“une fraise”反向翻译成英文,因为有两种可能的含义,gettext不会知道你的意思。

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. 也许你需要Python gettext文档所谓的“延迟翻译”:而不是在定义时应用翻译功能,而是在打印时执行。

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.) (假设_()被用作真正的翻译函数;如果它是一个预处理器指令,这将无法工作,因为我在C环境中经常会这样做。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM