2017-09-26 95 views
1

我有一个模板用于添加我的项目,我使用的是Django的翻译模块。我对我现有的页面进行了很好的处理,但是在这个页面上没有渲染翻译,而是显示了所有的原始标签。我编写了消息等,但仍然没有。我该如何解决?Django Translation not working and showing trans标签

我看着下面的问题,但没有骰子: 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 %} 
+0

包含在其他模板这个模板的更多信息? –

回答

2

Django的反式templatetag不支持多行作为文本

所以使用blocktrans标签在支持多线

{% blocktrans %} 
enter any code here that you want translation 
{% endblocktrans %} 
+0

这些不是多行的。他们都是单行的 – fmakawa

+0

不,你有多行。例如:{%trans'如果您想
尝试使用双语'%},这是多行不是单行的理想选择。原因在前端,字符串显示为原样。尝试使用blocktrans标记。 –

+0

您按了trans标签字符串的
后输入。导致这个问题 –

0

别的之前的Django,请检查您的settings.py文件,如果它包括:

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

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

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

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

您可以参考Django documentation *翻译

+0

这已经完成。正如我上面所说,其他翻译正在研究项目,但不是这个页面 – fmakawa