带变量的Django blocktrans

时间:2017-09-26 20:17:18

标签: django internationalization po django-i18n

我有一个模板,我想要翻译一个字符串。

{% blocktrans with "www.mywebsite.com" as website_name %}footer-slogan{{ website_name }}{% endblocktrans %}

我已经生成了我的po文件,其中我将字符串翻译成如下:

msgid "footer-slogan %(website_name)s"
msgstr "This is a test %(website_name)s"

在我生成的html文件中,我得到了这个未翻译的元素:

footer-slogan www.mywebsite.com

如果我从已翻译的字符串中删除该变量,则可以正常工作:

msgid "footer-slogan %(website_name)s"
msgstr "This is a test"

我甚至尝试从源代码翻译中删除变量但是将变量保留在翻译后的字符串中,问题是一样的:

template.html
{% blocktrans with "www.mywebsite.com" as website_name %}footer-slogan{% endblocktrans %}

django.po
msgid "footer-slogan"
msgstr "This is a test %(website_name)s"

我希望能够仅在翻译的字符串上设置变量。

我在翻译的字符串上做错了什么?

1 个答案:

答案 0 :(得分:1)

您可以这样使用

.flex-box {
  display: flex;
  flex-flow: column wrap;
    .flex-item {
        flex: 1 0 auto;
    }
}

<div class="row">
  <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <div class="flex-box">
      <div class="flex-item" ng-repeat="campaign in mvm.regionCampaigns.results | orderBy:'name' track by campaign.id">
        <input id="audit-{{ mvm.title }}-{{ campaign.id }}" checklist-model="mvm.selectedFilters['campaign_id']" checklist-value="campaign.id" type="checkbox" ng-click="mvm.setRegionSelectAll()" ng-change="mvm.clearSearchMatch('campaign_id', campaign.id, checked)">
        <label for="audit-{{ mvm.title }}-{{ campaign.id }}" class="pull-left checkbox-label"></label>
        <span tooltip-placement="top" uib-tooltip="{{campaign.name}}">{{ campaign.name | limitTo:17 }}{{campaign.name.length > 17 ? '...' : ''}}</span>
      </div>
    </div>
  </div>
</div>