Django Translation无法正常工作并显示trans标签

时间:2017-09-26 10:52:36

标签: python django translation

我有一个我创建的模板来添加我的项目,我正在使用Django的翻译模块。我对已经存在的页面工作正常,但是在这一页上,翻译不会呈现,而是显示所有原始标记。我编译了消息等但仍然没有。我该如何解决这个问题?

我看过以下问题,但没有骰子: django - how to make translation work?

django internationalization and translations issue

How to setup up Django translation in the correct way?

http://askbot.org/en/question/8948/weve-edited-djangopo-files-but-translations-do-not-work-why/

见图:enter image description here

HTML:

{% load static %}
{% load staticfiles %}
{% load i18n %}

{% block bonos %}
<div class="container" >
 <div id='titleb' class="container">
  <h2 style= "color:black; align=center">MILINGUAL BONO</h2>
 </div>
 <div id='titleb' class="container">
  <h1 style= "color:black; align=center">MILINGUAL BONO</h1>
 </div>

 <div>
 <p>{% trans 'The Milingual Bono offers you more classes for much lesser. It saves you the hasslse of pasying each time you book a class, at the same time offering you the flexibilty of attending any Milingual class or event, anytime you want. Pick the 3 class bono if you would like to give it a try firt or book the <b>season bono</b> for unlimited access for 3 months.' %}
 </p>
 </div>
    <div>
      <div class="row">
        <!-- New set of columns, centered -->
        <div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 text-center bonoint" data-toggle="modal" data-target="#login-modal" >
              <div class="circle" style="background: #0045ab" ><span style="font-weight:bold; font-size:60px;"  >3</span><br> Credits</div>
                <div id="price">25€</div>
                <div id="savings">
                  {% trans 'You save' %} <span style="font-weight:bold">5€</span><br><br>
                    {% trans 'Ideal if you want to<br>
                  try out Milingual' %}</br>.
                </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 text-center bonoint" data-toggle="modal" data-target="#login-modal">
                <div class="circle" style="background: #58aeb4" ><span style="font-weight:bold; font-size:60px;">6</span><br> Credits</div>
                <div id="price">39€</div>
                <div id="savings">
                  {% trans 'You save' %} <span style="font-weight:bold">21€</span><br><br>
                    {% trans 'Ideal if you want to<br>
                  try Milingual or have attended <br>
                  a couple of classes.' %}
                </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 text-center bonoint" data-toggle="modal" data-target="#login-modal">
                <div class="circle"   style="background: #e8bf16"><span style="font-weight:bold; font-size:60px;">8</span><br> Credits
                </div>
                <div class="ribbon-wrapper-blue">
                  <div class="ribbon-blue">{% trans 'Most Popular' %}
                  </div>
                </div>
                <div id="price">50€</div>
                <div id="savings">
                  {% trans 'You save' %} <span style="font-weight:bold">30€</span><br><br>
                    {% trans 'Ideal if you want to practice <br>
                  twice a week for a month' %}
                </div>
            </div>
        </div>
    </div>

  </div>
<div>
    <div>
      <div class="row">
        <!-- New set of columns, centered -->
        <div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 text-center bonoint" data-toggle="modal" data-target="#login-modal" >
              <div class="circle"  style="background: #a7a5a7"><span style="font-weight:bold; font-size:60px;">10</span><br>Credits
              </div>
                <div id="price">64€</div>
                <div id="savings">
                  {% trans 'You save' %} <span style="font-weight:bold">36€</span><br><br>
                    {% trans 'Ideal if you want to make<br>
                  Milingual part of your routine' %}
                </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 text-center bonoint" data-toggle="modal" data-target="#login-modal">
                <div class="circle"  style="background: #c6595b"><span style="font-weight:bold; font-size:60px;">12</span><br> Credits</div>
                <div id="price">79€</div>
                <div id="savings">
                  {% trans 'You save' %} <span style="font-weight:bold">41€</span><br><br>
                    {% trans 'Ideal for multiple classes per<be>
                  week.' %}
                </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 text-center bonoint" data-toggle="modal" data-target="#login-modal">
                <div class="circle2"   style="background: #b18358"><span style="font-weight:bold; font-size:50px;">SEASON</div>
                <div id="price">89€</div>
                <div id="savings">
                  {% trans 'You save' %} <span style="font-weight:bold">200€*</span><br><br>
                    {% trans 'Get unlimited accee to <br>
                  classes as well as paid events<br>
                  for no extra cost.' %}
                </div>
            </div>
        </div>
    </div>
   </div>
  </div>

  </div>
</div>
</div>
{% endblock bonos %}

2 个答案:

答案 0 :(得分:2)

django trans templatetag不支持多行文字

所以在django中使用支持多行的

的blocktrans标签
 {% blocktrans %}
enter any code here that you want translation
{% endblocktrans %}

答案 1 :(得分:0)

除此之外,请查看您的settings.py文件(如果包含以下内容):

MIDDLEWARE_CLASSES = (
    ...
    'django.middleware.locale.LocaleMiddleware',
    ...
)
...
LOCALE_PATHS = (BASE_DIR + '/locale',)

之后,您应该手动在基本目录中创建一个名为locale的文件夹。

然后,您应该制作和编译消息,下面的实例是德语,它使用de作为语言代码。

django-admin makemessages --locale=de
django-admin compilemessages

您可以参考Django documentation了解有关翻译的更多信息

相关问题