16

可能重复:
gettext 如何处理动态内容?

我正在使用 PHP 的 gettext。我想翻译一个包含变量的句子。这可能吗?

例如,在英语中:

Are you sure you want to block Alice?

(其中“Alice”是用户名。)

但是,在德语中,主语不会出现在句末。

Sind Sie sicher, dass Sie Alice blockieren?

在messages.po中,我有

msgid "BLOCK"
msgstr "Are you sure you want to block"

但我看不出有办法传递一个或多个变量。这可能吗?

4

1 回答 1

37

poedit 识别变量。

msgid "Are you sure you want to block %s?"
msgstr "Sind Sie sicher, dass Sie %s blockieren?"

在 PHP 中

sprintf(_('Are you sure you want to block %s?'),'Alice');
于 2012-10-12T14:12:41.470 回答