如何使用gettext占位符?

时间:2012-01-30 14:48:27

标签: localization internationalization translation gettext vala

我不是程序员,但我想帮助使用gettext翻译用vala编写的项目(http://live.gnome.org/Vala/Tutorial)。当我不得不使用占位符重新排列句子的某些部分时,我遇到了一个问题。

示例:

public void show_retrieving_similars() {
    if(hint != ViewWrapper.Hint.SIMILAR || lm.media_info.media == null)
        return;

    errorBox.show_icon = false;
    errorBox.setWarning("<span weight=\"bold\" size=\"larger\">" + _("Loading similar songs") + "</span>\n\n" + _("BeatBox is loading songs similar to") + " <b>" + lm.media_info.media.title.replace("&", "&amp;") + "</b> by <b>" + lm.media_info.media.artist.replace("&", "&amp;") + "</b> " + _("..."), null);
    errorBox.show();
    list.hide();
    albumView.hide();
    similarsFetched = false;
}

我需要做什么?

1 个答案:

答案 0 :(得分:0)

我还没有使用过vala而我还没有对此进行过测试,看起来你需要更换

errorBox.setWarning("<span weight=\"bold\" size=\"larger\">" + _("Loading similar songs") + "</span>\n\n" + _("BeatBox is loading songs similar to") + " <b>" + lm.media_info.media.title.replace("&", "&amp;") + "</b> by <b>" + lm.media_info.media.artist.replace("&", "&amp;") + "</b> " + _("..."), null);

string title = lm.media_info.media.title.replace("&", "&amp;");
string artist = lm.media_info.media.artist.replace("&", "&amp;");
errorBox.setWarning(@"<span weight=\"bold\" size=\"larger\">Loading similar songs</span>\n\n BeatBox is loading songs similar to<b> $title </b>by<b> $artist </b>...", null);