我可以在.po文件中包含变量吗?

时间:2012-06-18 13:13:07

标签: variables gettext po

我想在gettext .po文件中以某种方式使用变量,例如:

msgid "ui_settings_connect_text"
msgstr "Connect to another running instance of " APP_NAME

有人曾尝试过这样的事吗?

2 个答案:

答案 0 :(得分:3)

.po文件中:

msgid "Connect to another running instance of %s"
msgstr "Connect to another running instance of %s"

在你的应用中:

printf(_("Connect to another running instance of %s"), app_name);

答案 1 :(得分:1)

我做了一个预处理器也是这样做的,因为我不相信应用程序代码应该与某些文本是否包含应用程序名称(使用Tom的示例)或任何其他已翻译的片段相关联。

我把源码放在github上并提供了一个Windows .exe,但是如果你不使用Windows则需要Mono。

https://github.com/Treer/POpp

要解决Tom提出的问题,.po文件将如下所示:

msgid "APP_NAME"
msgstr "Tom's app"

msgid "ui_settings_connect_text"
msgstr "Connect to another running instance of {id:APP_NAME}"

哪个应该可以在任何GUI PO编辑器中使用。

预处理器就像这样运行:

popp source.po destination.po
相关问题