2017-09-26 94 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